这里的第一个问题。不是等待一个人,而是在如何解决它或阅读文档方面的一点指导
我正在学习Tensorflow,我正在使用实时相机对象检测的基本示例,并希望将输出输入到其他软件(GIS)中。
我是否可以更改来自camera.OR的最终图像,甚至关闭来自摄像头的图像,只留下方块和标签
这是绘制矩形的代码
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)))
Tensorflow models/research/object_detection/utils/visualization_utils.py中的visualize_boxes_and_labels_on_image_array函数
我的第一个猜测是将image_np_with_detections修改为空白图像,但它不起作用。我尝试直接修改可视化工具,但它生成了一个错误,因为使用图像来处理检测。
另一种选择是深入研究opencv文档
有什么线索吗?
提前感谢
发布于 2021-04-21 05:58:35
这里你看到了如何一步一步地向原始图像添加一些东西(就像你的问题中可视化中的对象检测一样),但是你如何将添加的项目只提取到结果图像中。
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()
在实践中,看起来似乎是这样的:
https://stackoverflow.com/questions/67180606
复制相似问题