#include
#include
using namespace cv;
using namespace std;
Mat bgImage;
const char* dravdeo_win = "drav shapes and text demo";
void MyLines();
void MyRectangle();
void MyEllipse();
void MyPolyon();
void MyCircle();
void RandomLineDemo();
int main(int argc,char**argv)
{
bgImage = imread("E:/Learning_AI/OpenCV_C++/1.jpg");
if (bgImage.empty())
{
cout << "can't open image" << endl;
}
MyRectangle();
namedWindow("output image", WINDOW_NORMAL);
imshow("output image", bgImage);
waitKey(0);
return 0;
}
void MyLines()
{
Point p1 = Point(20,30);
Point p2;
p2.x = 300;
p2.y = 300;
Scalar color = Scalar(0, 0, 255);
line(bgImage, p1, p2, color, 10, LINE_AA);
}
void MyRectangle()
{
Rect rect = Rect(100, 500, 100, 500);
Scalar color = Scalar(0, 0, 255);
rectangle(bgImage, rect, color, 10, LINE_8);
}
void MyEllipse()
{
Scalar color = Scalar(255, 0, 0);
ellipse(bgImage, Point(bgImage.cols / 2, bgImage.rows / 2), Size(bgImage.cols / 4, bgImage.rows / 8),45, 0, 360, color, 10, LINE_8);
}
void MyCircle()
{
Scalar color = Scalar(0, 0, 255);
Point center = Point(bgImage.cols / 2, bgImage.rows / 2);
circle(bgImage, center, 150, color, 2, 8);
}
void MyPolyon()
{
Point pts[1][5];
pts[0][0] = Point(100, 100);
pts[0][1] = Point(100, 200);
pts[0][2] = Point(200, 200);
pts[0][3] = Point(200, 100);
pts[0][4] = Point(100, 100);
const Point* ppts[] = { pts[0] };
int npt[] = { 5 };
Scalar color = Scalar(255, 12, 255);
fillPoly(bgImage, ppts,npt, 1, color, 8);
}
void RandomLineDemo()
{
Mat bg = Mat::zeros(bgImage.size(), bgImage.type());
RNG rng(12345);
Point pt1;
Point pt2;
namedWindow("random line demo", 1);
for (int i = 0; i < 1000; i++)
{
pt1.x = rng.uniform(0, bgImage.cols);
pt2.x = rng.uniform(0, bgImage.cols);
pt1.y = rng.uniform(0, bgImage.rows);
pt2.y = rng.uniform(0, bgImage.rows);
Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
if(waitKey(50)>0)
{
imwrite("E:/Learning_AI/OpenCV_C++/demo.jpg", bg);
break;
}
line(bg, pt1, pt2, color, 1, 8);
imshow("random line demo", bg);
}
}