双重空闲或内存分配错误 我是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_)跳线,非常感谢您的解释,我很难理解它是如何工作的。谢谢