0

我一直在尝试在我的应用程序中使用 OpenCVs cvCalcOpticalFlowBM 进行光流计算。我正在做类似的事情:

IplImage* velX1 = cvCreateImage(cvSize((beforeGray->width - blockSize.width + shiftSize.width)/shiftSize.width, (beforeGray->height - blockSize.height + shiftSize.height)/shiftSize.height), IPL_DEPTH_32F,1);
IplImage* velY1 = cvCreateImage(cvSize((beforeGray->width - blockSize.width + shiftSize.width)/shiftSize.width, (beforeGray->height - blockSize.height + shiftSize.height)/shiftSize.height), IPL_DEPTH_32F,1);
IplImage* velX2 = cvCreateImage(cvSize((beforeGray->width - blockSize.width + shiftSize.width)/shiftSize.width, (beforeGray->height - blockSize.height + shiftSize.height)/shiftSize.height), IPL_DEPTH_32F,1);
IplImage* velY2 = cvCreateImage(cvSize((beforeGray->width - blockSize.width + shiftSize.width)/shiftSize.width, (beforeGray->height - blockSize.height + shiftSize.height)/shiftSize.height), IPL_DEPTH_32F,1);

cvSetZero(velX1);
cvSetZero(velY1);
cvSetZero(velX2);
cvSetZero(velY2);

cvCalcOpticalFlowBM(beforeGray, afterGray, 1, blockSize, shiftSize, range, 0, velX1, velY1);

beforeGray 和 afterGray 是相同大小的 IPL_DEPTH_8U 单通道图像。但是当最后一行执行时,我得到以下异常:

OpenCV Error: Null pointer (NULL array pointer is passed) in cvGetMat

我正在使用 OpenCV 2.4,但我无法弄清楚为什么这不起作用。我通过调试器检查了所有输入参数都不为空。有人知道吗?

4

1 回答 1

0

好像我的论点错了。应该:

cvCalcOpticalFlowBM(beforeGray, afterGray, blockSize, shiftSize, range, 0, velX1, velY1);
于 2013-03-07T11:52:25.130 回答