Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )
Article Directory
color problem: Graphic color will be affected by the number of image channels. As the image is grayscale, color graphics then fail , it will only show a gray line on the picture.
First, line line
prototype
void line(
InputOutputArray img,
Point pt1,
Point pt2,
const Scalar &color,
int thickness=1,
int lineType=LINE_8,
int shift=0
)
parameter
- img : image
- PT1 : starting point
- PT2 : end
- color:Scalar(b,g,r)
- thickness: the thickness of the thickness of the line. -1 can not be wrong.
- lineType: line types. See LineTypes.
- shift: shift, scale point coordinates.
Example: From a drawing (100,200) to (250,100) Blue Line
#include<opencv2/opencv.hpp>
using namespace cv;
int main()
{
Mat dstImage=Mat::zeros(300,400,CV_8UC3);
line(dstImage,Point(100,200),Point(250,100),Scalar(255,102,0));
imshow("dstImage",dstImage);
waitKey();
return 0;
}
Second, the rectangle rect
prototype
void rectangle(
InputOutputArray img,
Point pt1,
Point pt2,
const Scalar &color,
int thickness=1,
int lineType=LINE_8,
int shift=0
)
parameter
- img : image
- PT1 : on the corner
- PT2 : another pair of corner
- color:Scalar(b,g,r)
- thickness: the thickness of the thickness of the line. When to -1 drawn solid.
- lineType: line types. See LineTypes.
- shift: shift, scale point coordinates.
Example: two pairs of draw a hollow rectangle corner points (100,200) (250,100) of
#include<opencv2/opencv.hpp>
using namespace cv;
int main()
{
Mat dstImage=Mat::zeros(300,400,CV_8UC3);
rectangle(dstImage,Point(100,200),Point(250,100),Scalar(255,102,0));
imshow("dstImage",dstImage);
waitKey();
return 0;
}
Draw a filled rectangle corner points of two pairs (100,200) (250,100): Example
#include<opencv2/opencv.hpp>
using namespace cv;
int main()
{
Mat dstImage=Mat::zeros(300,400,CV_8UC3);
rectangle(dstImage,Point(100,200),Point(250,100),Scalar(255,102,0),-1);
imshow("dstImage",dstImage);
waitKey();
return 0;
}