Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <opencv2/core.hpp>
- #include <opencv2/videoio.hpp>
- #include <opencv2/highgui.hpp>
- #include <iostream>
- using namespace cv;
- using namespace std;
- int main(int, char**)
- {
- Mat frame;
- //--- INITIALIZE VIDEOCAPTURE
- VideoCapture cap;
- // open the default camera using default API
- // cap.open(0);
- // OR advance usage: select any API backend
- int deviceID = 0; // 0 = open default camera
- int apiID = cv::CAP_ANY; // 0 = autodetect default API
- // open selected camera using selected API
- cap.open(deviceID, apiID);
- // check if we succeeded
- if (!cap.isOpened()) {
- cerr << "ERROR! Unable to open camera\n";
- return -1;
- }
- //--- GRAB AND WRITE LOOP
- cout << "Start grabbing" << endl
- << "Press any key to terminate" << endl;
- auto smallImage = imread("index.png", -1);
- for (;;)
- {
- // wait for a new frame from camera and store it into 'frame'
- cap.read(frame);
- cv::Rect roi( cv::Point( 50, 50 ), smallImage.size() );
- smallImage.copyTo( frame( roi ) );
- // check if we succeeded
- if (frame.empty()) {
- cerr << "ERROR! blank frame grabbed\n";
- break;
- }
- // show live and wait for a key with timeout long enough to show images
- imshow("Live", frame);
- if (waitKey(5) >= 0)
- break;
- }
- // the camera will be deinitialized automatically in VideoCapture destructor
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment