【问题标题】:OpenCV slow face detection with CCTV Or IP Cam使用闭路电视或 IP 摄像头的 OpenCV 慢速人脸检测
【发布时间】: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


【解决方案1】:

您只是将输入帧缩放 0.70 倍,而不是绝对分辨率。您的 IP 摄像头可能比网络摄像头具有更高的分辨率,因此检测需要更多时间来分析更大的帧。

在人脸检测之前尝试将帧重新缩放到确定的大小(例如 800x600)。

【讨论】:

  • frame = cv2.resize(frame, (800,600)) 但它会延迟,并且相机的显示会滞后。
猜你喜欢
  • 2019-11-02
  • 2021-01-22
  • 2013-12-28
  • 2011-04-15
  • 2017-12-28
  • 1970-01-01
  • 1970-01-01
  • 2019-11-11
  • 1970-01-01
相关资源
最近更新 更多