int()参数必须是字符串,类似字节的对象或数字,而不是'NoneType',试图使用我的网络摄像头进行对象检测

问题描述 投票:0回答:1
    cap = cv2.VideoCapture(0)
     with detection_graph.as_default():
       with tf.Session(graph=detection_graph) as sess:
         while True:

          # Read frame from camera
           ret, image_np = cap.read()
           # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
          image_np_expanded = np.expand_dims(image_np, axis=0)
          # Extract image tensor
          image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
         # Extract detection boxes
          boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
          # Extract detection scores
          scores = detection_graph.get_tensor_by_name('detection_scores:0')
          # Extract detection classes
          classes = detection_graph.get_tensor_by_name('detection_classes:0')
          # Extract number of detectionsd
          num_detections = detection_graph.get_tensor_by_name(
            'num_detections:0')
        # Actual detection.
        (boxes, scores, classes, num_detections) = sess.run(
            [boxes, scores, classes, num_detections],
            feed_dict={image_tensor: image_np_expanded})
        # Visualization of the results of a detection.
        vis_util.visualize_boxes_and_labels_on_image_array(
            image_np,
            np.squeeze(boxes),
            np.squeeze(classes).astype(np.int32),
            np.squeeze(scores),
            category_index,
            use_normalized_coordinates=True,
            line_thickness=8)

        # Display output
        cv2.imshow('object detection', cv2.resize(image_np, (800, 600)))

        if cv2.waitKey(25) & 0xFF == ord('q'):
            cv2.destroyAllWindows()
            break

因此,我正在尝试使用网络摄像头进行实时对象检测,但此单元格上发生了错误

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

python tensorflow object-detection object-detection-api
1个回答
0
投票

我看到您没有将图像转换为numpy数组,而是直接扩展尺寸,请尝试使用以下代码行-


 ret, frame = cap.read()
 image = np.asarray(frame)
 image_np = np.array(image)

© www.soinside.com 2019 - 2024. All rights reserved.