-
Notifications
You must be signed in to change notification settings - Fork 1
/
draw.cpp
106 lines (93 loc) · 1.98 KB
/
draw.cpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "draw.h"
Draw::Draw(DisplayImageLabel* dl, Image* img, cv::Scalar* _color, Shapes _shape = Shapes::Square) :
Mouse(dl, img), shape(_shape), color(_color)
{
}
/**
* @brief Draw::leftClick
*
* set startPoint with x, y coords.
* @param x mouse's coord
* @param y mouse's coord
*/
void Draw::leftClick(int x, int y)
{
startPoint = cv::Point(x, y);
}
/**
* @brief Draw::leftMove
*
* Draw temp shape from startPoint to x, y (params).
* @param x mouse's coord
* @param y mouse's coord
*/
void Draw::leftMove(int x, int y)
{
cv::Point p(x, y);
// Clone image to display temp shape
Image temp = *image;
temp.cloneImg(image->getImg());
cv::Mat tempMat = temp.getImg();
switch (shape)
{
case Shapes::Square:
drawRectangle(tempMat, p);
break;
case Shapes::Circle:
default:
drawCircle(tempMat, p);
break;
}
temp.display();
}
/**
* @brief Draw::leftRelease
*
* Draw final shape to displayed image.
* @param x mouse's coord
* @param y mouse's coord
*/
void Draw::leftRelease(int x, int y)
{
cv::Point p(x, y);
cv::Mat img = image->getImg();
switch (shape)
{
case Shapes::Square:
drawRectangle(img, p);
break;
case Shapes::Circle:
default:
drawCircle(img, p);
break;
}
image->display();
}
/**
* @brief Draw::drawRectangle
*
* Draw rectangle with specific color and size.
* @param img
* @param p Point(x, y)
*/
void Draw::drawRectangle(cv::Mat img, cv::Point p)
{
cv::rectangle(img, startPoint, p, *color, -1);
}
/**
* @brief Draw::drawCircle
*
* Draw circle with specific color and radius.
* @param img
* @param p Point(x, y)
*/
void Draw::drawCircle(cv::Mat img, cv::Point p)
{
int deltaX = p.x - startPoint.x;
int deltaY = p.y - startPoint.y;
int radius = sqrt((deltaX * deltaX) + (deltaY * deltaY));
cv::circle(img, startPoint, radius, *color, -1);
}
//void Draw::drawEllipse(cv::Mat img, cv::Point p)
//{
//}