OPENCV Basic Drawing functions

Source: Internet
Author: User
Tags scalar

OpenCV commonly used data structures and functions

Color space conversion function Cvtcolor function

The Cvtcolor function is a color space conversion function in OPENCV.
It can convert RGB to HSV HSI and other color space, and can be converted to grayscale image.

Prototype: void Cvtcolor (Inputarray src,outarray dst,int code,int dstcn =0);
SRC: Input image
DST: Output image
Code: Color Conversion Space Indicator
DSTCN: The number of channels of the target image if this parameter is 0 is the number of channels of the target image

Cvtcolor function identifiers
Rgb-> BGR Cv_bgr2bgra, CV_RGB2BGRA,CV_BGRA2RGBA,CV_BGR2BGRA,CV_BGRA2BGR
Rgb->gray Cv_rgb2gray,cv_gray2rgb,cv_rgba2gray,cv_gray2rgba
RGB->HSV Cv_rgb2hsv,cv_bgr2hsv,cv_hsv2bgr,cv_hsv2bgr,cv_hsv2rgb
Rgb->hls CV_RGB2HLS,CV_BGR2HLS,CV_HLS2RGB,CV_HLS2BGR

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace CV;
int main ()
{
Mat srcimage = Imread ("Jpg/1.jpeg");
Mat Dstimage;
Cvtcolor (SRCIMAGE,DSTIMAGE,CV_RGB2BGR);
Imshow ("src", srcimage);
Imshow ("DST", dstimage);
Waitkey ();
return 0;
}


Graph drawing function
The use of the ellipse function
Function prototypes: void Ellipse (mat&img, point Center, Size axes, double angle, double startangle, double endangle, const SCALAR& ; color, int thickness=1, int linetype=8, int shift=0)

IMG: Canvas Container
Center: Oval Centre
Axes: The size is in the rectangle
Angle: The angle of rotation of the ellipse
StartAngle: Start Radian
Endangle: End Radian
Color: Graphic Colors
Thickness: line width
Linetype: Linetype
Shift: The precision of the center coordinate points and the axes

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace CV;
#define WINDOW_WIDTH 600
void DrawEllipse (Mat img,double angle)
{
int thickness = 2;
int linetype = 8;
Ellipse
Img
Point (WINDOW_WIDTH/2,WINDOW_WIDTH/2),
Size (WINDOW_WIDTH/4,WINDOW_WIDTH/16),
Angle
0,
360,
Scalar (255,129,0),
Thickness
Linetype
);

}
int main ()
{
Mat img (1000,600,cv_8uc3,scalar::all (0));
DrawEllipse (img,30);
Imshow ("Ellipse", IMG);
Waitkey ();
return 0;
}


Use of the Circle function

function prototype void Circle (mat& img, point Center, int radius, const scalar& color, Intthickness=1, int linetype=8, int shif t=0)
IMG: The image that will be drawn round;
Center: Center;
Radius: radius;
Color: The colour of the circle;
Thickness: If the value is positive, the thickness of the outer contour of the circle, if the value is negative, indicates to draw a fill circle;
Linetype: line type;
Shift

void Drawcircle (Mat img)
{
int thickness =-1;
int linetype = 8;

Circle
Img
Point (100,300),
60,
Scalar (0,89,255),
Thickness
Linetype

);
}

The use of the line function
Function prototype line (mat& img, point pt1, point pt2, const scalar& color, int thickness=1, int linetype=8, int shift=0)
IMG: Output image
PT1: Start point
PT2: End point
Color: Line Colors
Thickness: Line Thickness
Linetype: Linetype
Shift


void DrawLine (Mat img)
{
int thickness = 1;
int linetype = 8;

Line
Img
Point (100,200),
Point (500,600),
Scalar (255,23,56),
Thickness
Linetype
);
}

OPENCV Basic Drawing functions

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.