Note that there are some explanatory texts on larger screens.

plurals
  1. POImage copied in ROI doesn't follow camera c++. How to fix this?
    text
    copied!<p>I work on Windows7 x64 with opencv and Visual Studio 2010 on c++ language.</p> <p>I created a project in which I show to my camera a rectangular area (call <strong><em>squared_surface</em></strong>). This area is recognized by tracing a rectangle with <code>findSquare ()</code> and <code>drawSquares ()</code> of opencv file <code>squares.cpp</code>. On this rectangle I create a ROI and there I copy an image (let's call <strong><em>copied_image)</em></strong></p> <p>My problem is that when I rotate <strong><em>squared_surface</em></strong> (in front of camera), <strong><em>copied_image</em></strong> does not follow it.</p> <p>I think I need to use the functions <code>getPerpective ()</code> and <code>warpPerspective ()</code>, but I do not know how. Can anyone help me?</p> <p>Here's the code:</p> <pre><code>int main(){ vector&lt;vector&lt;Point&gt; &gt; squares; cv::VideoCapture cap(0); for (;;) { cv::Mat image; cap &gt;&gt; image; findSquares(image, squares); for (size_t i = 0; i &lt; squares.size(); i++) { Rect rectangle = boundingRect(Mat(squares[i])); if((rectangle.width&lt;=630)&amp;&amp; (rectangle.width &gt;= 420) &amp;&amp; (rectangle.height&lt;= 490) &amp;&amp;(rectangle.height &gt;= 250 )) { cv::Size dsize = Size(rectangle.width, rectangle.height); Mat img1 = imread("scacchiera.jpg"); cv::resize(img1,img1,dsize,0,0, INTER_LINEAR); Rect roi (rectangle.x, rectangle.y,rectangle.width, rectangle.height); Mat imageRoi(image, roi); img1.copyTo(imageRoi); } } drawSquares(image, squares); imshow("camera",image); if(waitKey(30) &gt;= 0) break; } return 0; } </code></pre> <p><img src="https://i.stack.imgur.com/QD8Wx.jpg" alt="enter image description here"> <img src="https://i.stack.imgur.com/k8Qaq.jpg" alt="enter image description here"></p> <p>Thanks!</p> <p><strong>EDIT.</strong> I was thinking of rotating <strong>Copied_image</strong>, so it follows <strong>Squared_surface</strong>, but I need to calculate the angle of rotation of the rectangle identified by the camera (drawn in red in the above images). Is there a way to calculate this angle? </p> <p>Or how can I do so that <strong>Copied_image</strong> follows <strong>Squared_surface</strong> when I rotate squared_surface?</p> <p>Help me, please!</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