I use LK method to calculate the optical flow of OpenCV.

Asked 2 years ago, Updated 2 years ago, 77 views

If the win_size value is greater than or equal to 16,

OpenCV Error: Assertion failed ((icvCalcOpticalFlowLK_8u32fR(uchar*)srcA->data.ptr,
    (uchar*)srcB->data.ptr,srcA->step,cvGetMatSize(srcA),winSize,
        velx->data.fl,very->data.fl,velx->step))>=0)incvCalcOpticalFlowLK,
            file C:\builds\2_4_PackSlave-win32-vc12-shared\opencv\modules\legacy\src\optflowlk.cpp,
                line 596

I get this kind of error.
Probably

C:\builds\2_4_PackSlave-win32-vc12hared\opencv\modules\legacy\src\optflowlk.cpp

It seems that the maximum window size value has been determined in line 596 of , so I should rewrite it, but I am sorry that I could not find the folder C:\builds in the first place.
Please help me;;

I looked into various things and solved it.
Apparently, it would be better to use PyrLK to calculate the sparse optical flow.
Thank you for your reply.

opencv

2022-09-30 18:27

1 Answers

If you look at the optflowlk.cpp:icvCalcOpticalFlowLK_8u32fR() in question, you will see:

static CvStatus CV_STDCALL
icvCalcOpticalFlowLK_8u32fR(uchar*imgA,
                             uchar*imgB,
                             int imgStep,
                             CvSize imgSize,
                             CvSize winSize,
                             float*velocityX,
                             float*velocityY, intvelStep)
             :

int winWidth = winSize.width;
int winHeight=winSize.height;
             :

if(imageHeight<winHeight)
    return CV_BADSIZE_ERR;
if(imageWidth<winWidth)
    return CV_BADSIZE_ERR;

if(winHeight>=16)
    return CV_BADSIZE_ERR;
if(winWidth>=16)
    return CV_BADSIZE_ERR;

if(!(winHeight & 1))
    return CV_BADSIZE_ERR;
if(!(winWidth & 1))
    return CV_BADSIZE_ERR;

If there is a problem with the Window size, an error will be returned (assertion failed):

  • Window size is larger than image size
  • Window size (width/height) >16pixcel
  • Window size is even

The reason why we limit the Window size to less than 16 pixcel (odd value of ) seems to be for some reason.If you change this limitation and rebuild OpenCV, it will only return meaningless results, even if it is not an error.


2022-09-30 18:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.