У меня проблема с извлечением переднего плана из видеокадра.
Он также извлекает несколько фоновых объектов. Я сделал снимок из примера видео, которое будет использоваться в качестве фонового изображения. Предложите мне, что нужно сделать. Было ли выбрано отдельное изображение для фонового изображения вместо того, чтобы делать снимок из видео (при условии снимок имеет более низкое разрешение, чем изображение) или другой лучший код. Код, используемый для извлечения:
int _tmain(int argc, _TCHAR* argv[])
{
IplImage *frame = NULL;
IplImage *img1 = NULL;
IplImage *grey = NULL;
IplImage *edges = NULL;
int delay = 0, key=0, i=0;
CvCapture *video = NULL;
CvCapture *video1 = NULL;
cvNamedWindow("window_name");
video = cvCreateFileCapture("sample.avi");
video1 = cvCreateFileCapture("sample.avi");
frame = cvQueryFrame(video);
img1 = cvQueryFrame(video1);
grey = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1);
edges = cvCreateImage(cvGetSize(img1), IPL_DEPTH_8U, 1);
cvShowImage("backgrnd", img1);
//get height and width using OpenCV functions
const int &rows = img1->width;
const int &cols =frame->height;
BYTE *Pixel2=0;
cvGetRawData(img1,&Pixel2,0,0);
while (frame) {
BYTE *Pixel1=0;
//extract pixels using the OpenCV function cvGetRawData
cvGetRawData(frame,&Pixel1,0,0);
//register int to increase the speed
register int r,ri,c;
//to find diffrence of 2 images by pixel to pixel comparision
for(r = 0, ri = 0; r < rows*3; r++, ri += cols)
{
for(c = 0; c < cols; c++)
{
//get the difference in pixels
Pixel1[ri + c] = Pixel1[ri + c] - Pixel2[ri + c];
//set threshold value as 100 for comparision, it can be changed to values between 50 and 200, for getting binary image
if(Pixel1[ri + c] < 150)
{
Pixel1[ri + c]=0;
}
else
Pixel1[ri + c]=255;
}//for c
}//for r, ri
Return 0;
}