Draw rectangle in OpenCV

前端 未结 2 1559
花落未央
花落未央 2021-02-04 08:15

I want to draw a rectangle in OpenCV by using this function:

rectangle(Mat& img, Rect rec, const Scalar& color, int thickness=1, int lineType=8, int shif         


        
2条回答
  •  醉酒成梦
    2021-02-04 08:38

    Here's a simple example of drawing a pre-defined rectangle on an image

    using namespace cv;
    
    int main(){
    Mat img=imread("myImage.jpg");
    
    Rect r=Rect(10,20,40,60);
    //create a Rect with top-left vertex at (10,20), of width 40 and height 60 pixels.
    
    rectangle(img,r,Scalar(255,0,0),1,8,0);
    //draw the rect defined by r with line thickness 1 and Blue color
    
    imwrite("myImageWithRect.jpg",img);
    
    
    return 0;
    }
    

提交回复
热议问题