1
我有一個小腳本,我正在將來自Raspberry Pi上的picamera的圖像傳遞給OpenCV的流。一旦OpenCV有圖像,它應該使用哈爾級聯方法尋找人臉。如果我將臉部檢測分開,代碼將運行正常,讀取圖像並按照預期上傳到遠程服務器。當我把人臉檢測中,我得到了以下錯誤:必需的參數'rejectLevels'(pos 2)找不到OpenCV Raspberry Pi
標誌= cv2.cv.CV_HAAR_SCALE_IMAGE
類型錯誤:必需的參數「rejectLevels」(位置2)未找到
這是代碼:
current_time = time.time()
endtime = current_time + 30
stream = io.BytesIO()
CAMERA_WIDTH = 640
CAMERA_HEIGHT = 480
cascPath = sys.argv[1]
faceCascade = cv2.CascadeClassifier(cascPath)
while current_time <= endtime:
timeStamp = time.strftime('%d-%m-%Y-%H-%M-%S', time.localtime(current_time))
with picamera.PiCamera() as cam:
cam.rotation = 270
cam.resolution = (CAMERA_WIDTH, CAMERA_HEIGHT)
cam.capture(stream, format='bmp')
data = np.fromstring(stream.getvalue(), dtype=np.uint8)
img = cv2.imdecode(data, 1)
stream.seek(0)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbours=5,
minSize=(30,30),
flags = cv2.cv.CV_HAAR_SCALE_IMAGE
)
print("Found {0} faces!".format(len(faces)))
我不確定到底是什麼錯誤告訴我,有些建議會很棒!
非常感謝你!!!永遠都看不到,英國vs美國的拼寫! – 2015-03-04 17:11:03
很高興看到它的幫助。當我嘗試製作minSize值變量並忘記將它們轉換爲整數時,我遇到了相同的混淆錯誤信息;-) – Hokascha 2015-03-05 12:59:22
我從包含該錯字的教程中得到了我的例子。 – 2015-04-26 20:35:55