title: Initialize a vector of Rect with some Rect objects - Opencv C++
body: <p>I'm working on a face tracking project with Kalman Filter. Basically, I want to store the result of my tracking application (int x, int y, int width, int heigth)  on a vector of Rectangles, (i.e. each face will be stored on a Rect, then all the Rects will be stored on a vector of Rect).</p>
  
  <p>The following code is what I tried to do: </p>
  
  <pre><code>Rect faceTracked(Estimated_int.at&lt;int&gt;(0, 0), Estimated_int.at&lt;int&gt;(
                  1, 0), Estimated_int.at&lt;int&gt;(2, 0), Estimated_int.at&lt;int&gt;(3, 0));
          std::vector &lt;Rect&gt; facesVector;
          facesVector[i] = faceTracked;
  </code></pre>
  
  <p>Where "Estimated_int" is the result matrix (4,1) of KF. When I run this code the following error is displayed on Android Studio Logcat, then the app crashes: </p>
  
  <blockquote>
    <p>11-21 17:36:43.729 10735-11321/com.example.android.ndkopencvtest1 A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 11321 (Thread-5)</p>
  </blockquote>
  
  <p>That error only happens when the statement <b>facesVector[i] = faceTracked</B> is called. What am I doing wrong? The entire function code is shown below: </p>
  
  <pre><code>void trackFace (Mat&amp; frame, std::vector&lt;Rect&gt; faces) {
  for (size_t i = 0; i &lt; faces.size(); i++) {
      X = A * X_p;
      transpose(A, A_transpose);
      P = A * P_p * A_transpose;
      if (faces.size() &gt; 0) {
          Mat Z = (Mat_&lt;float&gt;(4, 1) &lt;&lt; faces[i].x, faces[i].y, faces[i].x + faces[i].width,
                  faces[i].y + faces[i].height);
          Y = Z - H * X;
          transpose(H, H_transpose);
          S = H * P * H_transpose + R;
          invert(S, S_inverse);
          K = P * H_transpose * S_inverse;
          X_p = X + K * Y;
          Estimated = H * X_p;
          P_p = (Ident - K * H) * P;
          Mat Estimated_int = (Mat_&lt;int&gt;(4, 1) &lt;&lt; cvRound(Estimated.at&lt;float&gt;(0, 0)), cvRound(
                  Estimated.at&lt;float&gt;(1, 0)), cvRound(Estimated.at&lt;float&gt;(2, 0)), cvRound(
                  Estimated.at&lt;float&gt;(3, 0)));
          rectangle(frame, Point((Estimated_int.at&lt;int&gt;(0, 0)), (Estimated_int.at&lt;int&gt;(1, 0))),
                    Point((Estimated_int.at&lt;int&gt;(2, 0)), (Estimated_int.at&lt;int&gt;(3, 0))),
                    Scalar(255, 255, 102, 255), 2, 8, 0);
          Rect faceTracked(Estimated_int.at&lt;int&gt;(0, 0), Estimated_int.at&lt;int&gt;(
                  1, 0), Estimated_int.at&lt;int&gt;(2, 0), Estimated_int.at&lt;int&gt;(3, 0));
          std::vector &lt;Rect&gt; facesVector;
          facesVector[i] = faceTracked;
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>@edit: All matrix were properly initialized on a header file. It was tested before and it is working.</p>