2

I'm asking you a very simple question. I want to use the TVL1 function for computing opticalflow with openCV (and python). But here is what I get :

AttributeError: 'module' object has no attribute 'DualTVL1OpticalFlow_create'

Traceback (most recent call last):

File "opticalFlowModel.py", line 50, in computeOpticalFlow
optical_flow = cv2.DualTVL1OpticalFlow_create()

AttributeError: 'module' object has no attribute 'DualTVL1OpticalFlow_create'

The problem is that in this topic How to compute optical flow using tvl1 opencv function , they seems to use the exact same code. I also try this code : Speed Up Optical Flow algorithm (If applicable) Python OpenCV and have the same result.

Here are all my import :

import cv2
import numpy as np
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4 import QtCore, QtGui

I'm using OpenCV 4.0.1

Alexy
  • 780
  • 6
  • 22

1 Answers1

4

I found the solution here.

The way to call the function is different with the latest openCV version. Here is what to do :

Replace

optical_flow = cv2.DualTVL1OpticalFlow_create()

by

optical_flow = cv2.optflow.DualTVL1OpticalFlow_create()
Alexy
  • 780
  • 6
  • 22
  • 1
    optical_flow = cv2.optflow.DualTVL1OpticalFlow_create().calc(prvs,next,None) – sjcoding May 16 '19 at 08:44
  • 1
    @sjcoding I would not recommend this because evry time you will compute an optical flow, this will create a new instance of DualTVL1OpticalFlow. Must use optical_flow = cv2.optflow.DualTVL1OpticalFlow_create() and then current_opt_flow = optical_flow.calc(prvs, next, None) for every new optical flow. – Alexy May 17 '19 at 08:28