How do I get the pixel coordinates for a specific bounding box(如何获取特定边界框的像素坐标)
                            本文介绍了如何获取特定边界框的像素坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
                        
                        问题描述
我正在尝试从Person类获取边界框的像素坐标(标记为: Mcoco_Label_map.pbtxtitem {
  name: "/m/01g317"
  id: 1
  display_name: "person"
}
目前我正在通过将边界框和标签放到图像上
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=3,
          min_score_thresh=.30,
          agnostic_mode=False)
(所有代码都在While循环中)
但是当我打印出检测时,我得到了这么多归一化的坐标,我不知道如何将这些坐标排序到特殊的框中,例如。人员标签。那么,如何在检测中获取特定边界框的像素坐标?
StackOverflow新手入门,因此非常感谢您的任何提示。
推荐答案
sodetection_boxes应该是归一化坐标中[ymin, xmin, ymax, xmax]形式的N乘4边界框坐标数组,detection_classes应该是(`Float?)数字类标签。我假设他们没有太多更改API,因为我从去年年初开始就没有使用过对象检测API。
您应该能够这样做,将其转换为像素坐标,然后只获取一组标签。
detection_boxes = detections['detection_boxes'][0].numpy()
detection_classes = detections['detection_classes'][0].numpy().astype(int) + label_id_offset
detection_scores = detections['detection_scores'][0].numpy()
# Scale to pixel co-ordinates
detection_boxes[:, (0, 2)] *= IMAGE_HEIGHT
detection_boxes[:, (1, 3)] *= IMAGE_WIDTH
# Select person boxes
cond = (detection_classes == PERSON_CLASS_ID) & (detection_scores >= SCORE_THRESH)
person_boxes = detection_boxes[cond, :]
person_boxes = np.round(person_boxes).astype(int)
                        这篇关于如何获取特定边界框的像素坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
				 沃梦达教程
				
			本文标题为:如何获取特定边界框的像素坐标
				
        
 
            
        基础教程推荐
             猜你喜欢
        
	     - 求两个直方图的卷积 2022-01-01
 - PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
 - 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
 - 在Python中从Azure BLOB存储中读取文件 2022-01-01
 - 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
 - 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
 - 包装空间模型 2022-01-01
 - PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
 - 修改列表中的数据帧不起作用 2022-01-01
 - Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				