Python脚本在几秒钟后自动关闭,当它从IP摄像机对RTSP实时源进行对象检测时?

问题描述 投票:0回答:1

我在RTSP链接上进行图像处理。当我从RTSP捕获实时源并在python中显示时,它工作得很好而且非常完美。但是当我从ip camera在RTSP实时源上实现对象检测时,它可以正常工作几秒钟。检测到对象几秒钟,但之后我的python脚本会自动关闭。 Python脚本到达代码的最后一行然后停止。我不想在几秒钟后自动关闭脚本。

python image-processing rtsp
1个回答
0
投票
ret, frame = cap.read()
if ret==True:
    (h, w) = frame.shape[:2]
    blob = cv2.dnn.blobFromImage(cv2.resize(frame, (300, 300)),0.007843, (300, 300), 127.5)
    net.setInput(blob)
    detections = net.forward()
    for i in np.arange(0, detections.shape[2]):
              confidence = detections[0, 0, i, 2]
              if confidence > args["confidence"]:
                       idx = int(detections[0, 0, i, 1])
                       box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
                       (startX, startY, endX, endY) = box.astype("int")
                       label = "{}: {:.2f}%".format(CLASSES[idx],confidence * 100)
                       cv2.rectangle(frame, (startX, startY), (endX, endY),COLORS[idx], 2)
                       y = startY - 15 if startY - 15 > 15 else startY + 15
                       cv2.putText(frame, label, (startX, y),cv2.FONT_HERSHEY_SIMPLEX, 0.5, COLORS[idx], 2)
                       if idx==15:
                           out.write(frame)
                           print("This is person")
                       else:
                           break
    cv2.imshow('frame',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
else:
    break
© www.soinside.com 2019 - 2024. All rights reserved.