Overlay one video feed on another video feed.

asked 2019-04-30 08:56:42 -0600

TharinduEH gravatar image

updated 2019-04-30 09:12:23 -0600

I want to place a video on a corner of another video feed. My code is based on this example. following code does not generate my desired output. could anyone please give a solution for me?

Mat mainFrame;
Mat overlayFrame;

// Create a VideoCapture object and open the input file
// If the input is the web camera, pass 0 instead of the video file name
VideoCapture capMain(0);
VideoCapture capOverlay(1);

// Check if camera opened successfully
if (!capMain.isOpened()) return 1;
if (!capOverlay.isOpened()) return 1;

// Define where the show the overlay frame 
Rect roi(0, 0, overlayFrame.cols, overlayFrame.rows);

while (1) {

    // Capture frame-by-frame
    capMain >> mainFrame; 
    capOverlay >> overlayFrame; 

    // Overlay
    Mat finalFrame = mainFrame(roi);
    overlayFrame.copyTo(finalFrame);


    // If the frame is empty, break immediately
    if (finalFrame.empty())
        break;

    // Display the resulting frame in full screen
    //namedWindow("finalFrame", WND_PROP_FULLSCREEN);
    //setWindowProperty("finalFrame", WND_PROP_FULLSCREEN, WINDOW_FULLSCREEN);
    imshow("finalFrame", finalFrame);


    // Press  ESC on keyboard to exit
    char c = (char)waitKey(25);
    if (c == 27)
        break;
}

// When everything done, release the video capture object
capMain.release();
capOverlay.release();

// Closes all the frames
destroyAllWindows();

return 0;

}

edit retag flag offensive close merge delete

Comments

and the problem is ?

berak gravatar imageberak ( 2019-05-01 01:36:31 -0600 )edit