简体   繁体   English

在OpenCV中在图像中绘制矩形

[英]drawing rectangle in an image in OpenCV

To find out the maximum and minimum pixel value of a gray scale image is 为了找出灰度图像的最大和最小像素值是

     IplImage* src = cvLoadImage(argv[1],0);

     double min_val;
     double max_val;
     CvPoint minLoc;
     CvPoint maxLoc;
     cvMinMaxLoc(dst,&minVal,&maxVal, &minLoc, &maxLoc);
     printf("Min val %f \n",minVal);
     printf("Max Val %f \n",maxVal);
     printf("Min location %d \n",minLoc);
     printf("Max location %d \n",maxLoc);

I am using OpenCV C API. 我正在使用OpenCV C API。 Now I want to draw a rectangle around the maximum pixel location (maxLoc) with cvRectangle(CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1, int lineType=8, int shift=0) but I don't know what will be the parameters of rectangle vertices ie pt1 and pt2. 现在我想用cvRectangle(CvArr* img, CvPoint pt1, CvPoint pt2, CvScalar color, int thickness=1, int lineType=8, int shift=0)在最大像素位置(maxLoc)周围绘制一个矩形不知道矩形顶点(即pt1和pt2)的参数是什么。 Will the other 3 parameters be always 1, 8 and 0. Can anybody help me with the parameters. 其他3个参数是否始终为1、8和0。有人可以帮我提供这些参数吗?

the two corners of your rectangle will be displaced say 1 pixel above and below the location of the max pixel. 矩形的两个角将在最大像素位置的上方和下方移动1个像素。

so cvRectangle(img, minLoc+cvPoint(- 1,- 1), minLoc+cvPoint(1,1), 255, 2) will draw a rectangle 1px araound the point, with the rect having a border thickness of 2px 因此cvRectangle(img, minLoc+cvPoint(- 1,- 1), minLoc+cvPoint(1,1), 255, 2)将在该点周围绘制一个1px的矩形,矩形的边框厚度为2px

Yes, If the other parameters are not specified, they default to their values 1,8,0 是的,如果未指定其他参数,则默认为它们的值1,8,0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM