Ask Your Question

Revision history [back]

Overlay one video feed on another video feed.

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?

#include "opencv2/opencv.hpp"

include <iostream>

using namespace std; using namespace cv;

int main() {

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;

}

Overlay one video feed on another video feed.

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?

#include "opencv2/opencv.hpp"

include <iostream>

using namespace std; using namespace cv;

int main() {

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;

}