1
2
3'''
4Texture flow direction estimation.
5
6Sample shows how cv.cornerEigenValsAndVecs function can be used
7to estimate image texture flow direction.
8
9Usage:
10 texture_flow.py [<image>]
11'''
12
13
14from __future__ import print_function
15
16import numpy as np
17import cv2 as cv
18
20 import sys
21 try:
22 fn = sys.argv[1]
23 except:
24 fn = 'starry_night.jpg'
25
27 if img is None:
28 print('Failed to load image file:', fn)
29 sys.exit(1)
30
32 h, w = img.shape[:2]
33
35 eigen = eigen.reshape(h, w, 3, 2)
36 flow = eigen[:,:,2]
37
38 vis = img.copy()
39 vis[:] = (192 + np.uint32(vis)) / 2
40 d = 12
41 points = np.dstack( np.mgrid[d/2:w:d, d/2:h:d] ).reshape(-1, 2)
42 for x, y in np.int32(points):
43 vx, vy = np.int32(flow[y, x]*d)
44 cv.line(vis, (x-vx, y-vy), (x+vx, y+vy), (0, 0, 0), 1, cv.LINE_AA)
48
49 print('Done')
50
51
52if __name__ == '__main__':
53 print(__doc__)
cv::String findFile(const cv::String &relative_path, bool required=true, bool silentMode=false)
Try to find requested data file.
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
void destroyAllWindows()
Destroys all of the HighGUI windows.
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR_BGR)
Loads an image from a file.
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0, AlgorithmHint hint=cv::ALGO_HINT_DEFAULT)
Converts an image from one color space to another.
void line(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a line segment connecting two points.
void cornerEigenValsAndVecs(InputArray src, OutputArray dst, int blockSize, int ksize, int borderType=BORDER_DEFAULT)
Calculates eigenvalues and eigenvectors of image blocks for corner detection.
int main(int argc, char *argv[])
Definition highgui_qt.cpp:3