Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用CCTV或IP Cam进行OpenCV慢速人脸检测_Python_Opencv_Machine Learning_Image Processing_Yolo - Fatal编程技术网

Python 使用CCTV或IP Cam进行OpenCV慢速人脸检测

Python 使用CCTV或IP Cam进行OpenCV慢速人脸检测,python,opencv,machine-learning,image-processing,yolo,Python,Opencv,Machine Learning,Image Processing,Yolo,当我尝试使用笔记本电脑或电脑网络摄像头检测人脸时,效果很好,但当我尝试使用IP摄像头检测人脸时,检测一帧似乎需要花费很多时间。有什么解决办法吗?因为我也尝试了YOLO。它比opencv haar cascade花费更多的时间 这里我有一个简单的代码,可以检测人脸和裁剪,而不是部分帧 cap = cv2.VideoCapture("web_Cam_IP") cropScal = 25 while(True): # Capture frame-by-frame for i in

当我尝试使用笔记本电脑或电脑网络摄像头检测人脸时,效果很好,但当我尝试使用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)。

frame=cv2.resize(frame,(800600))但它会延迟,并且相机的显示会滞后。您是否使用CPU处理帧?理想情况下,yolo需要GPU来进行计算。我想web和ip摄像头的性能都是1fps?由于网络上的帧流,IP cam速度肯定较慢。是的,我使用的是CPU,但这不是YOLO,这是opencv或检测。