#7276·opencv

Python interface does not report missing parameters

Author: knedlseppCreated Sep 13, 2016Updated Sep 28, 2026
Labelsbugcategory: python bindingscategory: video
System information (version)
  • OpenCV => 3.1
  • Operating System / Platform => Linux 64 Bit
  • Compiler => gcc
Detailed description

The function calcOpticalFlowFarneback offers a flag: OPTFLOW_USE_INITIAL_FLOW, which when set needs an additional input field flow. If this flag is set, but the parameter is not given, the function acts non-deterministic and returns mostly garbage. Identifying this problem took me quite some time.

Expected behaviour

There should be an error message stating: "The field flow is not given, but expected, as OPTFLOW_USE_INITIAL_FLOW is set"

Steps to reproduce
import numpy as np
import cv2
image1 = np.random.rand(100,100)
image2 = np.random.rand(100,100)
flow = cv2.calcOpticalFlowFarneback(image1, image2, 
                                    pyr_scale=0.5, levels=3, 
                                    winsize=15, iterations=3, 
                                    poly_n=5, poly_sigma=1.2,
                                    flags=cv2.OPTFLOW_USE_INITIAL_FLOW)
# flow now contains garbage.