我正在尝试将两个脚本组合在一起,以便通过笔记本电脑网络摄像头实现面部识别。我有一个工作的opencv2脚本,可以与我的网络摄像头一起查看实时镜头,另一个是面部识别脚本,在jpeg静止图像上使用haar分类器。我正在使用Python 3.6 IDE,打开cv2。以下脚本适用于通过笔记本电脑网络摄像头查看实时信息。
for( var i in myArray ){
try{ throw i }
catch(ii){
// Do whatever it is you want to do with ii
}
}
我得到了这个脚本,在一个面部周围绘制一个框,以便为haar分类器工作,并在静止的.jpeg图像上运行。如何将这两个脚本与使用haar分类器进行实时视频输入的面部识别相结合? haar分类器XML和jpeg是我本地PC目录中的文件。
import numpy as np
import cv2, time
video = cv2.VideoCapture(0)
a = 0
while True:
a = a + 1
check, frame = video.read()
print(check)
print(frame)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow("Capturing", gray)
cv2.waitKey(1)
key = cv2.waitKey(1)
if key == ord('q'):
break
print(a)
video.release()
答案 0 :(得分:0)
试试这个:
import numpy as np
import cv2, time
import matplotlib.pyplot as plt
haar_face_cascade = cv2.CascadeClassifier('C:/Python/opencv/opencv-master/opencv-master/data/haarcascades/haarcascade_frontalface_alt.xml')
video = cv2.VideoCapture(0)
a = 0
while True:
a = a + 1
check, frame = video.read()
print(check)
print(frame)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = f_cascade.detectMultiScale(gray, scaleFactor=scaleFactor, minNeighbors=5);
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 0, 255), 2)
cv2.imshow("Face Detector", frame)
cv2.waitKey(1)
key = cv2.waitKey(1)
if key == ord('q'):
break
print(a)
video.release()