我试图加载一个YouTube视频,在脸上放一个盒子,并预测他们的年龄和性别。但是,当我运行代码时,它只是执行,但弹出窗口没有出现。我的代码在下面。我不确定问题出在哪里。感谢您的帮助,伙计们import pafyimport cv2url = 'https://www.youtube.com/watch?v=dTL7LriRZJQ' #URL that you want to copyvPafy= pafy.new(url) #get URL and get best mp4 video play = vPafy.getbest(preftype="mp4")#Video capturecap = 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 videodef 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
1 回答
慕婉清6462132
TA贡献1804条经验 获得超2个赞
您已经创建了两个函数video_detector()和init_caffe_models(),它们从未被调用过。您的代码只是到达gender_list = [“男性”,“女性”],然后退出而没有进入这两个函数。
添加回答
举报
0/150
提交
取消