Note that there are some explanatory texts on larger screens.

plurals
  1. POVector out of range
    primarykey
    data
    text
    <p>I am trying to draw a bounding box around contours using OpenCV. This is a real time application where all the images are grabbed from a camera real time, and Following is the important part of the code</p> <p><strong>RTMotionDetector.h</strong></p> <pre><code>vector&lt;vector&lt;Point&gt;&gt; *contours; vector&lt;vector&lt;Point&gt;&gt; *contoursPoly; </code></pre> <p><strong>RTMotionDetector.cpp</strong></p> <pre><code>RTMotionDetector::RTMotionDetector(void) { current = new Mat(); currentGrey = new Mat(); canny = new Mat(); next = new Mat(); absolute = new Mat(); cam1 = new VideoCapture(); cam2 = new VideoCapture(); contours = new vector&lt;vector&lt;Point&gt;&gt;(); contoursPoly = new vector&lt;vector&lt;Point&gt;&gt;(); boundRect = new vector&lt;Rect&gt;(); } double RTMotionDetector::getMSE(Mat I1, Mat I2) { Mat s1; //Find difference cv::absdiff(I1, I2, s1); // |I1 - I2| imshow("Difference",s1); //Do canny to get edges cv::Canny(s1,*canny,30,30,3); imshow("Canny",*canny); //Find contours findContours(*canny,*contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE); //System::Windows::Forms::MessageBox::Show(""+contours-&gt;size()); //Draw contours drawContours(*current,*contours,-1,Scalar(0,0,255),2); for(int i=0;i&lt;contours-&gt;size();i++) { cv::approxPolyDP(Mat((*contours)[i]),(*contoursPoly)[i],3,true); //boundRect[i] = boundingRect(contoursPoly[i]); } } </code></pre> <p>As soon as the following part gets executed, I am getting an error</p> <pre><code>cv::approxPolyDP(Mat((*contours)[i]),(*contoursPoly)[i],3,true); </code></pre> <p>Here is the error I am getting. </p> <p><img src="https://i.stack.imgur.com/stgqP.png" alt="enter image description here"></p> <p>If I comment out that piece of code, then no issues. I know this is <code>ArrayIndexOutOfBounds</code> issue but I really can't find a fix. May be because I am new to Windows Programming. </p> <p>It is very important that <code>contours</code> stay as a pointer instead of local variable, because local variable slowed the program in an unbelievable way. </p> <p>Please help me to fix this issue. Thank you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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