参数必须是字符串或数字

时间:2018-05-16 19:29:57

标签: tensorflow cv2

我在运行脚本10秒后收到此错误消息。

  

int()参数必须是字符串,类字节对象或数字,而不是'NoneType'

能否请您解释此错误消息并帮我解决此问题。 我正在使用tensorflow版本1.8 cv2版本3.4.0

提前致谢!

我的代码

video = cv2.VideoCapture('rtsp://10.10.10.10/h264.sdp?res=half&x0=0&y0=0&x1=1920&y1=1080&qp=20&ratelimit=10000&doublescan=0&ssn=16026')
ret = video.set(3,1280)
ret = video.set(4,720)


while(True):
    try:
        # Acquire frame and expand frame dimensions to have shape: [1, None, None, 3]
        # i.e. a single-column array, where each item in the column has the pixel RGB value
        #frame = cameraDevice.get_frame()
        ret, frame = video.read()
        frame_expanded = np.expand_dims(frame, axis=0)

        # Perform the actual detection by running the model with the image as input
        (boxes, scores, classes, num) = sess.run(
            [detection_boxes, detection_scores, detection_classes, num_detections],
            feed_dict={image_tensor: frame_expanded})

        # Draw the results of the detection (aka 'visulaize the results')
        vis_util.visualize_boxes_and_labels_on_image_array(
            frame,
            np.squeeze(boxes),
            np.squeeze(classes).astype(np.int32),
            np.squeeze(scores),
            category_index,
            use_normalized_coordinates=True,
            line_thickness=4,
            min_score_thresh=0.85)

        # All the results have been drawn on the frame, so it's time to display it.
        cv2.imshow('Object detector', frame)
    except Exception as exc:
        print(exc)

    # Press 'q' to quit
    if cv2.waitKey(1) == ord('q'):
        break

# Clean up
video.release()
cv2.destroyAllWindows()

1 个答案:

答案 0 :(得分:0)

我得到同样的错误。它最初来自frame_expanded为None类型,因此ret为false并构成一个0矩阵。这个问题为什么很难。似乎video.read()与张量流正在执行的操作发生冲突,因此无法读取不是0矩阵的图像。有人可以帮忙吗?

Traceback (most recent call last):
  File "flight_detection4.py", line 564, in <module>
    detect(40,11,"","test.jpg")
  File "flight_detection4.py", line 158, in detect
    feed_dict={image_tensor: frame_expanded})
  File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/client/session.py", line 950, in run
    run_metadata_ptr)
  File "/usr/local/lib/python3.7/dist-packages/tensorflow/python/client/session.py", line 1142, in _run
    np_val = np.asarray(subfeed_val, dtype=subfeed_dtype)
  File "/usr/lib/python3/dist-packages/numpy/core/numeric.py", line 538, in asarray
    return array(a, dtype, copy=False, order=order)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'