Python Tensorflow对象检测:计算边界框和报警区域之间的距离
我正在使用CV2捕获视频,并在视频帧中定义感兴趣的区域Python Tensorflow对象检测:计算边界框和报警区域之间的距离,python,tensorflow,opencv,computer-vision,object-detection,Python,Tensorflow,Opencv,Computer Vision,Object Detection,我正在使用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, 0), thickness=2) 在定义了上述感兴趣的区域后,每当我的对象检测模型
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, 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, 0,0), 2)
playsound(r"C:\Project\alert.wav")
cv2.rectangle(image_np, (posii-20,20), (posii+85,60), (255,0,0), thickness=3, lineType=8, shift=0)
return 1
else:
return 0
if(从多边形到多边形的距离