我在absdiff(grayImg, bgImg, diffImg);
上有错误
而且我不明白为什么这是错误的。
VideoCapture capture;
capture.open(0);
if (!capture.isOpened()) {
printf("error\n");
return -1;
}
Mat grayImg;
Mat diffImg;
Mat bgImg = imread("BgImg.jpg");
Mat frame;
std::vector<std::vector<cv::Point> > contours;
for (;;) {
capture >> frame;
cvtColor(frame, grayImg, CV_RGB2GRAY);
absdiff(grayImg, bgImg, diffImg);
threshold(diffImg, diffImg, 50, 255, CV_THRESH_BINARY);
findContours(diffImg, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
drawContours(frame, contours, -1, CV_RGB(255, 0, 0), 1, 8);
imshow("capture", frame);
imshow("diffImg", diffImg);
char chKey = waitKey(10);
if (chKey == 27) break;
}
destroyAllWindows();
return 0;