Opencv -- write the camera into a video file

Source: Internet
Author: User

We mainly use Opencv to open the camera code and write the video function. However, we only need to note that the camera does not seem to have a frame rate. In cvCreateVideoWriter, we need to set it by ourselves.

1 # include "cv. h "2 # include" highgui. h "3 4 int main (int argc, char ** argv) 5 {6 cvNamedWindow (" camera ", CV_WINDOW_AUTOSIZE); 7 argc = 1; 8 CvCapture * capture; 9 capture = cvCreateCameraCapture (1); // if it cannot be changed to-, 1, try 10 assert (capture! = NULL); 11 IplImage * frame; 12 CvSize size = cvSize (int) cvGetCaptureProperty (capture, CV_CAP_PROP_FRAME_WIDTH), 13 (int) cvGetCaptureProperty (capture, CV_CAP_PROP_FRAME_HEIGHT )); 14 15 double fps = cvGetCaptureProperty (16 capture, 17 CV_CAP_PROP_FPS // frame rate 18 ); 19 CvVideoWriter * writer = cvCreateVideoWriter (// On linux Will only work if you 've installed ffmpeg development files correctly, 20 "D: \ Opencv \\ TestData \ camera. avi ", // otherwise segmentation fault. windows probably better.21 CV_FOURCC ('D', 'x', '5', '0'), 22 15, // The Frame Rate of the camera is 0, it is set to 1523 size24); 25 IplImage * imgWrite = cvCreateImage (size, 8, 3); 26 while (1) {27 frame = cvQueryFrame (capture); 28 if (! Frame) 29 break; 30 char c = cvWaitKey (10); 31 if (c = 27) break; 32 cvCopy (frame, imgWrite); 33 cvWriteToAVI (writer, imgWrite ); 34 cvShowImage ("camera", frame); 35} 36 37 cvReleaseCapture (& capture); 38 cvReleaseVideoWriter (& writer); 39 cvDestroyWindow ("camera"); 40 return 0; 41}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.