Sizes of input arguments do not match in cvcalcopticalflowbm opencv 2.4.7

本秂侑毒 提交于 2019-12-13 06:19:32

问题


I want to calculate optical flow using cvcalcopticalflowBM function in opencv 2.4.7 When I complied the belowed code. The error message is "Sizes of input arguments do not macth() in cvcalcopticalflowbm

I do not understand why it is. Please help me. Thank you advance.

#define BS 5

IplImage *imgA = NULL, *imgB = NULL;
IplImage *grayA = NULL, *grayB = NULL;
IplImage *velx = NULL, *vely = NULL;
IplImage *result = NULL;
imgA = cvLoadImage("00.jpg", 1);
imgB = cvLoadImage("01.jpg", 1);
grayA = cvCreateImage(cvGetSize(imgA), IPL_DEPTH_8U, 1);
grayB = cvCreateImage(cvGetSize(imgA), IPL_DEPTH_8U, 1);

cvCvtColor(imgA, grayA, CV_BGR2GRAY);
cvCvtColor(imgB, grayB, CV_BGR2GRAY);

CvSize size = cvGetSize(imgA);
size.width /= BS;
size.height /= BS;
result = cvCreateImage(size, IPL_DEPTH_8U, 1);
for (int i=0; i<size.height; i++) {
    for (int j=0; j<size.width; j++) {
        cvSet(result, CV_RGB(255,255,255), NULL);
    }
}
velx = cvCreateImage(size, IPL_DEPTH_32F, 1);
vely = cvCreateImage(size, IPL_DEPTH_32F, 1);
cvCalcOpticalFlowBM(grayB, grayA, cvSize(BS, BS), cvSize(1, 1), cvSize(1, 1), 0, velx, vely);
//
cvNamedWindow("HorFlowBM", CV_WINDOW_AUTOSIZE);
cvShowImage("HorFlowBM", velx);
cvNamedWindow("VerFlowBM", CV_WINDOW_AUTOSIZE);
cvShowImage("VerFlowBM", vely);
for (int i=0; i<size.height; i+=2) {
    for (int j=0; j<size.width; j+=2) {
        int dx = (int)cvGetReal2D(velx, i, j);
        int dy = (int)cvGetReal2D(vely, i, j);
        cvLine(result, cvPoint(j, i), cvPoint(j+dx, i+dy), CV_RGB(0,0,0), 1, 8, 0);
    }
}
cvNamedWindow("OpticalFlow", CV_WINDOW_AUTOSIZE);
cvShowImage("OpticalFlow", result);
cvWaitKey(0);

回答1:


Are you sure that the input images are getting load. Try to show them after loading them i.e. cvShowImage("input1", imgA);. Also, try to print the size of both the images to check that the size of both the images is same.




回答2:


I recognized this error. The size of velx and vely should be

CvSize velSize =
{
    (grayA->width - BLOCK_SIZE + SHIFT_SIZE)/SHIFT_SIZE,
    (grayA->height - BLOCK_SIZE + SHIFT_SIZE)/SHIFT_SIZE
};

It becomes correctly when complie the program



来源:https://stackoverflow.com/questions/21794539/sizes-of-input-arguments-do-not-match-in-cvcalcopticalflowbm-opencv-2-4-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!