OpenCV Open the camera but can't capture the image solution

Source: Internet
Author: User

Write OpenCV program, turn on the camera, behold the program error on the book, can open the camera, but can't capture the image

I tried it with my brother's computer, it worked, no problem.

On the internet for a long time, tried a lot of methods, no use, and later in a Baidu know to find a way to success

http://zhidao.baidu.com/link?url=8I5s8NuD3uID9-8oAYb2uFf-thH6j-i940Tgil9XPpYqwB7olGEEsKg3I3Jm4pPdTnVz1q__ Ivkxaz42vvtfpr_3geqhv1c-idzz_y33aum


#include <opencv2/opencv.hpp>
#include <iostream>
using namespace CV;
using namespace std;

String Name= "my";

int main ()
{
	videocapture capture;//declare video read-in class
	Capture.open (0);//read in video from the camera 0 means read from the camera

	if (! Capture.isopened ())///first to determine whether to turn on
	the camera {
		cout<< "can not open";
		Cin.get ();
		return-1;
	}

	Namedwindow (name);

	while (1) { 
		mat cap;//define a mat variable to store the image of each frame
		capture>>cap;//Read the current frame
		if (!cap.empty ())// Determines whether the current frame captures success * * This step is important
			imshow (name, CAP);//If the current frame captures successfully, the
		else
			cout<< "Can not" is displayed; 
		Waitkey (30); Delay 30 milliseconds
	}

	return 0;
}



I don't know if you guys saw it.

can not means that the program does not read the image

That's why I went wrong, the first frame of the camera can't be read in .


The most important problem is solved, but there is a small problem, the window name appears garbled,

The problem hasn't been solved yet.

I'll fix it later and put it up.

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.