基于opencv3.3获取图片某点处RGB及HSV值完整工程

参考文献:http://blog.csdn.net/jiamuju84/article/details/52893239?locationNum=8&fps=1

完整工程:

点此下载

放代码:

#include
#include 
#include "iostream"
using namespace std;
using namespace cv;
void on_mouse(int EVENT, int x, int y, int flags, void* userdata);
int main(int argc, char** argv)
{

	Mat src, hsv;
	//此处更改图片地址
	src = imread("D:\\PLATE\\1.bmp");
	namedWindow("【display】");
	setMouseCallback("【display】", on_mouse, &src);
	while (1)
	{
		imshow("【display】", src);
		waitKey(40);
	}
}
void on_mouse(int EVENT, int x, int y, int flags, void* userdata)
{
	Mat rgb,hsv;
	rgb = *(Mat*)userdata;
	Mat temp;
	cvtColor(*(Mat*)userdata, hsv, CV_RGB2HSV);
	Point p(x, y);
	switch (EVENT)
	{
	case EVENT_LBUTTONDOWN:
	{
		
			printf("b=%d\t", rgb.at(p)[0]);
			printf("g=%d\t", rgb.at(p)[1]);
			printf("r=%d\n", rgb.at(p)[2]);
			
			printf("H=%d\t", hsv.at(p)[0]);
			printf("S=%d\t", hsv.at(p)[1]);
			printf("V=%d\n", hsv.at(p)[2]);
			circle(rgb, p, 2, Scalar(255), 3);
	}
	break;

	}
} 


你可能感兴趣的:(图像处理,C++)