Ask Your Question
0

DISOptical flow in 4.1?

asked 2019-05-14 18:29:18 -0500

david.bernstein gravatar image

Hi Everyone, I'm converting some python code from opencv version 3.4 to 4.1. The code uses the DISOpticalFlow algorithm (https://docs.opencv.org/4.1.0/de/d4f/...) but the interface to this class seems to have changed. If anyone has used the DIS optical flow in V4.1 in a python code I would appreciate an example snippet.

Thanks, Dave

edit retag flag offensive close merge delete

Comments

1

can you be a bit more specific ? which errors do you get ? show your code ?

berak gravatar imageberak ( 2019-05-15 03:44:56 -0500 )edit

Yes sorry, here is a minimal example that works in 3.4.4.19:

import cv2

if __name__ == '__main__':

    print('cv2 version: {}'.format(cv2.__version__))

    img1 = cv2.imread('test_1.png')
    img2 = cv2.imread('test_2.png')

    gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
    gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)

    inst = cv2.optflow.createOptFlow_DIS(cv2.optflow.DISOPTICAL_FLOW_PRESET_MEDIUM)

flow = inst.calc(gray1, gray2, None)
david.bernstein gravatar imagedavid.bernstein ( 2019-05-15 12:15:29 -0500 )edit

When running this with V4.1 I get:

Traceback (most recent call last): File "dis_minimal.py", line 13, in <module> inst = cv2.optflow.createOptFlow_DIS(cv2.optflow.DISOPTICAL_FLOW_PRESET_MEDIUM) AttributeError: module 'cv2.optflow' has no attribute 'createOptFlow_DIS'

david.bernstein gravatar imagedavid.bernstein ( 2019-05-15 12:16:04 -0500 )edit
1

strike the .optflow , it was moved into main opencv repo recently.

berak gravatar imageberak ( 2019-05-15 12:53:34 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-05-15 12:55:20 -0500

david.bernstein gravatar image

Yes, you're right, here's a version that works in 4.1

import cv2

if __name__ == '__main__':

    print('cv2 version: {}'.format(cv2.__version__))

    img1 = cv2.imread('test_1.png')
    img2 = cv2.imread('test_2.png')

    gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
    gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)

    # 3.4.4.19
    #inst = cv2.optflow.createOptFlow_DIS(cv2.optflow.DISOPTICAL_FLOW_PRESET_MEDIUM)

    # 4.1
    inst = cv2.DISOpticalFlow_create(cv2.DISOPTICAL_FLOW_PRESET_MEDIUM)

    flow = inst.calc(gray1, gray2, None)
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-05-14 18:29:18 -0500

Seen: 130 times

Last updated: May 14