-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.2.cpp
More file actions
155 lines (127 loc) · 3.22 KB
/
4.2.cpp
File metadata and controls
155 lines (127 loc) · 3.22 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Part4.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//
#include <iostream>
#include <sstream>
#include <cv.h>
#include <highgui.h>
IplImage* temp = new IplImage();
void my_mouse_callback1(int event, int x, int y, int flags, void* param)
{
IplImage* image = (IplImage*)param;
switch (event)
{
case CV_EVENT_LBUTTONDOWN:
{
CvScalar Pixel = cvGet2D(image, x, y);
std::ostringstream strs;
strs << Pixel.val[0] << " " << Pixel.val[1] << " " << Pixel.val[2] << " ";
CvFont font;
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.3, 0.3);
temp = cvCloneImage(image);
cvPutText(temp, strs.str().c_str(), cvPoint(x, y), &font, cvScalarAll(0));
break;
}
default:
{
break;
}
}
}
CvRect box;
bool drawing_box = false;
void draw_box(IplImage* img, CvRect rect) {
cvRectangle(img, cvPoint(box.x, box.y), cvPoint(box.x + box.width, box.y + box.height), cvScalar(0x00, 0x00, 0x00));
}
void my_mouse_callback2(int event, int x, int y, int flags, void* param)
{
IplImage* image = (IplImage*)param;
switch (event)
{
case CV_EVENT_MOUSEMOVE: {
if (drawing_box) {
box.width = x - box.x;
box.height = y - box.y;
}
break;
}
case CV_EVENT_LBUTTONDOWN: {
drawing_box = true;
box = cvRect(x, y, 0, 0);
break;
}
case CV_EVENT_LBUTTONUP: {
drawing_box = false;
if (box.width < 0) {
box.x += box.width;
box.width *= -1;
}
if (box.height < 0) {
box.y += box.height;
box.height *= -1;
}
temp = cvCloneImage(image);
draw_box(temp, box);
break;
}
default: {
break;
}
}
}
bool status_drawing = false;
CvPoint PointA, PointB;
void my_mouse_callback3(int event, int x, int y, int flags, void* param)
{
IplImage* image = (IplImage*)param;
switch (event)
{
case CV_EVENT_LBUTTONDOWN: {
status_drawing = true;
PointA.x = x;
PointA.y = y;
}
case CV_EVENT_LBUTTONUP: {
status_drawing = false;
PointB.x = x;
PointB.y = y;
temp = cvCloneImage(image);
cvLine(temp, PointA, PointB, cvScalarAll(0), 1);
break;
}
case CV_EVENT_RBUTTONDOWN: {
cvCircle(temp, cvPoint(x, y), 5, cvScalarAll(255), 20);
break;
}
default: {
break;
}
}
}
int pos_value = 0;
void position_callback(int position)
{
pos_value = position * 10;
}
int turn = 0;
void turn_callback(int position)
{
turn = position;
}
int main(int argc, char* argv[])
{
////##################################################################################
упражнение 4.2 - текст на изображении
IplImage* Picture = cvLoadImage("../Part3/picture/88.png");
temp = cvCloneImage(Picture);
cvNamedWindow("Pixels");
cvSetMouseCallback("Pixels", my_mouse_callback1, (void*)Picture);
bool work = true;
while (work)
{
cvShowImage("Pixels", temp);
if (27 == cvWaitKey(15)) // нажатие кнопки ecs
work = false;
}
cvDestroyWindow("Pixels");
getchar();
}