0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Cascade分類機【備忘録】【Opencv】

Posted at

概要

備忘録。それぞれの引数については説明なし。

サンプルコード

test.py
import cv2

cap = cv2.VideoCapture(0)
# モデルファイル? はopencvのgithubリポジオリにある
cascade = cv2.CascadeClassifier("./data/haarcascades/haarcascade_frontalface_default.xml")


if (cap is not None):
    print('cap ok')
else:
    return -1

while(True):    
    _, frame = cap.read()# カメラからフレーム情報を取得
    
    # グレースケール変換
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    
    # 顔領域の探索。
    face = cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=3, minSize=(30, 30))        
    for (x, y, w, h) in face:# 検出した顔領域を元画面に四角で描画
        cv2.rectangle(frame, (x, y), (x + w, y+h), (0,0,200), 3)

    cv2.imshow("test", frame)# 画面表示
    key = cv2.waitKey(10)# キーボード入力受付け。知ってる人もいると思いますが、これがないとimshowされません。

    if key == ord('q'):# 終了処理用 qを押下時終了
        break
cap.release()# カメラリソースを返却
cv2.destroyAllWindows() # imshowで表示した画面を削除
print("finish")
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?