【发布时间】:2020-02-18 19:01:14
【问题描述】:
当我尝试使用笔记本电脑或计算机网络摄像头检测人脸时,它工作正常,但当我尝试使用 IP 摄像头检测时,检测一帧似乎需要很长时间。有什么解决方案吗,因为我也尝试过 YOLO。比 opencv haar cascade 需要更多时间
我有一个简单的代码可以检测面部并裁剪而不是部分帧。
cap = cv2.VideoCapture("web_Cam_IP")
cropScal = 25
while(True):
# Capture frame-by-frame
for i in range(10): #this loop skip 10 frames if I don't skip frame it looks like it stack there
ret, frame = cap.read()
frame = cv2.resize(frame, (0, 0), fx=0.70, fy=0.70)
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
faces = faceCascade.detectMultiScale(gray, scaleFactor=1.02, minNeighbors=5, minSize=(30, 30))
for (x, y, w, h) in faces:
if len(faces) > 0 :
try:
img = gray[y-cropScal:y+h+cropScal, x-cropScal:x+w+cropScal]
img = cv2.resize(img,(200,200))
img = Image.fromarray(img)
img.save('images/'+datetime.now().strftime("%d_%m_%Y_%I_%M_%S_%p")+'.png')
except Exception as e:
pass
cv2.rectangle(gray, (x-cropScal, y-cropScal), (x+w+cropScal, y+h+cropScal), (0, 255, 0), 2)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
【问题讨论】:
-
您是否使用 CPU 来处理帧?理想情况下,yolo 需要 GPU 来进行计算。我想你在网络和网络摄像头上都获得了 1 fps 的性能?由于网络上的帧流,IP cam 肯定更慢。
-
是的,我用的是CPU,但这不是YOLO,这是opencv或检测。
标签: python opencv machine-learning image-processing yolo