The first time you use Cvrectangle to draw a rectangle, you encounter a problem:Error: There is no appropriate conversion function from "Cv::mat" to "cvarr*" , we have checked the data, and summarized the following.
Comparison of Cvrentangle and Cv::rectangle function prototypes:
C: void cvrectangle( cvarr*img, Cvpointpt1, Cvpoint pt2, CvscalarColor, intthickness=1, intLine_type=8, intShift=0)
-
C + +:   void rectangle ( mat&
img , point
pt1 , point
pt2 , const scalar&
color , int
thickness =1, int
linetype =8, int
shift =0 )
-
-
C + +: void rectangle(mat&
img, Rect
rec, const scalar&
color, int
thickness=1, int
linetype=8, int
shift=0 )
Parameter description:
Img
image.
Pt1
a vertex of the rectangle.
Pt2
another vertex on the diagonal of the rectangle
Color
Line Color (RGB) or luminance (grayscale image) (grayscale images).
Thickness
The thickness of the
line that makes up the rectangle. A negative value (such as the cv_filled) function draws a color-filled rectangle.
Line_type
the type of the line. See Cvline's description
Shift
the number of decimal places for the coordinate point.
Code:
#include <iostream> #include <opencv2\highgui\highgui.hpp>using namespace std;using namespace Cv;int main ( {Char *imagesrc = "I:\\opencv learning\\picture\\sumpalace.jpg"; Mat matimage = Imread (imagesrc,-1); Iplimage *iplimage = Cvloadimage (imagesrc,-1); if (matimage.data==0| | Iplimage->imagedata ==0) {cout<< "picture loading Failed" <<endl;return-1;} Cv::rectangle (Matimage,cvpoint (20,200), Cvpoint (200,300), Scalar (255,0,0), 1,1,0),//rect (int a,int b,int c,int d) A, b is the upper-left coordinate of the rectangle, c,d the length and width of the rectangle Cv::rectangle (Matimage,rect (100,300,20,200), Scalar (0,0,255), 1,1,0), Cvrectangle (Iplimage, Cvpoint (20,200), Cvpoint (200,300), Scalar (0,255,255), 1,1,0), Imshow ("Matimage", Matimage), Cvshowimage ("Iplimage", Iplimage); Waitkey (); return 0;}
Results:
If you need to draw a rectangle on a chart of the mat type, select Cv::trctangle ()
Draw a rectangle on a diagram of type iplimage*, select Cvrectangle ()
OPENCV Study Notes (7): Usage of cvrectangle and Cv::rectangle