OpenCV the rectangle function with Windows GDI Rectangle function description

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/qiuchangyong/article/details/89150204

rectangle drawing function is a rectangular frame, which has two forms, one is the input x and y coordinates of the upper left and lower right corner point, i.e. Point, the other input is a Rect. They are as follows:

CV_EXPORTS_W void rectangle(CV_IN_OUT Mat& img, Point pt1, Point pt2,
                          const Scalar& color, int thickness=1,
                          int lineType=8, int shift=0);

CV_EXPORTS void rectangle(CV_IN_OUT Mat& img, Rect rec,
                          const Scalar& color, int thickness=1,
                          int lineType=8, int shift=0);

The first form of a rectangular frame comprising a drawn position of the lower right corner, is contained in a relationship of true. For example, if the upper left corner is (0,0), the lower right corner is (1,1), is drawn out of the two pixel width and height of a rectangular two pixel regions.

The second form of realization is invoked in the first form. Rect's br () returns the upper-left corner coordinates plus the width and height of the offset, when calling the first form, minus 1, so that a rectangular area drawn exactly equal to the width and height of the Rect of the product.

It is to be understood pt2 coordinates and a second form of the first form of the rec br () returns the coordinates of the points are different.

In the drawn rectangle using Windows API function Rectangle behavior is different, it passed left, top, right, bottom four coordinates, is drawn out of the area does not include the right and below, and above this second form somewhat similar. Pro-test found that for the right-left coordinate of the coordinate is less than, is less than the coordinate of the coordinates will be exchanged, and draw out a region that does not contain the coordinates corresponding to the lower right side.

Furthermore, OpenCV draw the line function under Windows and line drawing function LineTo segment has a similar distinction, that is, the line drawn under Windows that does not include the end of that point, and OpenCV are included.

Comments: a call to achieve what others, like the face of a black box, you never know what it is inside. Even with the source code, to follow up to see what happens, but also time-consuming. Black Box or less touch, no source of things, encounter problems, they may fall into a dead end, no end of trouble. If you must use, but also to choose a good reputation. Some open source projects, code, large, complex frame structure, can not control, should think twice before using.

 

Guess you like

Origin blog.csdn.net/qiuchangyong/article/details/89150204