Path: blob/master/modules/python/test/test_texture_flow.py
16337 views
#!/usr/bin/env python12'''3Texture flow direction estimation.45Sample shows how cv.cornerEigenValsAndVecs function can be used6to estimate image texture flow direction.7'''89# Python 2/3 compatibility10from __future__ import print_function1112import numpy as np13import cv2 as cv14import sys1516from tests_common import NewOpenCVTests171819class texture_flow_test(NewOpenCVTests):2021def test_texture_flow(self):2223img = self.get_sample('samples/data/chessboard.png')2425gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)26h, w = img.shape[:2]2728eigen = cv.cornerEigenValsAndVecs(gray, 5, 3)29eigen = eigen.reshape(h, w, 3, 2) # [[e1, e2], v1, v2]30flow = eigen[:,:,2]3132d = 30033eps = d / 303435points = np.dstack( np.mgrid[d/2:w:d, d/2:h:d] ).reshape(-1, 2)3637textureVectors = []38for x, y in np.int32(points):39textureVectors.append(np.int32(flow[y, x]*d))4041for i in range(len(textureVectors)):42self.assertTrue(cv.norm(textureVectors[i], cv.NORM_L2) < eps43or abs(cv.norm(textureVectors[i], cv.NORM_L2) - d) < eps)4445if __name__ == '__main__':46NewOpenCVTests.bootstrap()474849