/usr/share/doc/opencv-doc/examples/python/fback.py is in opencv-doc 2.4.9.1+dfsg-1.5ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #!/usr/bin/env python
from cv import *
class FBackDemo:
def __init__(self):
self.capture = CaptureFromCAM(0)
self.mv_step = 16
self.mv_scale = 1.5
self.mv_color = (0, 255, 0)
self.cflow = None
self.flow = None
NamedWindow( "Optical Flow", 1 )
print( "Press ESC - quit the program\n" )
def draw_flow(self, flow, prevgray):
""" Returns a nice representation of a hue histogram """
CvtColor(prevgray, self.cflow, CV_GRAY2BGR)
for y in range(0, flow.height, self.mv_step):
for x in range(0, flow.width, self.mv_step):
fx, fy = flow[y, x]
Line(self.cflow, (x,y), (x+fx,y+fy), self.mv_color)
Circle(self.cflow, (x,y), 2, self.mv_color, -1)
ShowImage("Optical Flow", self.cflow)
def run(self):
first_frame = True
while True:
frame = QueryFrame( self.capture )
if first_frame:
gray = CreateImage(GetSize(frame), 8, 1)
prev_gray = CreateImage(GetSize(frame), 8, 1)
flow = CreateImage(GetSize(frame), 32, 2)
self.cflow = CreateImage(GetSize(frame), 8, 3)
CvtColor(frame, gray, CV_BGR2GRAY)
if not first_frame:
CalcOpticalFlowFarneback(prev_gray, gray, flow,
pyr_scale=0.5, levels=3, winsize=15,
iterations=3, poly_n=5, poly_sigma=1.2, flags=0)
self.draw_flow(flow, prev_gray)
c = WaitKey(7)
if c in [27, ord('q'), ord('Q')]:
break
prev_gray, gray = gray, prev_gray
first_frame = False
if __name__=="__main__":
demo = FBackDemo()
demo.run()
cv.DestroyAllWindows()
|