Python Tensorflow对象检测:如何计算边框和帧中指定区域之间的距离

Python Tensorflow对象检测:如何计算边框和帧中指定区域之间的距离,python,python-3.x,tensorflow,opencv,tensorflow-datasets,Python,Python 3.x,Tensorflow,Opencv,Tensorflow Datasets,我正在使用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) 在定义了上述感兴趣的区域后,每当我的对象检测模型

我正在使用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)
在定义了上述感兴趣的区域后,每当我的对象检测模型检测到带有方框的对象时,一旦它进入定义的区域,我需要发出警报。我怎么能接受这个? 下面是tensorflow对象检测的函数

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

您的
factorial
return
缩进过度,因此当
n
0
时,不会返回任何内容。您的C代码也是错误的,对
i=n1
使用了
“条件”,即使它是
i==n1
,它仍然是错误的,因此在Python中仍然是错误的。这两块代码都不起作用


还要注意:在将简单的C
for
整数循环转换为Python时,在
范围内使用Python
for
循环,不要将其作为Python
while
循环来实现。

您的Python阶乘函数的
return
语句在
while
循环中,我认为这不是有意的。如果该循环不执行,则该函数将永远不会返回任何有效值——它只返回“代码> No.< /代码>作为一个旁注,请考虑在C中不使用嵌套函数(定义),除非您不想使代码具有可移植性。嵌套函数不是标准的C。您忘记问这个问题了