1.绘制形状和文字
代码演示:
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
Mat bgImage;
const char* dravdemo_vin = "draw shapes and text demo";
void MyLines();
void MyRectangle();
void MyEllipse();
void MyCircle();
void MyPolygon();
int main(int argc, char** argv)
{
bgImage = imread("C:/ERRT/c16d7c94363dc0f6e95e46187605e803.jpg");
if (!bgImage.data)
{
printf("could not load image...\n");
return -1;
}
MyLines();
MyRectangle();
MyEllipse();
MyCircle();
MyPolygon();
putText(bgImage, "Hello CAT", Point(bgImage.cols / 2, bgImage.rows / 2), FONT_HERSHEY_COMPLEX, 2.0, Scalar(177, 178, 23), 3, LINE_AA);
namedWindow(dravdemo_vin, WINDOW_FREERATIO);
imshow(dravdemo_vin, bgImage);
waitKey(0);
return 0;
}
void MyLines()
{
Point p1 = Point(20,30);
Point p2;
p2.x = 700;
p2.y = 700;
Scalar color = Scalar(0, 0, 255);
line(bgImage, p1, p2, color, 1, LINE_AA);
}
void MyRectangle()
{
Rect rect = Rect(700, 100, 700, 700);
Scalar color = Scalar(255, 0, 0);
rectangle(bgImage, rect, color, 2, LINE_8);
}
void MyEllipse()
{
Scalar color = Scalar(0, 255, 0);
ellipse(bgImage, Point(bgImage.cols / 2, bgImage.rows / 2), Size(bgImage.cols / 4, bgImage.rows / 8), 45, 0, 360, color, 2, LINE_8);
}
void MyCircle()
{
Scalar color = Scalar(0, 255, 255);
Point center = Point(bgImage.cols / 2, bgImage.rows / 2);
circle(bgImage, center, 500, color, 2, 8);
}
void MyPolygon()
{
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);
}
效果图:
2.模糊图像1
代码演示:
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
int main(int argc, char** argv)
{
Mat src, dst;
src = imread("C:/ERRT/c16d7c94363dc0f6e95e46187605e803.jpg");
if (!src.data)
{
printf("could not load image...\n");
return -1;
}
char input_title[] = "input image";
char output_title[] = "blur image";
namedWindow(input_title, WINDOW_FREERATIO);
namedWindow(output_title, WINDOW_FREERATIO);
imshow(input_title, src);
blur(src, dst, Size(25, 25), Point(-1, -1));
imshow(output_title, dst);
Mat gblur;
GaussianBlur(src, gblur, Size(25, 25), 11, 11);
namedWindow("gaussianblur", WINDOW_FREERATIO);
imshow("gaussianblur", gblur);
waitKey(0);
return 0;
}
?效果图:
3.模糊图像2
代码演示:
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
int main(int argc, char** argv)
{
Mat src, dst;
src = imread("C:/ERRT/c16d7c94363dc0f6e95e46187605e803.jpg");
if (!src.data)
{
printf("could not load image...\n");
return -1;
}
namedWindow("input image", WINDOW_FREERATIO);
imshow("input image", src);
//medianBlur(src, dst, 3);
bilateralFilter(src, dst, 15, 150, 3);
namedWindow("median Filter Result", WINDOW_FREERATIO);
imshow("median Filter Result", dst);
waitKey(0);
return 0;
}
效果图:
?
?
|