整整一天我已经尝试了很多东西来获得子图像中的所有相关匹配(使用matchtemplate函数),这是我已经使用mousecallback函数从原始图像中提取的ROI.所以我的代码在下面是匹配功能
////Matching Function
void CTemplate_MatchDlg::OnBnTemplatematch()
{
namedWindow("reference",CV_WINDOW_AUTOSIZE);
while(true)
{
Mat ref = imread("img.jpg"); // Original Image
mod_ref = cvCreateMat(ref.rows,ref.cols,CV_32F);// resizing the image to fit in picture box
resize(ref,mod_ref,Size(),0.5,0.5,CV_INTER_AREA);
Mat tpl =imread("Template.jpg"); // TEMPLATE IMAGE
cvSetMouseCallback("reference",find_mouseHandler,0);
Mat aim=roiImg1.clone(); // SUB_IMAGE FROM ORIGINALIMAGE
// aim variable contains the ROI matrix
// next, want to perform template matching in that ROI // and display results on original image
if(select_flag1 == 1)
{
// imshow("ref",aim);
Mat res(aim.rows-tpl.rows+1, aim.cols-tpl.cols+1,CV_32FC1);
matchTemplate(aim, tpl, res, CV_TM_CCOEFF_NORMED);
threshold(res, res, …Run Code Online (Sandbox Code Playgroud) 这是绘制矩形的功能,为参数提供相应的值
void rectangle(Mat& img, Point pt1, Point pt2,const Scalar& color, int thickness=1,int lineType=8, int shift=0);
Run Code Online (Sandbox Code Playgroud)
用户可以使用此功能通过鼠标设置ROI,在Templte Matching应用程序中在检测到的匹配上绘制矩形.我的问题是,第二和第三个参数是这里的点数.如果用户想要获得第1点和第2点值以进行进一步处理,如何获得?如何打印两个点值?!指向double或int转换?!
任何人,清除我的怀疑.在此先感谢您的帮助!!
更新:
void mouseHandler(int event, int x, int y, int flags, void* param)
{
if (event == CV_EVENT_LBUTTONDOWN && !drag)
{
/* left button clicked. ROI selection begins */
point1 = Point(x,y);
drag = 1;
}
if (event == CV_EVENT_MOUSEMOVE && drag)
{
/* mouse dragged. ROI being selected */
Mat img1 = mod_tempimg.clone();
point2 = Point(x, y);
rectangle(img1, point1, point2, CV_RGB(255, 0, …Run Code Online (Sandbox Code Playgroud)