我试图加载一个YouTube视频,在脸上放一个盒子,并预测他们的年龄和性别。但是,当我运行代码时,它只是执行,但弹出窗口没有出现。我的代码在下面。我不确定问题出在哪里。感谢您的帮助,伙计们
import pafy
import cv2
url = 'https://www.youtube.com/watch?v=dTL7LriRZJQ' #URL that you want to copy
vPafy= pafy.new(url) #get URL and get best mp4 video
play = vPafy.getbest(preftype="mp4")
#Video capture
cap = cv2.VideoCapture(play.url)
MODEL_MEAN_VALUES = (78.4, 87.7, 114.9)
age_list = ['(0, 2)', '(4, 6)', '(8, 12)', '(15, 20)', '(25, 32)', '(38, 43)', '(48, 53)', '(60, 100)']
gender_list = ['Male', 'Female']
# defining a function to load prototxt & caffe
def init_caffe_models():
age_net = cv2.dnn.readNetFromCaffe('/Users/Desktop/Gender-and-Age-Detection-master/age_deploy.prototxt', '/Users/Desktop/Gender-and-Age-Detection-master/age_net.caffemodel')
gender_net = cv2.dnn.readNetFromCaffe('/Users/Desktop/Gender-and-Age-Detection-master/gender_deploy.prototxt','/Users/Desktop/Gender-and-Age-Detection-master/gender_net.caffemodel')
return(age_net, gender_net)
# defining a function for capturing the video
def video_detector(age_net, gender_net):
font = cv2.FONT_HERSHEY_SIMPLE
while True:
ret, frame = cap.read() #returns a boolean
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
face_cascade = cv2.CascadeClassifier('/Users/Desktop/OpenCV-Python-Series-master/src/cascades/data/haarcascade_frontalface_default.xml')
faces = face_cascade.detectMultiScale(gray, 1.1, 5) # input = grey image, 1.1 = scale factor
慕婉清6462132
相关分类