这是绘制矩形并为参数提供相应值的函数
void rectangle(Mat& img, Point pt1, Point pt2,const Scalar& color, int thickness=1,int lineType=8, int shift=0);
用户可以使用此功能用鼠标设置 ROI,在模板匹配应用程序中在检测到的匹配上绘制矩形。我的问题是,第二个和第三个参数是这里的点。如果用户想要获得第 1 点和第 2 点的值以进行进一步处理,如何获得?!如何打印两个点值?!指向双精度或整数转换?!
任何人,清除我的疑虑。提前感谢您的帮助!
更新:
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, 0), 1, 8, 0);
imshow("image", img1);
}
if (event == CV_EVENT_LBUTTONUP && drag)
{
Mat img2=mod_tempimg.clone();
point2 = Point(x, y);
rect = Rect(point1.x,point1.y,x-point1.x,y-point1.y);
drag = 0;
roiImg = mod_tempimg(rect1);
imshow("image", img2);
}
if (event == CV_EVENT_LBUTTONUP)
{
/* ROI selected */
select_flag = 1;
drag = 0;
}
在上面的代码中,如何从这一行检索点值?!
rect = Rect(point1.x,point1.y,x-point1.x,y-point1.y);
如果我知道有助于找到 rect 角度的值。