使用一些Rect对象初始化Rect的向量 - Opencv C ++

时间:2017-11-21 19:47:21

标签: c++ opencv android-ndk face-detection

我正在使用卡尔曼滤波器进行面部跟踪项目。基本上,我想将跟踪应用程序的结果(int x,int y,int width,int heigth)存储在矩形向量上(即每个面将存储在一个Rect上,然后所有的Rects都将存储在一个Rect的矢量。

以下代码是我尝试做的:

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;

其中“Estimated_int”是KF的结果矩阵(4,1)。当我运行此代码时,Android Studio Logcat上会显示以下错误,然后应用程序崩溃:

  

11-21 17:36:43.729 10735-11321 / com.example.android.ndkopencvtest1 A / libc:致命信号11(SIGSEGV),代码1,故障地址0x0 in tid 11321(Thread-5)

只有在调用语句 facesVector [i] = faceTracked 时才会发生该错误。我究竟做错了什么?整个功能代码如下所示:

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:所有矩阵都在头文件上正确初始化。它之前已经过测试,并且正在运行。

0 个答案:

没有答案