Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mat OpenCv的分配错误 我正在使用OpenCV和C++进行一个项目,我发现以下问题:在初始化一个垫子后,用下面的语句< /P> Mat or_mat=Mat(img->height,img->width,CV_32FC1);_C++_Opencv - Fatal编程技术网

Mat OpenCv的分配错误 我正在使用OpenCV和C++进行一个项目,我发现以下问题:在初始化一个垫子后,用下面的语句< /P> Mat or_mat=Mat(img->height,img->width,CV_32FC1);

Mat OpenCv的分配错误 我正在使用OpenCV和C++进行一个项目,我发现以下问题:在初始化一个垫子后,用下面的语句< /P> Mat or_mat=Mat(img->height,img->width,CV_32FC1);,c++,opencv,C++,Opencv,检查以下值 or_mat.at <float> (i, j) = atan (fy / fx) / 2 +1.5707963; 我必须计算指纹图像的局部方向,以下代码我省略了几个没有错误的语句和计算。我将三次检查您是否正确索引。下面的代码显示了我初始化一个满是零的矩阵,然后使用at.at操作符用一些浮点值填充它。它编译和运行良好: int main() { int height = 10; int width = 3; // Initialise or_

检查以下值

or_mat.at <float> (i, j) = atan (fy / fx) / 2 +1.5707963;

我必须计算指纹图像的局部方向,以下代码我省略了几个没有错误的语句和计算。

我将三次检查您是否正确索引。下面的代码显示了我初始化一个满是零的矩阵,然后使用at
.at
操作符用一些浮点值填充它。它编译和运行良好:

int main()
{

    int height = 10;
    int width = 3;

    // Initialise or_mat to with every element set to zero
    cv::Mat or_mat = cv::Mat::zeros(height, width, CV_32FC1);
    std::cout << "Original or_mat:\n" << or_mat << std::endl;

    // Loop through and set each element equal to some float
    float value = 10.254;
    for (int i = 0; i < or_mat.rows; ++i)
    {
        for (int j = 0; j < or_mat.cols; ++j)
        {
            or_mat.at<float>(i,j) = value;
        }
    }

    std::cout << "Final or_mat:\n" << or_mat << std::endl;

    return 0;
}
intmain()
{
整数高度=10;
整数宽度=3;
//将每个元素设置为零,初始化或_mat to
cv::Mat或_Mat=cv::Mat::Zero(高度、宽度、cv_32FC1);

std::cout首先,指定通道:
CV_32FC1
CV_32FC3
。然后发布相关代码。我尝试使用以下语句仅使用Mat初始化结构:Mat或_Mat=Mat(img->height,img->width,CV_32F);并如上所述分配值。错误仍然存在。您似乎在使用
CvMat*
cv::Mat
-这是不同的结构,您可能应该选择其中一种。请注意,在
CvMat
中,CvMat
被视为过时…我选择使用cv::Mat和您看到的代码。问题不在于lue被计算并分配到位置(i,j)…导致一些问题,并且没有分配正确的值。我用新代码更正了帖子。我只使用cv::mat,不使用Cvmat*
int main()
{

    int height = 10;
    int width = 3;

    // Initialise or_mat to with every element set to zero
    cv::Mat or_mat = cv::Mat::zeros(height, width, CV_32FC1);
    std::cout << "Original or_mat:\n" << or_mat << std::endl;

    // Loop through and set each element equal to some float
    float value = 10.254;
    for (int i = 0; i < or_mat.rows; ++i)
    {
        for (int j = 0; j < or_mat.cols; ++j)
        {
            or_mat.at<float>(i,j) = value;
        }
    }

    std::cout << "Final or_mat:\n" << or_mat << std::endl;

    return 0;
}