Ошибка при установке значения для элемента матрицы: OpenCV(4.5.1) Ошибка: Ошибка утверждения

#c #opencv

Вопрос:

Я получаю сообщение об ошибке при запуске функции ниже.

 OpenCV(4.5.1) Error: Assertion failed (((0x28442211 >> ((traits::Depth<_Tp>::value) amp; ((1 << 3) - 1))*4) amp; 15) == elemSize1()) in cv::Mat::at, file C:OpenCV-4.2.0opencvbuildincludeopencv2coremat.inl.hpp, line 873
 

Я провел некоторую отладку и обнаружил, что приведенная ниже строка вызывает ошибку.
Что я мог сделать не так?

 source_matrix.at<float>(m   1, 0) = 0;
 

Функция:

 void compute_projection_matrix(Mat image_points, Mat object_points, Mat projection_matrix) {
    
    Mat eigenvectors = Mat(12, 12, CV_64F);
    Mat eigenvalues = Mat(12, 1, CV_64F);
    Mat source_matrix = Mat(NUM_POINTS * 2, 12, CV_64F);
    Mat destination_matrix = Mat(12, NUM_POINTS * 2, CV_64F);
    Mat final_matrix = Mat(12, 12, CV_64F);

    
    int point = 0, m = 0;
    while (m < (NUM_POINTS * 2))
    {

        float x = object_points.at<float>(point, 0);
        float y = object_points.at<float>(point, 1);
        float z = object_points.at<float>(point, 2);
        float xprime = image_points.at<float>(point, 0);
        float yprime = image_points.at<float>(point, 1);
        
        source_matrix.at<float>(m   1, 0) = 0;
        source_matrix.at<float>(m   1, 1) = 0;
        source_matrix.at<float>(m   1, 2) = 0;
        source_matrix.at<float>(m   1, 3) = 0;
        source_matrix.at<float>(m   1, 4) = x;
        source_matrix.at<float>(m   1, 5) = y;
        source_matrix.at<float>(m   1, 6) = z;
        source_matrix.at<float>(m   1, 7) = 1;
        source_matrix.at<float>(m   1, 8) = -(yprime * x);
        source_matrix.at<float>(m   1, 9) = -(yprime * y);
        source_matrix.at<float>(m   1, 10) = -(yprime * z);
        source_matrix.at<float>(m   1, 11) = -yprime;
        
        source_matrix.at<float>(m, 0) = x;
        source_matrix.at<float>(m, 1) = y;
        source_matrix.at<float>(m, 2) = z;
        source_matrix.at<float>(m, 3) = 1;
        source_matrix.at<float>(m, 4) = 0;
        source_matrix.at<float>(m, 5) = 0;
        source_matrix.at<float>(m, 6) = 0;
        source_matrix.at<float>(m, 7) = 0;
        source_matrix.at<float>(m, 8) = -(xprime * x);
        source_matrix.at<float>(m, 9) = -(xprime * y);
        source_matrix.at<float>(m, 10) = -(xprime * z);
        source_matrix.at<float>(m, 11) = -xprime;
        point  ;
        m  = 2;
    }

    transpose(source_matrix, destination_matrix);
    multiply(destination_matrix, source_matrix, final_matrix);
    eigen(final_matrix, eigenvectors, eigenvalues);

    int index = 0, row = 0, col = 0;
    while (row < 3)
    {
        while (col < 4)
        {
            projection_matrix.at<float>(row, col) = eigenvectors.at<float>(11, index  );
            col  ;
        }
        col = 0;
        row  ;
    }
    
}

 

Комментарии:

1. Вы создали матрицы double и пытаетесь получить к ним доступ как float