回答編集履歴
2
d
answer
CHANGED
@@ -70,5 +70,5 @@
|
|
70
70
|
rect = max(rects, key=(lambda x: x[2] * x[3]))
|
71
71
|
cv2.rectangle(frame, tuple(rect[0:2]), tuple(rect[0:2] + rect[2:4]), (0, 0, 255), thickness=2)
|
72
72
|
|
73
|
-
cv2.imshow('red', frame)
|
73
|
+
cv2.imshow('red', frame)
|
74
74
|
```
|
1
d
answer
CHANGED
@@ -53,4 +53,22 @@
|
|
53
53
|
出力画像
|
54
54
|
|
55
55
|
※1: `mask[(h > 170)] = 255` の部分は抽出したい色に応じて変更してください。
|
56
|
-
※2: `1000 <= cv2.contourArea(x) <= 5000` の部分は抽出したい面積の範囲に応じて変更してください。
|
56
|
+
※2: `1000 <= cv2.contourArea(x) <= 5000` の部分は抽出したい面積の範囲に応じて変更してください。
|
57
|
+
|
58
|
+
## 動画が流れない問題について
|
59
|
+
|
60
|
+
> 動画が流れるわけでもなく、どのキーを押しても反応しなくなりました。
|
61
|
+
|
62
|
+
cv2.imshow() が while ループの外にあるので、動画は表示されません。
|
63
|
+
ループの中に入れるべきだと思います。
|
64
|
+
|
65
|
+
```python
|
66
|
+
while cv2.waitKey(30) < 0:
|
67
|
+
_, frame = capture.read()
|
68
|
+
rects = find_rect_of_target_color(frame)
|
69
|
+
if len(rects) > 0:
|
70
|
+
rect = max(rects, key=(lambda x: x[2] * x[3]))
|
71
|
+
cv2.rectangle(frame, tuple(rect[0:2]), tuple(rect[0:2] + rect[2:4]), (0, 0, 255), thickness=2)
|
72
|
+
|
73
|
+
cv2.imshow('red', frame)
|
74
|
+
```
|