C + + OpenCV read video and call camera __c++

Source: Internet
Author: User

OpenCV through the Videocapture class, to read the video, call the camera

Read Video:

1. Instantiate and initialize first

Videocapture capture;

Capture.open ("1.avi");

2. Initialize simultaneously with instantiation

Videocapture Capture ("1.avi");


Play Video:

After the video reads like a Videocapture class object, use a loop to display each frame

while (1)

{

Mat frame;

capture>>frame;

Imshow ("read video", frame);

Waitkey (30);

}


Call camera

Change the code videocapture capture ("1.avi") to 1.avi in 0.



Let's look at a piece of code:

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

int main ()
{
	//read video or webcam
	videocapture capture ("1.avi");

	while (true)
	{
		Mat frame;
		Capture >> frame;
		Imshow ("read video", frame);
		Waitkey (a);	Delay of
	0;
This is to read the file and then play it:

The following are the results of the operation:


Here's a look at the engineering catalog.


Here's the code to open the camera:

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

int main ()
{
	//read video or Camera
	Videocapture capture (0);

	while (true)
	{
		Mat frame;
		Capture >> frame;
		Imshow ("read video", frame);
		Waitkey (a);	Delay of
	return
	0;
}
Run Result:


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.