質問編集履歴
1
指摘されたmy_colorのprint文とログを追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,6 +12,12 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
+
修正
|
16
|
+
|
17
|
+
2018/12/06 指摘されたmy_colorのprint文とログを追記しました。
|
18
|
+
|
19
|
+
|
20
|
+
|
15
21
|
### 該当のソースコード
|
16
22
|
|
17
23
|
|
@@ -30,12 +36,168 @@
|
|
30
36
|
|
31
37
|
img = np.ones((h, w, 3))*255
|
32
38
|
|
39
|
+
|
40
|
+
|
41
|
+
# -----------ご指摘のprint文、を挿入しました-----------
|
42
|
+
|
43
|
+
print('paint_block_on_result_canvas: my_color={}'.format(my_color))
|
44
|
+
|
45
|
+
|
46
|
+
|
33
|
-
cv2.rectangle(img, (150, 25),(300, 50), my_color, -1)
|
47
|
+
cv2.rectangle(img, (150, 25), (300, 50), my_color, -1)
|
34
|
-
|
48
|
+
|
35
|
-
# cv2.rectangle(img, (150, 25), (300, 50), (0, 0, 255), -1) これだとうまくいく
|
49
|
+
# cv2.rectangle(img, (150, 25), (300, 50), (0, 0, 255), -1) # これだとうまくいく
|
36
50
|
|
37
51
|
|
38
52
|
|
39
53
|
cv2.imshow("result_img", img)
|
40
54
|
|
55
|
+
|
56
|
+
|
41
57
|
```
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
### ログ
|
62
|
+
|
63
|
+
ご指摘のmy_colorのprintを追加しました。
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
Connected to pydev debugger (build 183.4284.139)
|
68
|
+
|
69
|
+
mouse_call_back_test: img.shape=(589, 960, 3)
|
70
|
+
|
71
|
+
-------click event start-------
|
72
|
+
|
73
|
+
print_position: (x,y)=(157, 238)
|
74
|
+
|
75
|
+
print_position: gbr:[188 146 101]
|
76
|
+
|
77
|
+
paint_block_on_result_canvas: my_color=(188, 146, 101)
|
78
|
+
|
79
|
+
-------click event end-------
|
80
|
+
|
81
|
+
-------click event start-------
|
82
|
+
|
83
|
+
print_position: (x,y)=(343, 384)
|
84
|
+
|
85
|
+
print_position: gbr:[105 77 47]
|
86
|
+
|
87
|
+
paint_block_on_result_canvas: my_color=(105, 77, 47)
|
88
|
+
|
89
|
+
-------click event end-------
|
90
|
+
|
91
|
+
-------click event start-------
|
92
|
+
|
93
|
+
print_position: (x,y)=(400, 262)
|
94
|
+
|
95
|
+
print_position: gbr:[46 33 19]
|
96
|
+
|
97
|
+
paint_block_on_result_canvas: my_color=(46, 33, 19)
|
98
|
+
|
99
|
+
-------click event end-------
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
### 補足:全ソース
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
```python
|
108
|
+
|
109
|
+
import cv2
|
110
|
+
|
111
|
+
import numpy as np
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
def paint_block_on_result_canvas(img, y, x):
|
118
|
+
|
119
|
+
my_color = (int(img[y][x][0]), int(img[y][x][1]), int(img[y][x][2]))
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
# 認識結果のウインドウ
|
124
|
+
|
125
|
+
h, w, c = img.shape
|
126
|
+
|
127
|
+
img = np.ones((h, w, 3))*255
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
# -----------ご指摘のprint文、を挿入しました-----------
|
132
|
+
|
133
|
+
print('paint_block_on_result_canvas: my_color={}'.format(my_color))
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
cv2.rectangle(img, (150, 25), (300, 50), my_color, -1)
|
138
|
+
|
139
|
+
# cv2.rectangle(img, (150, 25), (300, 50), (0, 0, 255), -1) # これだとうまくいく
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
cv2.imshow("result_img", img)
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
def print_position(event, x, y, flags, img):
|
150
|
+
|
151
|
+
if event == cv2.EVENT_LBUTTONDBLCLK:
|
152
|
+
|
153
|
+
print('-------click event start-------')
|
154
|
+
|
155
|
+
print('print_position: (x,y)=({x}, {y})'.format(x=x, y=y))
|
156
|
+
|
157
|
+
print('print_position: gbr:{gbr_value}'.format(gbr_value=(img[y][x])))
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
paint_block_on_result_canvas(img, y, x)
|
162
|
+
|
163
|
+
print('-------click event end-------')
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
def mouse_call_back_test():
|
170
|
+
|
171
|
+
img = cv2.imread("data/src/Berry.jpg")
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
print('mouse_call_back_test: img.shape={}'.format(img.shape))
|
176
|
+
|
177
|
+
cv2.imshow("img", img)
|
178
|
+
|
179
|
+
cv2.setMouseCallback("img", print_position, img)
|
180
|
+
|
181
|
+
cv2.waitKey(0)
|
182
|
+
|
183
|
+
cv2.destroyAllWindows()
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
def main():
|
190
|
+
|
191
|
+
mouse_call_back_test()
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
if __name__ == '__main__':
|
198
|
+
|
199
|
+
main()
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
```
|