在实时摄像机对象检测中,如何关闭摄像机并离开盒子

2024-04-29 01:44:41 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我正在学习Tensorflow,我正在使用实时摄像机objet检测的基本示例,并希望在其他软件(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_box_和_labels_on_image_数组是Tensorflow models/research/object_detection/utils/visualize_utils.py的一部分

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

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

有线索吗

提前谢谢


Tags: 文档图像imagenumpyinputtftensorflowwith
1条回答
网友
1楼 · 发布于 2024-04-29 01:44:41

在这里,您将看到如何一步一步地向原始图像中添加内容(如您的问题中的可视化中的对象检测),但如何仅将添加的项目提取到结果图像中

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()

在实践中,它看起来是这样的:

enter image description here

相关问题 更多 >