Opencv collects and saves video/camera data

Source: Internet
Author: User

It is purely self-entertainment, and does not conduct in-depth learning on the use of opencv. It is also the most basic thing to use opencv to open a video file or enable the camera to collect and save it.

1. Install the configuration Environment

Vs2008 install and configure opencv, 2005, 2010 steps should be similar, Here provide Web site, no more detailed than this http://www.opencv.org.cn/index.php/VC_2008_Express%E4%B8%8B%E5% AE %89%E8%A3%85OpenCV2.3.1

Ii. program code

For Learning opencv, we recommend "opencv tutorial-basics". Chapter 3 describes the video in detail. The following code is provided:

# Include "stdafx. H "# include" CV. H "# include" highgui. H "int main (INT argc, char ** argv) {cvcapture * capture = 0; iplimage * frame = 0; capture = cvcapturefromavi (" video. avi "); // capture = cvcapturefromcam (0); // Replace the double FPS = cvgetcaptureproperty (capture, cv_cap_prop_fps) with the camera ); // video frame rate // int FPS = 25; // capture frame rate, which affects the playback speed of produced files. Frame = cvqueryframe (capture ); // capture a frame first. cvvideowriter * Writer = 0; // Save the frame with int iscolol = 1; // int framew = 640; // int frameh = 480; writer = cvcreatevideowriter ("out. avi ", cv_fourcc ('F', 'l', 'V', '1'), FPS, cvsize (frame-> width, frame-> height), iscolol ); // The size here does not seem to work. // cvnamedwindow ("window", 1); // For (INT I = 0; I <50; I ++) // 2 seconds for (;) // always read {frame = cvqueryframe (capture); cvwriteframe (writer, frame); cvshowimage ("window", frame ); // display the cvwaitkey (1000/FPs) of an image; // video speed} cvreleasevideowriter (& writer); cvreleaseimage (& frame); cvreleasecapture (& capture ); cvdestroywindow ("window"); Return 0 ;}

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.