OPENCV, open the webcam.

Source: Internet
Author: User

Free from the students found a openwrt, suddenly think up OpenCV can easily open their own camera, just began to learn OpenCV opened a number of notebook camera, OPENCV can open webcam it. Search data in Baidu to see others have done opencv+openwrt do wireless monitoring project, feel OpenCV from webcam to get video can also be achieved, other forums also found relevant information. I tried on my own computer to try the beginning is always not, the direct error can not find the camera, this problem is very depressing to me. But in the end it was solved:


Attached below is a program:

#include "Cv.h"
#include "highgui.h"
#include <iostream>


int main (int, char**) {
Cv::videocapture Vcap;
Cv::mat image;
Cvcapture *capture;
Const std::string videostreamaddress = "Http://192.168.1.1:8080/?action=stream?dummy=param.mjpg";
/* It May is an MJPEG stream,
e.g. "http://user:pass@cam_address:8081/cgi/mjpg/mjpg.cgi?.mjpg" * *


Open the video stream and make sure it ' s opened
if (!vcap.open (videostreamaddress)) {
Std::cout << "Error opening video stream or file" << Std::endl;
return-1;
}


Create Output window for displaying frames.
It ' s important to create this window outside of the ' for ' Loop
Otherwise this window would be created automatically the
' Imshow (...) ', which is very inefficient.
Cv::namedwindow ("Output window");




for (;;) {
if (!vcap.read (image)) {
Std::cout << "No frame" << Std::endl;
Cv::waitkey ();
}
Cv::imshow ("Output window", image);


if (Cv::waitkey (1) >= 0) break;

}
}







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.