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: