OpenCV Getting started learning to read USB camera images, real-time display

Source: Internet
Author: User
First, create a new source program file for. CPP, for example,
Gedit Test.cpp

Add the following program to the file:

#include <opencv2/core/core.hpp>    
#include <opencv2/highgui/highgui.hpp>    
using namespace CV;  
      
int main (int argc, char** argv) {
    Cvnamedwindow ("video");

    cvcapture* capture = cvcreatecameracapture (1);
    iplimage* frame;

    while (1) {
        frame = cvqueryframe (capture);
        if (!frame) break;
        Cvshowimage ("video", frame);

        char C = cvwaitkey (+);
        if (c==27) break;
    }

    Cvreleasecapture (&capture);
    Cvdestroywindow ("video");
    return 0;
}
Save exit. The compilation chain is delivered as an executable file.
g++ test.cpp-o test-i/usr/local/include/opencv-i/usr/local/include/opencv2-l/usr/local/lib/*.so

Insert Camera, run program

./test
Done.

cvcreatecameracapture (), initialize get video from camera

cvcapture* cvcreatecameracapture (int index);

If there is only one camera, the parameter value takes 0. When the parameter is set to-1, OpenCV opens a window for the user to select the camera to use.


cvqueryframe () fetches a frame from the camera or file and then extracts and returns the frame. The returned image can not be released or modified by the user.

iplimage* Cvqueryframe (cvcapture* capture);


Cvshowimage ()that is used to display the image in the specified window.

void Cvshowimage (const char* name, const cvarr* image);


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.