Ask Your Question

Revision history [back]

DenseOpticalFlow - Shape problems

Hi all,

I am working on a project where I have to implement the DOF algorithm: calcOpticalFlowFarneback().

I've followed the opencv tutorial and it works very well with .avi files.

The "problem" is that I have to use .tif image sequences. As you can see in the tutorial he's using gray image and my .tif are already gray-scale but the algorithm doesn't like the shape of the calculated magnitude and phase:

-Tiff Extraction:

VideoToSOF = [0 for _ in range(len(images))]
print("Extracting frames..")
VideoFrameCounter = 0
for image in images:
    VideoToSOF[VideoFrameCounter] = image
    VideoFrameCounter += 1
    print("Video Frame n°%d/%d" % (VideoFrameCounter,len(images)),end='\r')

-DOF Code:

frame2 = VideoToSOF[counter]
next = frame2
flow = cv2.calcOpticalFlowFarneback(prvs,next, flow, pyr_scale, levels, winsize, iteration, poly_n, poly_sigma, flags)

mag, ang = cv2.cartToPolar(flow[...,0], flow[...,1]) 

hsv[...,0] = ang*180/np.pi/2
hsv[...,2] = cv2.normalize(mag,None,0,255,cv2.NORM_MINMAX)

As you can see my code is totally equal to the tutorial's one. Anyway i get this error:

Traceback (most recent call last): File ".\varioustest_script.py", line 73, in <module> hsv[...,0] = ang*180/np.pi/2 ValueError: could not broadcast input array from shape (300,300) into shape (300)

Do you know Why? I mean, the image should have the same shape as the .avi one..I don't get it!