opencv cvset2d java,OpenCV cvSet2d .....这是做什么的

本文讨论了在OpenCV中访问和设置像素时出现的一个常见问题,即`cvSet2D()`函数的坐标参数顺序。作者指出,这个函数使用的是行优先的矩阵存储方式,因此参数顺序应为`(行, 列)`,而不是`(列, 行)`。文章还提到了使用指针直接访问图像数据作为替代方案的优势,并提醒读者注意像素值的设置,如`s.val[0]=111`等操作可能意味着设置像素的蓝色分量为111,而非将其设为黑色。
摘要由CSDN通过智能技术生成

I was browsing over some code in the OpenCV page when it came to accessing Pixel Data

IplImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_32F,3);

CvScalar s;

s=cvGet2D(img,i,j); // get the (i,j) pixel value

printf("B=%f, G=%f, R=%f\n",s.val[0],s.val[1],s.val[2]);

s.val[0]=111;

s.val[1]=111;

s.val[2]=111;

cvSet2D(img,i,j,s); // set the (i,j) pixel value

I had done something similar, but I used the Template Class provided to access pixel data......anyways Im not sure I understand the part s.val[0]=111....etc?

if s.val[0] contains the B value, what exactly is s.val[0]=111 doing? is it setting it to black?........I dont understand exactly what it's supposed to be?

Im used to CVscalars and such but I dont understand this format? Specifically what 111 means?

thanks

解决方案

The cvSet2D(img, i, j, s) functions to not access the (i,j)th pixel. It accesses the (j,i)th pixel. That is because images are stored as a matrix - you need to specify the row first (the Y coordinate) and then the column (the X coordinate).

Instead of using the cvGet/Set functions, did you try using pointers to access data within an image?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值