Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.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
双重空闲或内存分配错误 我是C++编程新手,我在代码的一部分遇到这个问题,错误有时是内存分配类型错误,有时是双自由错误。p>_C++_Opencv_Out Of Memory - Fatal编程技术网

双重空闲或内存分配错误 我是C++编程新手,我在代码的一部分遇到这个问题,错误有时是内存分配类型错误,有时是双自由错误。p>

双重空闲或内存分配错误 我是C++编程新手,我在代码的一部分遇到这个问题,错误有时是内存分配类型错误,有时是双自由错误。p>,c++,opencv,out-of-memory,C++,Opencv,Out Of Memory,错误代码如下所示 cv::Mat obstacles = cv::Mat::ones(output.size(), CV_8UC1); for (int r=0; r<obstacles.rows; ++r) { int x_cord = cvRound((r - intercet)/slope); if (x_cord >= 0 && x_cord <= disp_size){ for (int c=0; c<obst

错误代码如下所示

cv::Mat obstacles = cv::Mat::ones(output.size(), CV_8UC1);

for (int r=0; r<obstacles.rows; ++r) {
    int x_cord = cvRound((r - intercet)/slope);
    if (x_cord  >= 0 && x_cord <= disp_size){
        for (int c=0; c<obstacles.cols; ++c) {
                int d = output.at<int>(r,c);
                if ((d/(256/disp_size)) <= x_cord+5){//<= x_cord+5 && d>= x_cord-5){
                obstacles.at<int>(r,c) = 0;  //error is in this line
            }
        }
   }
}
cv::Mat障碍物=cv::Mat::ones(output.size(),cv_8UC1);

对于(int r=0;r=0&&x)跳线您的Mat具有类型
CV_8UC1
,这是一种8位=1字节的数据类型

您尝试以
.at
的身份访问,但int是32位数据类型

请尝试使用无符号字符或其他8位类型,如下所示:

cv::Mat obstacles = cv::Mat::ones(output.size(), CV_8UC1);

for (int r=0; r<obstacles.rows; ++r) {
int x_cord = cvRound((r - intercet)/slope);
if (x_cord  >= 0 && x_cord <= disp_size){
    for (int c=0; c<obstacles.cols; ++c) {
            int d = output.at<uchar>(r,c);
            if ((d/(256/disp_size)) <= x_cord+5){//<= x_cord+5 && d>= x_cord-5){
            obstacles.at<uchar>(r,c) = 0;  //error is in this line
        }
    }
   }
}
cv::Mat障碍物=cv::Mat::ones(output.size(),cv_8UC1);

对于(int r=0;r=0&&x_)跳线,非常感谢您的解释,我很难理解它是如何工作的。谢谢