【问题标题】:In live camera object detection how to swich off the camera and leave the boxes在实时相机对象检测中如何关闭相机并离开盒子
【发布时间】:2021-04-20 14:08:11
【问题描述】:

这里的第一个问题。不是等待答案,而是关于如何解决它或阅读文档的一些指导

我正在学习 Tensorflow,我正在处理实时相机对象检测的基本示例,并希望在其他软件 (GIS) 中输入输出

我可以更改来自相机的最终图像吗?或者甚至关闭来自相机的图像并只留下正方形和标签

这是绘制矩形的代码

input_tensor = tf.convert_to_tensor(np.expand_dims(image_np, 0), dtype=tf.float32)
detections, predictions_dict, shapes = detect_fn(input_tensor)

label_id_offset = 1
image_np_with_detections = image_np.copy()

viz_utils.visualize_boxes_and_labels_on_image_array(
      image_np_with_detections,
      detections['detection_boxes'][0].numpy(),
      (detections['detection_classes'][0].numpy() + label_id_offset).astype(int),
      detections['detection_scores'][0].numpy(),
      category_index,
      use_normalized_coordinates=True,
      max_boxes_to_draw=200,
      min_score_thresh=.30,
      agnostic_mode=False)

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

函数visualize_boxes_and_labels_on_image_array是Tensorflow models/research/object_detection/utils/visualization_utils.py的一部分

我的第一个猜测是将 image_np_with_detections 修改为空白图像,但它不起作用。我曾尝试直接修改可视化工具,但它会在使用图像处理检测时产生错误。

另一种选择是深入研究 opencv 文档

有什么线索吗?

提前致谢

【问题讨论】:

    标签: python tensorflow opencv computer-vision


    【解决方案1】:

    在这里,您将了解如何逐步向原始图像添加一些内容(例如在您的问题中的可视化对象检测中发生的情况),以及如何仅将添加的项目提取到结果图像中。

    import numpy as np
    from PIL import Image
    from matplotlib import image
    import matplotlib.pyplot as plt
    
    image_np = np.array(Image.open('taulu_seinalla.jpg').convert('RGB'))
    
    #Let's simulate and add some detection info...
    image_np_with_detections=image_np.copy()
    
    for i in np.arange(1200,2700):
        image_np_with_detections[300:320,i,:]=[0,255,0]
        image_np_with_detections[1500:1520,i,:]=[0,255,0]
    
    for j in np.arange(300,1500):
        image_np_with_detections[j,1200:1220,:]=[0,255,0]
        image_np_with_detections[j,2700:2720,:]=[0,255,0]
    
    #And now let's create a "boxes leaved" version...
    image_difference=image_np_with_detections-image_np
    indexes_with_interesting_content=np.where(image_difference[:,:,:]>0)
    image_np_boxes_leaved=255*np.ones((len(image_np),len(image_np[0]),3))
    image_np_boxes_leaved[indexes_with_interesting_content]=image_np_with_detections[indexes_with_interesting_content]
    image_np_boxes_leaved=np.uint8(image_np_boxes_leaved)
    
    #And just for art...
    image_np_for_art=255*np.ones((len(image_np),len(image_np[0]),3))
    for i in [np.arange(1000,1100),np.arange(2000,2100)]:
        image_np_for_art[500:520,i,:]=[0,0,255]
    for i in np.arange(1000,2000):
        y_temp=-0.0005*(i-1500)**2+1500
        y_temp=np.uint(y_temp)
        image_np_for_art[y_temp:(y_temp+20),i,:]=[0,0,255]
    
    image_np_for_art=np.uint8(image_np_for_art)
    
    fig1,((ax1,ax2),(ax3,ax4))=plt.subplots(2,2)
    ax1.imshow(image_np)
    ax1.set_title('Original')
    ax2.imshow(image_np_with_detections)
    ax2.set_title('With detections')
    ax3.imshow(image_np_boxes_leaved)
    ax3.set_title('Boxes leaved')
    ax4.imshow(image_np_for_art)
    ax4.set_title('Smile!')
    
    plt.show()
    

    实际上它看起来像这样:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-27
      • 2010-11-15
      • 1970-01-01
      • 1970-01-01
      • 2022-01-08
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      相关资源
      最近更新 更多