我正试图从Mat对象中获取一个像素.为了测试我尝试在正方形上绘制一条对角线,并期望从左上角到右下顶点获得完美的线交叉.
for (int i =0; i<500; i++){
//I just hard-coded the width (or height) to make the problem more obvious
(image2.at<int>(i, i)) = 0xffffff;
//Draw a white dot at pixels that have equal x and y position.
}
Run Code Online (Sandbox Code Playgroud)
然而,结果并不像预期的那样.这是在彩色图片上绘制的对角线.
这是灰度图片.
有谁看到了这个问题?
小智 6
问题是你试图以int(每像素32位图像)访问每个像素,而你的图像是3通道无符号字符(每像素24位图像)或1通道无符号字符(每像素8位)图像)为灰度级.您可以尝试像灰度图像那样访问每个像素
for (int i =0; i<image2.width; i++){
image2.at<unsigned char>(i, i) = 255;
}
Run Code Online (Sandbox Code Playgroud)
或者像这样的颜色
for (int i =0; i<image2.width; i++){
image2.at<Vec3b>(i, i)[0] = 255;
image2.at<Vec3b>(i, i)[1] = 255;
image2.at<Vec3b>(i, i)[2] = 255;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
152 次 |
最近记录: |