#include <cv.h>
#include <opencv.hpp>
#include <highgui.h>
using namespace cv;

void mouse_callback(int event,int x, int y, int flags, void* param );

int main()
{
	Mat LeftImg = imread("1L.jpg");
	unsigned char* data = (unsigned char*)LeftImg.data;
	for (int i = 0 ; i < LeftImg.cols ; i++)
	{
		for (int j = 0 ; j < LeftImg.rows ; j++)
		{
			if(	LeftImg.at<Vec3b>(j,i)[0] <= 10 ||
				LeftImg.at<Vec3b>(j,i)[1] <= 10 ||
				LeftImg.at<Vec3b>(j,i)[2] <= 10 )
			{ 
				LeftImg.at<Vec3b>(j,i)[0] = 255;
				LeftImg.at<Vec3b>(j,i)[1] = 255;
				LeftImg.at<Vec3b>(j,i)[2] = 255;
			}
			else
			{
				break;
			}
		}
	}
	imshow("d",LeftImg);
	setMouseCallback("d",mouse_callback, &LeftImg);

	waitKey(0);
}

//Mouse callback function
void mouse_callback(int event,int x, int y, int flags, void* param )
{
	char str[100];
	Mat* temp = (Mat*)param;
	Mat temp2;
	temp->copyTo(temp2);

	if (flags == EVENT_FLAG_LBUTTON) //left button flag
	{

		unsigned char B = temp->at<Vec3b>(y,x)[0];
		unsigned char G = temp->at<Vec3b>(y,x)[1];
		unsigned char R = temp->at<Vec3b>(y,x)[2];

		sprintf_s(str,"( %d, %d ) :%d , %d, %d", x, y, R,G,B);
		putText(temp2,str,Point2f(x,y),FONT_HERSHEY_PLAIN,1,Scalar(255,0,0,255));
		imshow("d",temp2);
	}
}
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기