OpenCV Open the camera and create a new window to display

Source: Internet
Author: User

The basic functions used by several programs are as follows:

*******************************************************************

cvcreatecameracapture

Initialize get video from camera

cvcapture* cvcreatecameracapture (int index);
Index of the camera to use. It doesn't matter if you have only one camera or a camera, so use the parameter-1.

The function Cvcreatecameracapture assigns and initializes the cvcapture structure to the video stream from the camera. There are currently two interfaces available under Windows: Video for Windows (VFW) and Matrox Imaging Library (MIL), and two interfaces under Linux: v4l and FireWire (IEEE1394).

Release this structure, using the function cvreleasecapture.

The return value is a

Cvcapture
************************************************************************************************
Cvcapture

Video capture structure

typedef struct CVCAPTURE cvcapture;

struct Cvcapture does not have a public interface, it can only be used as a parameter to the video fetch function.

******************************************************************************

Cvqueryframe fetches and returns a frame iplimage* Cvqueryframe (cvcapture* capture) from the camera or file, capturing the structure of the capture video. The function Cvqueryframe fetches a frame from the camera or file and then extracts and returns the frame. This function is simply a combination of the function Cvgrabframe and the function cvretrieveframe called together. The returned image can not be released or modified by the user. The Cvqueryframe parameter is a pointer to the cvcapture structure. Used to load the next frame of video file into memory, returning a pointer to the current frame. Unlike Cvloadimage, Cvloadimage allocates memory space for an image, and Cvqueryframe uses memory already allocated in the cvcapture structure. In this case, it is not necessary to release the returned image pointer through Cvreleaseimage (), and when the Cvcapture structure is released, the memory space corresponding to each frame of the image is freed.

Break loop If grab frame is empty

Otherwise the captured frame is displayed on the created window

Cvshowimage ("video", Pframe);

After the current frame is displayed

Char C=cvwaitkey (33);
if (c==27) break;

We wait for 33ms

If the user triggers the key, the ASCII value of the key is given to C

If C is ESC (ASCII 27), the loop exits

Finally release capture and window

Cvreleasecapture (&pcapture);
Cvdestroywindow ("video");

Finally frees up resource usage

The program code is as follows:

======================================================================

#include <cv.h> #include <cxcore.h> #include 


The results of the operation are as follows:

OpenCV Open the camera and create a new window to display

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.