i cant write to the file mat [closed]

asked 2014-05-29 06:21:14 -0600

updated 2014-05-29 06:29:16 -0600

berak gravatar image

here is a function of the cascade Haar. But writer_finished.write writes the file only one image.I do something wrong?

void detect(Mat frame)
{
vector<Rect> faces;
Mat frame_gray;
Mat centers(8, 1, CV_32FC1);
//const char *filename_finished = "capture_обработанное.avi";
double fps = 15;
CvSize size = cvSize(640, 480);
VideoWriter writer_finished("capture_обработанное.avi", CV_FOURCC('X', 'V', 'I', 'D'), fps, size, 1);

cvtColor(frame, frame_gray, CV_BGR2GRAY);
equalizeHist(frame_gray, frame_gray);

//нахождение лица
face_cascade.detectMultiScale(frame_gray, faces, 1.15, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(75, 75));

for (size_t i = 0; i < faces.size(); i++)
{
    Point center(faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5);
    ellipse(frame, center, Size(faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar(0, 0, 255), 4, 8, 0);

    Mat faceROI = frame_gray(faces[i]);
    cout << "x " << faces[i].x << " y " << faces[i].y<< endl;


}
if (!frame.empty()) writer_finished.write(frame);
//показываем
imshow(window_name, frame);

    }

    }
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-09-27 10:51:51.848244

Comments

2

your code only writes 1 image.

are you calling that function multiple times ? then move the videowriter construction out of it, and pass it as an argument instead. (each time you build a new videowriter, it starts a new movie)

berak gravatar imageberak ( 2014-05-29 06:26:24 -0600 )edit

No, I call this function once

soulloli gravatar imagesoulloli ( 2014-05-29 06:31:46 -0600 )edit

Thank you. It earned awwwww~

soulloli gravatar imagesoulloli ( 2014-05-29 06:39:35 -0600 )edit