teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

個人の情報が特定できる可能性があったため

2019/05/28 23:24

投稿

konnitiha2
konnitiha2

スコア30

title CHANGED
File without changes
body CHANGED
@@ -1,49 +1,6 @@
1
- 情報系の学生です。pythonやopenCVはほとんど触ったことがありません。今度行われる他の学校とともにgopigoを使った開発を行うのでその予習内容に関して質問があります。実行環境は学校にしかなく今は動作確認ができません。
2
1
  カメラで撮っている映像の手の輪郭?(肌の輪郭?)を検出するメソッドがあります。今のままだと肌の面積が小さいところや中くらいのところなど輪郭として囲まれる部分が複数個出てきます。問題では面積が大きい一か所だけを囲んで下さいと書いてあります。そこで自分で調べた結果,extract_contoursメソッドのreturn contoursの三つ上の行のcontoursに入るものがnumpyの配列であることがわかりました。なのでreturn numpy.amax(numpy.contours())のようにすればいいのではないかと思っているのですがどうでしょうか?
3
2
 
4
3
  ```python
5
- import cv2
6
- import picamera
7
- import picamera.array
8
- import time
9
- import numpy
10
- #from fractions import Fraction
11
-
12
- class gopigo_control:
13
- # Init various camera parameter.
14
- # Finally, every parameter should be fixed to reasonable values.
15
- def __init__(self):
16
- self.width = 640
17
- self.height = 480
18
- self.camera = picamera.PiCamera(resolution=(self.width,self.height),framerate=10)
19
- self.camera.iso = 100
20
- # Wait for the automatic gain control to settle
21
- time.sleep(2)
22
- # Fix the values
23
- self.camera.shutter_speed = self.camera.exposure_speed
24
- self.camera.exposure_mode = 'off'
25
- g = self.camera.awb_gains
26
- self.camera.awb_mode = 'off'
27
- self.camera.awb_gains = g
28
- print("shutter:"+str(self.camera.shutter_speed)+" awb_gains:"+str(g))
29
-
30
- # capture a frame from picamera
31
- def capture_frame(self):
32
- cap_stream = picamera.array.PiRGBArray(self.camera,size=(self.width,self.height))
33
- self.camera.capture(cap_stream, format='bgr',use_video_port=True)
34
- frame = cap_stream.array
35
- return frame
36
-
37
- class cv_control:
38
- def __init__(self):
39
- self.lower = []
40
- self.upper = []
41
-
42
- # set lower and upper filter.
43
- def set_filter(self,base_hvalue):
44
- self.lower = numpy.array([base_hvalue-5, 80, 50], dtype = "uint8")
45
- self.upper = numpy.array([base_hvalue+5, 255, 230], dtype = "uint8")
46
-
47
4
  # returns contours array
48
5
  def extract_contours(self,frame):
49
6
  image = numpy.copy(frame)
@@ -65,27 +22,4 @@
65
22
  cv2.imshow("OpenCV Sample05 contours",image)
66
23
  return contours
67
24
 
68
- # show each contour center position, width, height, and area
69
- def detect_contour_position(self,contours,frame):
70
- for cont in contours:
71
- x,y,w,h = cv2.boundingRect(cont) # encloses contour in a rectangle.
72
- cx = x + w/2
73
- cy = y + h/2
74
- area = cv2.contourArea(cont) # calculate contour area
75
- print("(cx,cy,wide,height,area)=(" + str(cx) + "," + str(cy) + "," + str(w) + "," + str(h) + "," + str(area) + ")")
76
- cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),5)
77
- cv2.imshow("OpenCV Sample05 rect-contours",frame)
78
-
79
- if __name__ == '__main__':
80
- gpgc = gopigo_control()
81
- cvc = cv_control()
82
- cvc.set_filter(10)
83
-
84
- while True:
85
- frame = gpgc.capture_frame()
86
- contours = cvc.extract_contours(frame)
87
- cvc.detect_contour_position(contours,frame)
88
-
89
- if cv2.waitKey(10)%256 == ord('q'):
90
- break
91
25
  ```

1

誤字

2019/05/28 23:24

投稿

konnitiha2
konnitiha2

スコア30

title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,6 @@
1
1
  情報系の学生です。pythonやopenCVはほとんど触ったことがありません。今度行われる他の学校とともにgopigoを使った開発を行うのでその予習内容に関して質問があります。実行環境は学校にしかなく今は動作確認ができません。
2
2
  カメラで撮っている映像の手の輪郭?(肌の輪郭?)を検出するメソッドがあります。今のままだと肌の面積が小さいところや中くらいのところなど輪郭として囲まれる部分が複数個出てきます。問題では面積が大きい一か所だけを囲んで下さいと書いてあります。そこで自分で調べた結果,extract_contoursメソッドのreturn contoursの三つ上の行のcontoursに入るものがnumpyの配列であることがわかりました。なのでreturn numpy.amax(numpy.contours())のようにすればいいのではないかと思っているのですがどうでしょうか?
3
3
 
4
- 二つ目が
5
4
  ```python
6
5
  import cv2
7
6
  import picamera