0

我可以通过将帧作为图像然后处理来处理视频帧。但无法直接传帧到物体检测。使用 imwrite 保存图像会使程序变慢...

这是我的主要方法:

cap = cv2.VideoCapture(gstreamer_pipeline(flip_method=2), cv2.CAP_GSTREAMER)

if cap.isOpened():
    window_handle = cv2.namedWindow("CSI Camera", cv2.WINDOW_AUTOSIZE)
    # Window
    while cv2.getWindowProperty("CSI Camera", 0) >= 0:
        ret_val, frame = cap.read()
        if not ret_val:
            break
        frame = imutils.resize(frame, width=600)

        #cv2.imwrite('box.jpg', frame)
        #image = Image.open(path)
        #Error in here!!!
        predictions = od_model.predict_image(frame)


        for x in range(len(predictions)):
            probab = (predictions[x]['probability'])*100
            if(probab > 45):
                print(predictions[x]['tagName'], end=' ')
                print(probab)
        #cv2.imshow("CSI Camera", frame)
        # This also acts as
        keyCode = cv2.waitKey(30) & 0xFF
        # Stop the program on the ESC key
        if keyCode == 27:
            break
    cap.release()
    cv2.destroyAllWindows()
else:
    print("Unable to open camera")

错误信息:

predictions = od_model.predict_image(frame)
File "/home/bharat/New_IT3/object_detection.py", line 125, in 
predict_image
inputs = self.preprocess(image)
File "/home/bharat/New_IT3/object_detection.py", line 130, in 
preprocess
image = image.convert("RGB") if image.mode != "RGB" else image
AttributeError: 'numpy.ndarray' object has no attribute 'mode'
4

1 回答 1

0

打开 cv 读取 bgr 色谱中的图像将其转换为 rgb 并发送图像进行检测,同样的 api 是 -

帧 = cv2.cvtColor(帧,cv2.COLOR_BGR2RGB)

于 2020-02-21T12:11:59.753 回答