我正在尝试在移动的对象上创建一个边界矩形。但是,我的Deb会话失败了一个表达式:_pFirstBlock == pHead
这是我的代码。需要帮助!
这是我的过程视频功能。我正在使用背景减法。
void processVideo(char* videoFilename) {
//create the capture object
VideoCapture capture(videoFilename);
if (!capture.isOpened()){
//error in opening the video input
cerr << "Unable to open video file: " << videoFilename <<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(frame)) {
cerr << "Unable to read next frame." << endl;
cerr << "Exiting..." << endl;
exit(EXIT_FAILURE);
}
//update the background model
//AND HERE!!!
pMOG->operator()(frame, fgMaskMOG);
dilate(fgMaskMOG, x, NULL);
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(x, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(2 ,0));
vector<vector<Point> > contours_poly(contours.size());
vector<Rect> boundRect(contours.size());
for (int i = 0; i < contours.size(); i++)
{
approxPolyDP(Mat(contours[i]), contours_poly[i], 3, true);
boundRect[i] = boundingRect(Mat(contours_poly[i]));
}
// Draw polygonal contour + bonding rects + circles
Mat drawing = Mat::zeros(x.size(), CV_8UC3);
for (int i = 0; i< contours.size(); i++)
{
Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
drawContours(drawing, contours_poly, i, color, 1, 8, vector<Vec4i>(), 0, Point());
rectangle(drawing, boundRect[i].tl(), boundRect[i].br(), color, 2, 8, 0);
}