如何解决Tensorflow对象检测:计算边界框和警报区域之间的距离
我正在使用CV2捕获视频并在视频帧中定义感兴趣的区域
cap = cv2.VideoCapture(0)
image_np = cap.read()
pts = np.array([[57,69],[215,65],[270,476],[3,476]],np.int32)
cv2.polylines(image_np,[pts],isClosed = True,color=(255,0),thickness=2)
在定义了上述感兴趣的区域之后,每当我的对象检测模型检测到带有框的对象,并且一旦它进入定义的区域,我都需要发出警报。我该如何处理?以下是来自tensorflow反对回购的功能
def show_inference(model,image_path):
# the array based representation of the image will be used later in order to prepare the
# result image with boxes and labels on it.
image_np = np.array(Image.open(image_path))
# Actual detection.
output_dict = run_inference_for_single_image(model,image_np)
# Visualization of the results of a detection.
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,output_dict['detection_boxes'],output_dict['detection_classes'],output_dict['detection_scores'],category_index,instance_masks=output_dict.get('detection_masks_reframed',None),use_normalized_coordinates=True,line_thickness=8)
display(Image.fromarray(image_np))
我稍后将定义一个函数,该函数可以给我以下警告
if (distance_from_polygon <= 0) :
posii=int(image_np.shape[1]/2)
cv2.putText(image_np,"ALERT",(posii,50),cv2.FONT_HERSHEY_SIMPLEX,0.75,(255,2)
playsound(r"C:\Project\alert.wav")
cv2.rectangle(image_np,(posii-20,20),(posii+85,60),thickness=3,lineType=8,shift=0)
return 1
else:
return 0
如何获取distance_from_polygon
的值,即定义的区域与边界框之间的距离?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。