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