前提・実現したいこと
現在、このプログラムに目の開眼度や瞬きの回数を追加するコードを追加して眠りの兆候を検知できるプログラムにしようと考えています。
今抱いてる疑問は以下の通りです。
[1]retは必要か(形式的なもの?)
[2]detsの中身
[3]shapeの中身
[4]for shape_point_count in range(shape.num_parts):
shape_point = shape.part(shape_point_count)の2行
????shape_point_count という変数にshape.num_partsの要素数分の回数の以降のメソッドを実行及び格納?
ご解決できる方よろしくお願いいたします。
発生している問題・エラーメッセージ
該当のソースコード
import sys
import dlib
import cv2
import time
import copy
predictor_path = "./shape_predictor_68_face_landmarks.dat"
detector = dlib.get_frontal_face_detector()顔検出器用意
predictor = dlib.shape_predictor(predictor_path)
■0番のカメラ(最初に見つかるカメラ)を引数にしてVideoCaptureクラスをインスタンス化
video_input = cv2.VideoCapture(0)
■isOpenedメソッドを使ってWebカメラに接続できているか確認
while(video_input.isOpened() == True):
■画像をWebカメラから取得できていればimageにnumpyのndarray形式で画像が,retにbool形式でTrueが格納される⇒受け取る引数減らして([1]を使用して)不要?[1]
ret, frame = video_input.read()
■深いコピー
temp_frame = copy.deepcopy(frame)
■顔検出処理**[2]**
dets= detector(temp_frame, 1)
for k, d in enumerate(dets):
■d == dets[k]であり、detsのk番目の実体
print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(k, d.left(), d.top(), d.right(), d.bottom()))
■顔検出した範囲内で顔器官検出
shape = predictor(temp_frame, d)[3]
for shape_point_count in range(shape.num_parts): shape_point = shape.part(shape_point_count)**[4]** if shape_point_count < 17: # [0-16]:輪郭 cv2.circle(frame, (int(shape_point.x), int(shape_point.y)), 2, (0, 0, 255), -1) elif shape_point_count < 22: # [17-21]眉(右) cv2.circle(frame, (int(shape_point.x), int(shape_point.y)), 2, (0, 255, 0), -1) elif shape_point_count < 27: # [22-26]眉(左) cv2.circle(frame, (int(shape_point.x), int(shape_point.y)), 2, (255, 0, 0), -1) elif shape_point_count < 31: # [27-30]鼻背 cv2.circle(frame, (int(shape_point.x), int(shape_point.y)), 2, (0, 255, 255), -1) elif shape_point_count < 36: # [31-35]鼻翼、鼻尖 cv2.circle(frame, (int(shape_point.x), int(shape_point.y)), 2, (255, 255, 0), -1) elif shape_point_count < 42: # [36-4142目47) cv2.circle(frame, (int(shape_point.x), int(shape_point.y)), 2, (255, 0, 255), -1) elif shape_point_count < 48: # [42-47]目(左) cv2.circle(frame, (int(shape_point.x), int(shape_point.y)), 2, (0, 0, 128), -1) elif shape_point_count < 55: # [48-54]上唇(上側輪郭) cv2.circle(frame, (int(shape_point.x), int(shape_point.y)), 2, (0, 128, 0), -1) elif shape_point_count < 60: # [54-59]下唇(下側輪郭) cv2.circle(frame, (int(shape_point.x), int(shape_point.y)), 2, (128, 0, 0), -1) elif shape_point_count < 65: # [60-64]上唇(下側輪郭) cv2.circle(frame, (int(shape_point.x), int(shape_point.y)), 2, (0, 128, 255), -1) elif shape_point_count < 68: # [65-67]下唇(上側輪郭) cv2.circle(frame, (int(shape_point.x), int(shape_point.y)), 2, (128, 255, 0), -1) cv2.circle(frame,(int(shape.part(8).x),int(shape.part(8).y)),10,(255,255,255),-1) cv2.imshow('face landmark detector', frame) c = cv2.waitKey(1) & 0xFF if c==27: # ESC break
video_input.release()
cv2.destroyAllWindows()
プログラムを引用させていただいたブログ, http://kazuhito00.hatenablog.com/entry/2016/10/12/010100
Pythonソースコード
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。