Sizes of input arguments do not match () in cvCalcOpticalFlowBM

asked 2016-03-22 13:48:17 -0600

hassouna09 gravatar image

hello

i am trying to Implement the opticalflow algorithm with block matching cv.CalcOpticalFlowBM(), but when i run i have error

OpenCV Error: Sizes of input arguments do not match () in cvCalcOpticalFlowBM, file /home/travis/miniconda/conda-bld/work/opencv-2.4.11/modules/legacy/src/optflowbm.cpp, line 88 Traceback (most recent call last): File "/home/kaos/PycharmProjects/untitled/1616.py", line 56, in <module> optix = calcOpticalFlow(image,image2 ,'BlockMatching') File "/home/kaos/PycharmProjects/untitled/1616.py", line 44, in calcOpticalFlow 0, cv.fromarray( opticalFlowArrayX ), cv.fromarray( opticalFlowArrayY ) ) cv2.error

here is the code i try all day, but didn't find where is the problem thank's

` def calcOpticalFlow( image1, image2, method="BlockMatching" ):

    storageWidth = image1.shape[0]
    storageHeight = image1.shape[1]

    if method == "BlockMatching":
        opticalFlowArrayX = np.ndarray( ( storageHeight, storageWidth ), dtype=np.float32 )
        opticalFlowArrayY = np.ndarray( ( storageHeight, storageWidth ), dtype=np.float32 )
        cv.CalcOpticalFlowBM(cv.fromarray(image1),cv.fromarray(image2),
            (16,16),
              (5,5),
              (1,1),
            0, cv.fromarray( opticalFlowArrayX ), cv.fromarray( opticalFlowArrayY ) )

    return ( opticalFlowArrayX, opticalFlowArrayY )

image = cv2.imread('2.jpg',cv2.CV_LOAD_IMAGE_GRAYSCALE)

image2 = cv2.imread('3.jpg',cv2.CV_LOAD_IMAGE_GRAYSCALE)

optix,optiy = calcOpticalFlow(image,image2 ,'BlockMatching')`

edit retag flag offensive close merge delete

Comments

please avoid using the legacy cv module (it's gone in current opencv), or mixing it with cv2 code

berak gravatar imageberak ( 2016-03-22 13:51:45 -0600 )edit

Hi, sorry but i didn't understand where i mix the cv2 code ? I am using opencv2.4 and python 2.7 .

hassouna09 gravatar imagehassouna09 ( 2016-03-22 14:21:26 -0600 )edit

cv is the deprecated c-api based python binding, cv2. the newer(well, 2010) c++ based one.

you're using a version of opncv, which still supports using one of them, but you should not mix. also, cv.CalcOpticalFlowBM is gone in current (3.1.0) opencv, so you better should not use it.

berak gravatar imageberak ( 2016-03-22 14:24:48 -0600 )edit

yes i know cv.CalcOpticalFlowBM() was removed from opencv 3.1 is why i back to 2.4 version but i need this fonction because i try to implement motion intensity from mpeg-7 visual descriptor and for this i need cv.CalcOpticalFlowBM() if this is not possible can you advice me i 'am trying to implement scene change detection algorithme in video should i go to histograme comparaison

hassouna09 gravatar imagehassouna09 ( 2016-03-22 14:36:23 -0600 )edit