OPENCV Study Notes (7): Usage of cvrectangle and Cv::rectangle

Source: Internet
Author: User
Tags scalar

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.