使用 Mat::at<Vec3i> Point 未构造正确的像素
Use Mat::at<Vec3i> Point not assing the correct pixel
我通常会找到通常遇到的问题的所有答案,不幸的是,在这种情况下我找不到解决方案。我有以下代码
Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 );
namedWindow( "Contours", CV_WINDOW_AUTOSIZE );
for( int i = 0; i< contours.size(); i++ ){
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
drawContours( drawing, contours_poly, i, color, 1, 8, vector<Vec4i>(), 0, Point() );
rectangle( drawing, boundRect[i].tl(), boundRect[i].br(), color, 2, 8, 0 );
drawing.at<Vec3i>(centroid[i])[0]=color[0];
drawing.at<Vec3i>(centroid[i])[1]=color[1];
drawing.at<Vec3i>(centroid[i])[2]=color[2];
circle(drawing, centroid[i], 5, color, 3,8,0);
cout<<centroid[i]<<endl;
imshow( "Contours", drawing );
waitKey(0);
}
问题是质心并没有放在应有的位置。这些点的高度相同,但宽度不对。我已经用圆图检查了每个轮廓的"质心",这些点都可以。
有人能在这件事上帮我吗
您试图将3*32位分配给一个只有3*8位大小的字段。您将矩阵定义为CV_8UC3
类型,因此应该使用drawing.at<Vec3b>(...)
(其中b
代表无符号字符)。你可以在这里找到各种类型的def。
您可以将CV_xxtCn
读取为
- xx:位数
- t: 类型(F=浮点类型,S=有符号整数,U=无符号整数)
- n: 通道数
相关文章:
- 如何在不产生任何垃圾的情况下获得C中的像素
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 如何在24位SDL_Surface上设置像素的颜色
- 如何从SDL_Surface获取特定像素的颜色
- 如何将CMSampleBufferRef/CIImage/UIImage转换为像素,例如uint8_t[]
- 在C++中查找像素 RGB 数据的最快方法是什么?
- 是否可以从 OpenGL 缓冲区获取原始大小的像素?
- 选择基于另一个垫子的非零像素的cv::Mat的一部分?
- 如何使用 sdl2 快速绘制像素网格?
- 如何在C++中进行像素操作? - Linux
- 他们如何将红外锁定像素转换为镜头前方 1m 的正常平面上的位置
- 访问随机图像像素的快速方法,最多一次
- OpenCV 像素访问点与 at() - 不同的值
- 如何使用 freetype2 访问单色位图中的像素状态
- 尝试渲染像素坐标时,简单线条渲染失败
- 计算另一个图像像素满足条件的像素值的平均值
- 如何返回定义良好的内存部分?例如来自图像数据的像素的颜色值
- 在Qt-cpp中通过像素获取QString的子字符串
- 有效地计算像素到其对应核线的距离
- 如何将像素图像导入cpp