Note that there are some explanatory texts on larger screens.

plurals
  1. POOverlay Image in OpenCV
    text
    copied!<p>I am trying to overlay an image over the video capture of my program with OpenCV but I am having trouble getting it to work. I set the a region of interest in the original frame taken from the webcam in the form of a rectangle. Then i copy it to the original frame. However it never shows up on the new frame captured by the webcam. I tested it and the image is loading correctly but it is not being copied to the new frame for some reason. </p> <p>Code Below in C++: </p> <pre><code>#include&lt;opencv2/core/core.hpp&gt; #include&lt;opencv2/contrib/contrib.hpp&gt; #include&lt;opencv2/highgui/highgui.hpp&gt; #include&lt;opencv2/imgproc/imgproc.hpp&gt; #include&lt;iostream&gt; #include&lt;vector&gt; using namespace std; using namespace cv; int main(){ VideoCapture cap; cap.open(0); if(!cap.isOpened()){ cerr &lt;&lt; "Error opening the webcam!" &lt;&lt; endl; return -1; } for(;;){ Mat frame; cap&gt;&gt;frame; Mat newFrame; frame.copyTo(newFrame); Mat image = imread("C:\\User\\Desktop\\images\\image.png"); int cx = (newFrame.cols - 70) / 2; if (image.data) { // Get a BGR version of the face, since the output is BGR color Mat srcBGR = Mat(face.size(), CV_8UC3); cvtColor(image, srcBGR, CV_GRAY2BGR); // Get the destination ROI (and make sure it is within the image) Rect dstRC = Rect(cx, newFrame.rows/2, 70, 70); Mat dstROI = newFrame(dstRC); // Copy the pixels from src to dst. srcBGR.copyTo(dstROI); } imshow("frame", newFrame); char key = (char) waitKey(30); // Exit this loop on escape: if(key == 27) break; } return 0; } </code></pre> <p>Any suggestions or help would be appreciated. Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload