首页 > 解决方案 > 部署在服务器 Django/Python 上时相机未打开

问题描述

无法在服务器上打开相机,其中相同的副本具有相同的设置

  cam = cv2.VideoCapture(0)

使用它来初始化相机(网络摄像头)和下面的代码来处理数据流,下图显示服务器上的错误单击此处查看错误

def identify_faces(video_capture):
    buf_length = 10
    known_conf = 6
    buf = [[]] * buf_length
    i = 0

    process_this_frame = True
    while True:
        ret, frame = video_capture.read()
        small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
        rgb_frame = small_frame[:, :, ::-1]
        if process_this_frame:
            predictions = predict(rgb_frame, model_path="folder/folder/models/trainedmodel.clf")
        process_this_frame = not process_this_frame

        face_names = []

        for name, (top, right, bottom, left) in predictions:
            top *= 4
            right *= 4
            bottom *= 4
            left *= 4
            cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
            cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
            font = cv2.FONT_HERSHEY_DUPLEX
            cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)
            identify1(frame, name, buf, buf_length, known_conf)

            face_names.append(name)

        buf[i] = face_names
        i = (i + 1) % buf_length
        cv2.imshow('Video', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    video_capture.release()
    cv2.destroyAllWindows()

标签: pythondjangocv2face-recognitionopencv-python

解决方案


推荐阅读