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).
The following code is what I tried to do:
Rect faceTracked(Estimated_int.at<int>(0, 0), Estimated_int.at<int>(
1, 0), Estimated_int.at<int>(2, 0), Estimated_int.at<int>(3, 0));
std::vector <Rect> facesVector;
facesVector[i] = faceTracked;
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:
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)
That error only happens when the statement facesVector[i] = faceTracked is called. What am I doing wrong? The entire function code is shown below:
void trackFace (Mat& frame, std::vector<Rect> faces) {
for (size_t i = 0; i < faces.size(); i++) {
X = A * X_p;
transpose(A, A_transpose);
P = A * P_p * A_transpose;
if (faces.size() > 0) {
Mat Z = (Mat_<float>(4, 1) << 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_<int>(4, 1) << cvRound(Estimated.at<float>(0, 0)), cvRound(
Estimated.at<float>(1, 0)), cvRound(Estimated.at<float>(2, 0)), cvRound(
Estimated.at<float>(3, 0)));
rectangle(frame, Point((Estimated_int.at<int>(0, 0)), (Estimated_int.at<int>(1, 0))),
Point((Estimated_int.at<int>(2, 0)), (Estimated_int.at<int>(3, 0))),
Scalar(255, 255, 102, 255), 2, 8, 0);
Rect faceTracked(Estimated_int.at<int>(0, 0), Estimated_int.at<int>(
1, 0), Estimated_int.at<int>(2, 0), Estimated_int.at<int>(3, 0));
std::vector <Rect> facesVector;
facesVector[i] = faceTracked;
}
}
}
@edit: All matrix were properly initialized on a header file. It was tested before and it is working.