Opencv Mat访问违规

Opencv Mat access violation

本文关键字:访问 Mat Opencv      更新时间:2023-10-16

运行以下代码时:

for(int i = 0; i < result.size(); ++i) {
   for(int j = 0; j < result[i].size(); ++j) {
     if(anchor_map->at<float>(i, j) > 0) {
     }
   }
}

由于result.size()1200和result[i].size(。

问题是,每次在i=1197,j=1436时,它都会因访问违规而中断,而anchor_map在开始时被设置为零,在右像素处为锚点所在的像素。

是在windows 7上的Visual Studio 12中制作的64位

试试这个:

using namespace cv;
void main (void)
{
    Mat anchor_map(1200,1600,CV_8UC1);
    for(int i = 0; i < anchor_map.rows; ++i) {
        for(int j = 0; j < anchor_map.cols; ++j) {
            if(anchor_map.at<unsigned char>(i, j) > 0) {
            }
        }
    }
    getchar();
}