python - 使用闭路电视或 IP 摄像头的 OpenCV 慢速人脸检测
问题描述
当我尝试使用我的笔记本电脑或计算机网络摄像头检测面部时,它工作正常,但是当我尝试使用 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()
解决方案
您只是将输入帧缩放 0.70 倍,而不是绝对分辨率。您的 IP 摄像头可能比网络摄像头具有更高的分辨率,因此检测需要更多时间来分析更大的帧。
尝试在人脸检测之前将帧重新缩放到确定的大小(例如 800x600)。
推荐阅读
- r - 使用 purrr 对相同的数据但不同的参数多次调用相同的函数
- drop-down-menu - YII Select2 下拉菜单
- macos - 返回 macOS perl - 来自 brew perl
- pandas - 在一列熊猫中拆分嵌套列表
- c++ - opengl-顶点法线不考虑
- java - 为什么 Apache POI xlsx 换行文本不起作用?
- python - 将列表项映射到 tensorflow 数据集字典
- python - 音频文件在通过低通滤波器后听起来很糟糕/嘈杂
- reactjs - 将 renderItem 作为 prop 传递给组件时,FlatList 项内的函数不会触发
- reactjs - 如何在谷歌地图上查找用户位置并使用 google-map-react 库关注他们所在的位置