2016-06-14 5 views
0

私は顔検出と画像クロッピングのためにこのlinkを見つけました。私はこのスクリプトを使用したいと思いますが、私はcv2をインストールしています。cv2と同等の属性です。

次の関数のcv関数をどのようにしてcv2関数に変換できますか?

def faces_from_pil_image(pil_image): 
    "Return a list of (x,y,h,w) tuples for faces detected in the PIL image" 
    storage = cv.CreateMemStorage(0) 
    facial_features = cv.Load('haarcascade_frontalface_alt.xml', storage=storage) 
    cv_im = cv.CreateImageHeader(pil_image.size, cv.IPL_DEPTH_8U, 3) 
    cv.SetData(cv_im, pil_image.tostring()) 
    faces = cv.HaarDetectObjects(cv_im, facial_features, storage) 
    # faces includes a `neighbors` field that we aren't going to use here 
    return [f[0] for f in faces] 

答えて

0

いずれかを使用

import cv2 

storage = cv2.cv.CreateMemStorage(0) 

又は

from cv2 import * 

storage = cv.CreateMemStorage(0) 
+0

エラー: 'ファイル "face_detect.py"、ライン55、faces_from_pil_imageで ストレージ= cv2.cv.CreateMemStorage(0) AttributeError: 'module'オブジェクトに属性 'cv''がありません – Sibi

+0

あなたの 'cv2 .__ version__'とは何ですか?どのバージョンのPython? – Mailerdaimon

+0

Python 3.4。 cv2 3.1.0-dev – Sibi

関連する問題