2013-04-08 146 views
0

我想从摄像机获取Partial图像。我有这个代码。这段代码给了我相机的矩形。我需要得到矩形包含图像。从Opencv摄像机获取Partial图像

for(int i=0;i<(detectRect_face ? detectRect_face->total:0); i++) 
    { 
     CvRect* r = (CvRect*)cvGetSeqElem(detectRect_face, i); 
     CvPoint pt1 = { r->x+20, r->y+20 }; 
     CvPoint pt2 = { r->x + r->width-20, r->y + r->height-10 }; 
     cvRectangle(frame, pt1, pt2, CV_RGB(255,0,0), 1,8, 0); 

     //I need to write here a method to get this rectangle include image. 
    } 

回答

1

您可以使用cvSetImageROI和cvCopy方法来裁剪图像。

IplImage *dst = // Prepare partition size image. 
cvSetImageROI(frame, r); 
cvCopy(frame, dst); 
cvResetImageROI(frame);