我是图像处理的初学者,刚刚开始为一个项目摆弄 OpenCV。我有一个行人行走的视频信号。我正在运行 pedestrain.cpp 程序,该程序使用 HOG 进行 bckgound 减法并想做一些类似于所附图像的事情。我在检测到 peson 后做了以下操作
int main (int argc, const char * argv[])
{
VideoCapture cap(0);
cap.set(CV_CAP_PROP_FRAME_WIDTH, 320);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240);
if (!cap.isOpened())
return -1;
Mat img;
HOGDescriptor hog;
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
if((WriteFP=fopen("output.txt", "w")) == NULL) ErrorExit(ER_WRITE_OPEN);
namedWindow("video capture", CV_WINDOW_AUTOSIZE);
namedWindow("Motion", CV_WINDOW_AUTOSIZE);
while (true)
{
cap >> img;
if (!img.data)
continue;
vector<Rect> found, found_filtered;
hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2);
size_t i, j;
for (i=0; i<found.size(); i++)
{
Rect r = found[i];
for (j=0; j<found.size(); j++)
if (j!=i && (r & found[j])==r)
break;
if (j==found.size())
found_filtered.push_back(r);
}
for (i=0; i<found_filtered.size(); i++)
{
Rect r = found_filtered[i];
r.x += cvRound(r.width*0.1);
r.width = cvRound(r.width*0.8);
r.y += cvRound(r.height*0.06);
r.height = cvRound(r.height*0.9);
rectangle(img, r.tl(), r.br(), cv::Scalar(0,255,0), 2);
}
imshow("video capture", img);
IplImage *mat_img;
mat_img=cvCloneImage(&(IplImage)img);
cvThreshold(img,img, 0, 255, CV_THRESH_BINARY_INV);
cvDilate(img, img, 0,1);
cvErode(img, img, 0, 0);
cvFindContours(img, storage_contours, &contours, sizeof(CvContour),
CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));
}
但是,我无法获得图片中的输出帧。有人可以告诉我需要做什么。谢谢