您好,我有以下代码:
void ViewPlane::colourPixel(const int u, const int v, const Colour c){
int step = img->widthStep;
cout << "U: " << u << ", V: " << v << ", step: " << step << "\n";
cout << "Colour: " << c.r << ", " << c.g << ", " << c.b << "\n";
cout << "Data: " << v*step+u*3 << ", " << v*step+u*3+1 << ", " << v*step+u*3+2 << "\n";
cout << "Data: " << data[v*step+u*3] << ", " << data[v*step+u*3+1] << ", " << data[v*step+u*3+2] << "\n";
//swap colours round as opencv default image is bgr, not rgb
data[v*step+u*3] = c.b;
cout << "done it\n";
data[v*step+u*3+1] = c.g;
cout << "done it\n";
data[v*step+u*3+2] = c.r;
cout <<"done it\n";
}
img是一个IplImage指针,数据是
data = (uchar *)img->imageData;
我循环遍历u和v(图像坐标)的大量值并为每个像素指定颜色。但是当代码达到u = 148时,代码只会在此像素中途停止。
打印出来的值显示此时绿色像素最初包含'*',并且是唯一一个到此为止的点。这是输出的副本:
....
U: 146, V: 0, step: -1219934912
Colour: 0, 0, 0
Data: 438, 439, 440
Data:
done it
done it
done it
U: 147, V: 0, step: -1219934912
Colour: 0, 0, 0
Data: 441, 442, 443
Data:
done it
done it
done it
U: 148, V: 0, step: -1219934912
Colour: 0, 0, 0
Data: 444, 445, 446
Data: �, *, �
done it
所以我的问题是,这颗星是什么意思?为什么阻止我在那里分配数据?
编辑:图像大小为400x400px
PS:我刚尝试评论绿色通道分配,此错误再次发生在红色通道上。这次它在作业之前保留了'@',所以这让我觉得它与出了什么问题无关......在这种情况下,到底是什么?我不是数组的界限,我插入的值是一个整数0 ...
答案 0 :(得分:0)
您的程序输出显示步骤为“-1219934912”。它使你看起来像一个迷路img
指针。相当奇怪的是,图像中的每一行都需要〜1GB