-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdrawing.cpp
More file actions
77 lines (66 loc) · 1.99 KB
/
Copy pathdrawing.cpp
File metadata and controls
77 lines (66 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// Created by Dariya Petrova on 11.05.2020.
//
#include <iostream>
#include "drawing.h"
/*!
* показывает изображение
* @param img - изображение
* @param imgName - имя изображения
*/
void showImg(Mat img, String imgName) {
imshow(imgName, img);
waitKey(0);
}
/*!
* рисует на изображении линии
* @param img - изображение
* @param points - массив точек
* @param color - цвет линии
* @param joinEnds - соединяются ли концы
* @param isShowImg - надо ли показывать изображение
* @param imgName - имя изображения
*/
void drawLines(Mat img, vector<Point> points, Scalar color, bool joinEnds, bool isShowImg,
String imgName) {
int size = points.size();
int end = size;
if (!joinEnds) {
end -= 1;
}
for (int j = 0; j < end; j++) {
line(img, points[j], points[(j + 1) % size], color, 1, LINE_AA);
if (isShowImg) {
showImg(img, imgName);
}
}
}
/*!
* рисует на изображении точки
* @param img - изображение
* @param points - массив точек
* @param color - цвет точек
*/
void drawPoints(Mat img, vector<Point> points, Scalar color) {
int size = points.size();
for (int j = 0; j < size; j++) {
line(img, points[j], points[j], color);
}
}
/*!
* обрезка картинки
*/
void cropImg(String imgPath, String newImgPath, int startX, int startY, int width, int height) {
// String imgPath = "../netBuildingsMarking.png";
// String newImgPath = "../netBuildingsMarking.jpg";
Mat image = imread(imgPath);
Mat ROI(image, Rect(startX, startY, width, height));
Mat croppedImage;
ROI.copyTo(croppedImage);
imwrite(newImgPath, croppedImage);
}
void printPoints(vector<Point> points) {
for (Point point: points) {
cout << point.x << ";" << point.y << endl;
}
}