【问题标题】:I'm getting error. I want to object counting我收到错误。我想反对计数
【发布时间】:2020-01-06 12:56:38
【问题描述】:

我正在使用对象检测。我想同时计算对象。但我收到错误。你能帮忙吗?

错误:

    Traceback (most recent call last):
    File "C:\tensorflow2\models\research\object_detection\Object_detection_image_say3.py", line 138, 
    in 
    <module>
    v2.putText(input_frame, counting_mode, (10, 35), font, 0.8, 
    (0,255,255),2,cv2.FONT_HERSHEY_SIMPLEX)
    SystemError: <built-in function putText> returned NULL without setting an error

主要代码: 我使用以下代码。我收到错误。

    input_frame = cv2.imread(PATH_TO_IMAGE)
    image_expanded = np.expand_dims(input_frame, axis=0)

    (boxes, scores, classes, num) = sess.run(
    [detection_boxes, detection_scores, detection_classes, num_detections],
    feed_dict={image_tensor: image_expanded})

    font = cv2.FONT_HERSHEY_SIMPLEX

    counting_mode = vis_util.visualize_boxes_and_labels_on_image_array(
    input_frame,
    np.squeeze(boxes),
    np.squeeze(classes).astype(np.int32),
    np.squeeze(scores),
    category_index,
    use_normalized_coordinates=True,
    line_thickness=2,
    min_score_thresh=0.80)

    if(len(counting_mode) == 0):
    cv2.putText(input_frame, "...", (10, 35), font, 0.8, (0,255,255),2,cv2.FONT_HERSHEY_SIMPLEX)                       
    else:
    cv2.putText(input_frame, counting_mode, (10, 35), font, 0.8, 
    (0,255,255),2,cv2.FONT_HERSHEY_SIMPLEX) 
    cv2.imshow('tensorflow_object counting_api',input_frame)
    cv2.waitKey(0)

【问题讨论】:

  • visualize_boxes_and_labels_on_image_array 返回一个 NumPy 数组,而不是一个字符串,putText 实际上期望它作为第二个输入。你希望在那一行写什么?
  • 一个函数正在运行。
  • 为每个盒子位置创建一个显示字符串(和颜色),对任何盒子进行分组
  • 在图像上绘制所有框
  • 我做这些事情。

标签: opencv tensorflow detection counting


【解决方案1】:

您的第二个 cv2putText 将counting_mode 作为输入 counting_mode 不是字符串,因此无法显示

将您的counting_mode 对象转换为字符串(str),然后再将其注入cv2.putText

【讨论】:

  • Hi " if(len(counting_mode) == 0): " 还不够吗?
  • 嗨,我做到了。但结果相同。
猜你喜欢
  • 2021-06-29
  • 2021-03-15
  • 1970-01-01
  • 2019-11-05
  • 1970-01-01
  • 2020-09-17
  • 1970-01-01
  • 1970-01-01
  • 2022-10-20
相关资源
最近更新 更多