opencv找出圖像最亮點並畫圓

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

void DrawFilledCircle(Mat img, Point center,int _radius)
{
	int thickness = -1;
	int lineType = 8;
	circle(img,
		center,
		_radius,
		Scalar(0, 0, 255),
		5,
		lineType);
}




int main()
{
	Mat img=imread("D:/Desktop/波長4100.bmp");

	if (img.empty())
	{
		std::cout<<"Could not load image file!";
		system("pause");
		return 0;
	}
	else
	{
		//unsigned char M = 0;
		int N=0;
		int row, col;
		int height, width, step, channels;
		int i, j;

		height = img.rows;
		width = img.cols;
		step = img.step;
		channels = img.dims;
		std::cout << "Processing a " << height << "*" << width << "image with" << channels << "channels and" << step << "steps" << endl;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		////////////////////////////////////////////////////////////////提取最大灰度值像素的座標////////////////////////////////////////////////////////////////
		for (i = 0; i<height; i++)
			for (j = 0; j<width; j++)
				if (img.data[i*step + j]>N)
				{
					N = img.data[i*step + j];
					row = j; col = i;
				}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////對圖像進行二值化////////////////////////////////////////////////////////////

		std::cout << "the centure is" <<row<<"*"<<col<<endl;
	    std::cout << "pixel value is" << N <<endl; 
		
		DrawFilledCircle(img, Point(row,col),100);

		namedWindow("畫圓", CV_WINDOW_NORMAL); //創建窗口,後面的參數表示可以調整窗口的大小
		imshow("畫圓", img);
	}
	cvWaitKey();
	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章