cv :: Mat中的cv :: Point的OpenCV rgb值 [英] OpenCV rgb value for cv::Point in cv::Mat

查看:1287
本文介绍了cv :: Mat中的cv :: Point的OpenCV rgb值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看过StackOverflow上已经存在的不同问题,但没有一个似乎有帮助。
我想做的是很简单的:我有一个 cv :: Point ,我需要获取像素的RGB值在那一点在 cv :: Mat ,以便我可以将其与存储的RGB值进行比较。



现在这应该很容易,我尝试了1001种不同的方式,只是不为我工作。



有人请帮助我离开我的痛苦!



edit:
两个答案以下工作!
我用C ++做一个新的,不知道通过 cout 输出 unsigned char 一个问号!
printf offcourse给出正确的值!!

解决方案

这真的很容易。但是,OpenCV的文档很好地隐藏了简单的答案。



这里是示例代码:

  cv :: Mat3b image = imread(filename); 
cv :: point point(23,42);
cv :: Vec3b template;
template [0] = 128; template [1] = 12; template [2] = 64;

const cv :: Vec3b& bgr = image(point);
if(bgr [0] == template [0]& bgr [1] == template [1]& bgr [2] == template [2])
std :: cout<< 颜色匹配! << std :: endl;

有可能更好的方式来处理cv :: Vec,但是我忘了。
另请参见 OpenCV作弊表。 / p>

I've looked at different questions already here on StackOverflow, but none seems to helps. What I want to do is quite simple: I have a cv::Point and I need to get the RGB value for the pixel at that point in a cv::Mat so that I can compare it with a stored RGB value.

Now this should be very easy but I've tried 1001 different ways and it just doesnt work for me.

Someone please help me out of my misery!!

edit: both answers below work! I'm kinda new with C++ and didn't know that outputting a unsigned char through cout gives a questionmark! printf offcourse gives the right value!!

解决方案

That's really easy. However the documentation of OpenCV is good at hiding the simple answers.

Here is example code:

cv::Mat3b image = imread(filename);
cv::Point point(23, 42);
cv::Vec3b template;
template[0] = 128; template[1] = 12; template[2] = 64;

const cv::Vec3b& bgr = image(point);
if (bgr[0] == template[0] && bgr[1] == template[1] && bgr[2] == template[2])
   std::cout << "Colors match!" << std::endl;

There are probable better ways of dealing with the cv::Vec, but I forgot. See also the OpenCV Cheat Sheet.

这篇关于cv :: Mat中的cv :: Point的OpenCV rgb值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆