###前提・実現したいこと
opencvについて勉強中でhttp://qiita.com/hitomatagi/items/8f2f37646179aca68649にあるプログラムを動かしてみたいんですが知識がなくわかりません。
###発生している問題・エラーメッセージ
AttributeError: 'module' object has no attribute 'createLBPHFaceRecognizer'
###該当のソースコード
python
1#!/usr/bin/python 2# -*- coding: utf-8 -*- 3 4import cv2, os 5import numpy as np 6from PIL import Image 7 8# トレーニング画像 9train_path = './yalefaces' 10 11# テスト画像 12test_path = './test' 13 14# Haar-like特徴分類器 15cascadePath = "haarcascade_frontalface_default.xml" 16faceCascade = cv2.CascadeClassifier(cascadePath) 17 18# 顔認識器の構築 for OpenCV 2 19# LBPH 20recognizer = cv2.createLBPHFaceRecognizer() 21 22# 指定されたpath内の画像を取得 23def get_images_and_labels(path): 24 # 画像を格納する配列 25 images = [] 26 # ラベルを格納する配列 27 labels = [] 28 # ファイル名を格納する配列 29 files = [] 30 for f in os.listdir(path): 31 # 画像のパス 32 image_path = os.path.join(path, f) 33 # グレースケールで画像を読み込む 34 image_pil = Image.open(image_path).convert('L') 35 # NumPyの配列に格納 36 image = np.array(image_pil, 'uint8') 37 # Haar-like特徴分類器で顔を検知 38 faces = faceCascade.detectMultiScale(image) 39 # 検出した顔画像の処理 40 for (x, y, w, h) in faces: 41 # 顔を 200x200 サイズにリサイズ 42 roi = cv2.resize(image[y: y + h, x: x + w], (200, 200), interpolation=cv2.INTER_LINEAR) 43 # 画像を配列に格納 44 images.append(roi) 45 # ファイル名からラベルを取得 46 labels.append(int(f[7:9])) 47 # ファイル名を配列に格納 48 files.append(f) 49 50 return images, labels, files 51 52 53# トレーニング画像を取得 54images, labels, files = get_images_and_labels(train_path) 55 56# トレーニング実施 57recognizer.train(images, np.array(labels)) 58 59# テスト画像を取得 60test_images, test_labels, test_files = get_images_and_labels(test_path) 61 62i = 0 63while i < len(test_labels): 64 # テスト画像に対して予測実施 65 label, confidence = recognizer.predict(test_images[i]) 66 # 予測結果をコンソール出力 67 print("Test Image: {}, Predicted Label: {}, Confidence: {}".format(test_files[i], label, confidence)) 68 # テスト画像を表示 69 cv2.imshow("test image", test_images[i]) 70 cv2.waitKey(300) 71 72 i += 1 73 74# 終了処理 75cv2.destroyAllWindows()
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
使用中のpythonのバージョンやモジュールのバージョンが書いてあるとより条件が特定しやすくなります。