【问题标题】:int() argument must be a string, a bytes-like object or a number, not 'NoneType'int() 参数必须是字符串、类似字节的对象或数字,而不是“NoneType”
【发布时间】:2018-06-02 18:00:04
【问题描述】:

我尝试开发对象检测API,在执行过程中出现错误,

import cv2
cap = cv2.VideoCapture(0)

with detection_graph.as_default():
 with tf.Session(graph=detection_graph) as sess:
   while(True):
     ret,image_np =cap.read()
     image_np_expanded = np.expand_dims(image_np,axis=0)
     image_tensor =detection_graph.get_tensor_by_name('image_tensor:0')
     boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
     scores = detection_graph.get_tensor_by_name('detection_scores:0')
     classes = detection_graph.get_tensor_by_name('detection_classes:0')
     num_detections = detection_graph.get_tensor_by_name('num_detections:0')

     (boxes,scores,classes,num_detections) = sess.run(
             [boxes,scores,classes,num_detections],
             feed_dict={ image_tensor:image_np_expanded})
     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)

     cv2.imshow('image',cv2.resize(image_np,(1280,960)))
     if cv2.waitkey(25) & 0xFF == ord('q'):
         break
         cv2.destroyAllWindows()
         cap.release()

【问题讨论】:

  • 你能发布完整的错误跟踪吗?
  • 文件“C:\Users\Sampath\Anaconda3\lib\site-packages\numpy\core\numeric.py”,第 492 行,在 asarray 中返回数组(a,dtype,copy=False, order=order) TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
  • 我认为这不是完整错误回溯,请通过编辑将其发布在问题中,并创建minimal reproducible example
  • 该整数参数为空。在运行它之前确保它有一个值@sampathkumara
  • @JeruLuke 不明白

标签: python opencv tensorflow


【解决方案1】:

您是否检查了流是否正确打开。您可以使用以下行进行尝试。

cap.isOpened()

如果上述方法返回true,则表示读取文件没有问题。然后,您需要使用下面的行设置要读取的帧。

cap.set(cv2.CAP_PROP_POS_MSEC,frameNumber)

在直播的情况下,您可以简单地将 frameNumber 设置为 1000(以毫秒为单位)!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-16
    相关资源
    最近更新 更多