当前位置:网站首页>Opencv learning (4) color conversion processing image rendering random number
Opencv learning (4) color conversion processing image rendering random number
2022-07-20 09:25:00 【@[email protected]】
Catalog
1. Color conversion cvtcolor De background
1. Color conversion cvtcolor De background
//hsv Space by hs control , If the background color is single , You should use hsv To control the
Mat hsv;
cvtColor(image, hsv, COLOR_BGR2HSV);
Mat mask;
// Intercept the area of a specific pixel value
inRange(hsv, Scalar(35, 43, 46), Scalar(77, 255, 255), mask);
Mat redback = Mat::zeros(image.size(), image.type());
redback = Scalar(40, 40, 200);
// Yes mask Take the opposite
bitwise_not(mask, mask);
imshow("mask", mask);
// Copy only mask by 1 Region
image.copyTo(redback, mask);
imshow("roi Region extraction ", redback);
2. Image rendering
// rectangular
Rect rect;
// Initial coordinates
rect.x = 100;
rect.y = 100;
// Rectangle size
rect.width = 250;
rect.height = 300;
Mat bg = Mat::zeros(image.size(), image.type());
// Draw a rectangle The fourth parameter is less than 0 That is, the filling is greater than 0 It's linewidth 8 Is Linetype ( Default ·)
rectangle(bg, rect, Scalar(0, 0, 255), -1, 8, 0);
// Draw the circle center of a circle Point(350, 400) radius :15 Color control :Scalar(255, 0, 0)b g r
circle(bg, Point(350, 400), 15, Scalar(255, 0, 0), -1, 8, 0);
// Draw the line
line(bg, Point(100, 100), Point(350, 400), Scalar(0, 255, 0), 4, LINE_AA, 0);
// Rotate rectangle (RotatedRect)
RotatedRect rrt;
rrt.center = Point(200, 200);
rrt.size = Size(100, 200);
rrt.angle = 90.0;
// The ellipse
ellipse(bg, rrt, Scalar(0, 255, 255), 2, 8);
Mat dst;
// Image addition
beta, double gamma, CvArr* dst );
/*
Parameters 1:src1, The first original array .
Parameters 2:alpha, The weight of the first array element
Parameters 3:src2 The second original array
Parameters 4:beta, The weight of the second array element
Parameters 5:gamma, chart 1 And graph 2 The value added after and . Don't be too big , Otherwise the picture will be white . The sum is equal to 255 The above is pure white .
Parameters 6:dst, Output pictures
*/
addWeighted(image, 0.7, bg, 0.3, 0, dst);
imshow(" Draw a demo ", bg);
3. random number
Mat canvas = Mat::zeros(Size(512, 512), CV_8UC3);
int w = canvas.cols;
int h = canvas.rows;
// Random seeds
RNG rng(12345);
while (true) {
int c = waitKey(10);
if (c == 27) { // sign out
break;
}
// produce 0-w The data of
int x1 = rng.uniform(0, w);
int y1 = rng.uniform(0, h);
int x2 = rng.uniform(0, w);
int y2 = rng.uniform(0, h);
int b = rng.uniform(0, 255);
int g = rng.uniform(0, 255);
int r = rng.uniform(0, 255);
// canvas = Scalar(0, 0, 0);
line(canvas, Point(x1, y1), Point(x2, y2), Scalar(b, g, r), 1, LINE_AA, 0);
imshow(" Random drawing demonstration ", canvas);
}
4. Polygon drawing
// Definition point , Stored in an array , Store this array in another array to become a two-dimensional array , Drawing
// canvas
Mat canvas = Mat::zeros(Size(512, 512), CV_8UC3);
int w = canvas.cols;
int h = canvas.rows;
Point p1(100, 100);
Point p2(300, 150);
Point p3(300, 350);
Point p4(250, 450);
Point p5(50, 450);
std::vector<Point> pts;
pts.push_back(p1);
pts.push_back(p2);
pts.push_back(p3);
pts.push_back(p3);
pts.push_back(p4);
pts.push_back(p5);
//-1 Cannot be filled
// polylines(canvas, pts, true, Scalar(0, 255, 0), -1, 8, 0); // Draw polygon
//
std::vector<std::vector<Point>> contours;
contours.push_back(pts);
// You can draw multiple polygons Draw fill -1
drawContours(canvas, contours, 0, Scalar(0, 0, 255), -1, 8);
imshow(" Draw polygon ", canvas);
版权声明
本文为[@[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/201/202207190511487074.html
边栏推荐
- Want to try Web3 work? It's enough to read this article
- Detailed explanation of yolov3
- 【论文导读】DAG-GNN: DAG Structure Learning with GNN
- Mindspore依赖库找不到
- Detailed explanation of yolov1
- Use of homebrew
- uni-app. Develop wechat applet to realize message subscription
- [deep learning] - model comparison of emotional analysis of IMDB data set (4) - cnn-lstm integrated model
- 语义分割介绍和FCN
- 深度学习在组织切片上的应用
猜你喜欢
【論文導讀】DAG-GNN: DAG Structure Learning with GNN
mysql45讲阅读笔记深入浅出索引下(五)
Common evaluation functions for causal models: SHD and FDR
Google Chrome browser shortcut key description
【mindspore】【import erro】 undefined symbol _Z14DlogErrorInneriPK
Power learning (1) - power system test
Jwt+rsa stateless SSO principle
uni-app. Develop wechat applet to realize message subscription
LSTM stock price forecast pytorch
yolov2
随机推荐
JS object addition_ JS object array attribute the same values are merged and added
Crack detection of pytoch migration learning Version (resnet50)
单片机2——数码管动态显示的简单原理
yolov3
Redis and MySQL double write consistency analysis
Redis详解(1)前言
【深度学习】-Imdb数据集情感分析之模型对比(1)-RNN
Handwriting verification framework
Create and manage databases using SQL statements
Redis data type and underlying data structure
CPU architecture compatible
yolov1
[deep learning] - model comparison of emotional analysis of IMDB data set (4) - cnn-lstm integrated model
mysql45讲阅读笔记全局锁和表锁(六)
Application of hash bucket
深度学习中的注意力机制
【论文导读】Continuity Scaling: A Rigorous Framework for Detecting andQuantifying Causality Accurately
Analog image encryption and decryption
mindspore官网教程中冻结网络参数怎么理解,能否解释下?
Transaction processing (combined with distributed transactions)