質問編集履歴
2
個人の情報が特定できる可能性があったため
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,94 +1,8 @@
|
|
1
|
-
情報系の学生です。pythonやopenCVはほとんど触ったことがありません。今度行われる他の学校とともにgopigoを使った開発を行うのでその予習内容に関して質問があります。実行環境は学校にしかなく今は動作確認ができません。
|
2
|
-
|
3
1
|
カメラで撮っている映像の手の輪郭?(肌の輪郭?)を検出するメソッドがあります。今のままだと肌の面積が小さいところや中くらいのところなど輪郭として囲まれる部分が複数個出てきます。問題では面積が大きい一か所だけを囲んで下さいと書いてあります。そこで自分で調べた結果,extract_contoursメソッドのreturn contoursの三つ上の行のcontoursに入るものがnumpyの配列であることがわかりました。なのでreturn numpy.amax(numpy.contours())のようにすればいいのではないかと思っているのですがどうでしょうか?
|
4
2
|
|
5
3
|
|
6
4
|
|
7
5
|
```python
|
8
|
-
|
9
|
-
import cv2
|
10
|
-
|
11
|
-
import picamera
|
12
|
-
|
13
|
-
import picamera.array
|
14
|
-
|
15
|
-
import time
|
16
|
-
|
17
|
-
import numpy
|
18
|
-
|
19
|
-
#from fractions import Fraction
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
class gopigo_control:
|
24
|
-
|
25
|
-
# Init various camera parameter.
|
26
|
-
|
27
|
-
# Finally, every parameter should be fixed to reasonable values.
|
28
|
-
|
29
|
-
def __init__(self):
|
30
|
-
|
31
|
-
self.width = 640
|
32
|
-
|
33
|
-
self.height = 480
|
34
|
-
|
35
|
-
self.camera = picamera.PiCamera(resolution=(self.width,self.height),framerate=10)
|
36
|
-
|
37
|
-
self.camera.iso = 100
|
38
|
-
|
39
|
-
# Wait for the automatic gain control to settle
|
40
|
-
|
41
|
-
time.sleep(2)
|
42
|
-
|
43
|
-
# Fix the values
|
44
|
-
|
45
|
-
self.camera.shutter_speed = self.camera.exposure_speed
|
46
|
-
|
47
|
-
self.camera.exposure_mode = 'off'
|
48
|
-
|
49
|
-
g = self.camera.awb_gains
|
50
|
-
|
51
|
-
self.camera.awb_mode = 'off'
|
52
|
-
|
53
|
-
self.camera.awb_gains = g
|
54
|
-
|
55
|
-
print("shutter:"+str(self.camera.shutter_speed)+" awb_gains:"+str(g))
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
# capture a frame from picamera
|
60
|
-
|
61
|
-
def capture_frame(self):
|
62
|
-
|
63
|
-
cap_stream = picamera.array.PiRGBArray(self.camera,size=(self.width,self.height))
|
64
|
-
|
65
|
-
self.camera.capture(cap_stream, format='bgr',use_video_port=True)
|
66
|
-
|
67
|
-
frame = cap_stream.array
|
68
|
-
|
69
|
-
return frame
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
class cv_control:
|
74
|
-
|
75
|
-
def __init__(self):
|
76
|
-
|
77
|
-
self.lower = []
|
78
|
-
|
79
|
-
self.upper = []
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
# set lower and upper filter.
|
84
|
-
|
85
|
-
def set_filter(self,base_hvalue):
|
86
|
-
|
87
|
-
self.lower = numpy.array([base_hvalue-5, 80, 50], dtype = "uint8")
|
88
|
-
|
89
|
-
self.upper = numpy.array([base_hvalue+5, 255, 230], dtype = "uint8")
|
90
|
-
|
91
|
-
|
92
6
|
|
93
7
|
# returns contours array
|
94
8
|
|
@@ -132,50 +46,4 @@
|
|
132
46
|
|
133
47
|
|
134
48
|
|
135
|
-
# show each contour center position, width, height, and area
|
136
|
-
|
137
|
-
def detect_contour_position(self,contours,frame):
|
138
|
-
|
139
|
-
for cont in contours:
|
140
|
-
|
141
|
-
x,y,w,h = cv2.boundingRect(cont) # encloses contour in a rectangle.
|
142
|
-
|
143
|
-
cx = x + w/2
|
144
|
-
|
145
|
-
cy = y + h/2
|
146
|
-
|
147
|
-
area = cv2.contourArea(cont) # calculate contour area
|
148
|
-
|
149
|
-
print("(cx,cy,wide,height,area)=(" + str(cx) + "," + str(cy) + "," + str(w) + "," + str(h) + "," + str(area) + ")")
|
150
|
-
|
151
|
-
cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),5)
|
152
|
-
|
153
|
-
cv2.imshow("OpenCV Sample05 rect-contours",frame)
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
if __name__ == '__main__':
|
158
|
-
|
159
|
-
gpgc = gopigo_control()
|
160
|
-
|
161
|
-
cvc = cv_control()
|
162
|
-
|
163
|
-
cvc.set_filter(10)
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
while True:
|
168
|
-
|
169
|
-
frame = gpgc.capture_frame()
|
170
|
-
|
171
|
-
contours = cvc.extract_contours(frame)
|
172
|
-
|
173
|
-
cvc.detect_contour_position(contours,frame)
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
if cv2.waitKey(10)%256 == ord('q'):
|
178
|
-
|
179
|
-
break
|
180
|
-
|
181
49
|
```
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -3,8 +3,6 @@
|
|
3
3
|
カメラで撮っている映像の手の輪郭?(肌の輪郭?)を検出するメソッドがあります。今のままだと肌の面積が小さいところや中くらいのところなど輪郭として囲まれる部分が複数個出てきます。問題では面積が大きい一か所だけを囲んで下さいと書いてあります。そこで自分で調べた結果,extract_contoursメソッドのreturn contoursの三つ上の行のcontoursに入るものがnumpyの配列であることがわかりました。なのでreturn numpy.amax(numpy.contours())のようにすればいいのではないかと思っているのですがどうでしょうか?
|
4
4
|
|
5
5
|
|
6
|
-
|
7
|
-
二つ目が
|
8
6
|
|
9
7
|
```python
|
10
8
|
|