所以我正在使用cvBlob和背景减法库。当我处理我的图像并获得面具时,我会尝试侵蚀和扩张它。
我在尝试侵蚀图片时收到错误。以下是错误:
OpenCV Error: Assertion failed (m.dims >= 2) in Mat, file /home/opencv-3.0.0/modules/core/src/matrix.cpp, line 441
terminate called after throwing an instance of 'cv::Exception'
what(): /home/opencv-3.0.0/modules/core/src/matrix.cpp:441: error: (-215) m.dims >= 2 in function Mat
Aborted (core dumped)
这是我的代码。
using namespace cv;
using namespace std;
int keyboard; //input from keyboard
int main(int argc, char **argv)
{
IBGS *bgs;
BlobTracking* blobTracking;
blobTracking = new BlobTracking();
bgs = new FrameDifferenceBGS;
Mat img_input;
Mat img_blob;
//create the capture object
VideoCapture capture(argv[1]);
if(!capture.isOpened()){
//error in opening the video input
cerr << "Unable to open video file: " << argv[1] << endl;
exit(EXIT_FAILURE);
}
//read input data. ESC or 'q' for quitting
while( (char)keyboard != 'q' && (char)keyboard != 27 ){
//read the current frame
if(!capture.read(img_input)) {
cerr << "Unable to read next frame." << endl;
cerr << "Exiting..." << endl;
exit(EXIT_FAILURE);
}
cv::Mat img_mask;
cv::Mat img_bkgmodel;
// by default, it shows automatically the foreground mask image
bgs->process(img_input, img_mask, img_bkgmodel);
cv::Mat img_mask_erode_and_dilate;
int erosion_size=3;
cv::Mat element = cv::getStructuringElement( cv::MORPH_RECT,
cv::Size( 2*erosion_size + 1, 2*erosion_size+1 ),
cv::Point( erosion_size, erosion_size ) );
// Erode the frame
cv::erode(img_mask, img_mask_erode_and_dilate, element);
// Dilate the frame
cv::dilate(img_mask, img_mask_erode_and_dilate, element);
// Show before and after dilate and erode
cv::imshow("Frame Before Erode or Dilate", img_mask);
cv::imshow("Frame AFTER Erode and Dilate", img_mask_erode_and_dilate
//get the input from the keyboard
keyboard = waitKey( 30 );
}
//delete capture object
capture.release();
delete bgs;
cvDestroyAllWindows();
return 0;
}
如果我使用原始帧而不是处理过的帧,那么一切都可以解决。我怀疑背景减法算法返回的灰度图像正在发生什么事情
答案 0 :(得分:4)
错误告诉您输入图像有多个通道。而是对二进制掩模图像执行变形操作。由canny函数或灰度图像的阈值处理产生。
所以请检查输入掩码代替它包含的内容。