如何使用张量流对象检测检查是否存在边界框
how to check if there is a boundng box using tensorflow object detection
我正在为小型无人机编写程序。我正在计算每一帧平台的距离和坐标。无人机根据边界框的坐标顺时针或逆时针旋转,直到边界框居中。
maxBoxes=1 #max boxes to draw
vis_util.visualize_boxes_and_labels_on_image_array(
image,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
max_boxes_to_draw=maxBoxes,
min_score_thresh=0.5,
use_normalized_coordinates=True,
line_thickness=4)
#if here, to check whether there is a detected object and then calculate
ymin = int((boxes[0][0][0]*imageHeight))
xmin = int((boxes[0][0][1]*imageWidth))
ymax = int((boxes[0][0][2]*imageHeight))
xmax = int((boxes[0][0][3]*imageWidth))
boxWidth=xmax-xmin
boxHeight=ymax-ymax
#Distance calculation
distance=round(W*F/boxWidth,2) #distance from the object
我的问题是如何检查给定帧是否有检测到的物体(边界框),因为有时它无法找到物体但仍然在随机方向上旋转。
所以,通过github查看源代码后,我已经能够弄明白了。方法是检查第一个分数是否低于阈值,就像我下面的例子。
maxBoxes=1 #max boxes to draw
minScoreThreshold=0.5 #minimum score threshold
vis_util.visualize_boxes_and_labels_on_image_array(
image,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
max_boxes_to_draw=maxBoxes,
min_score_thresh=minScoreThreshold,
use_normalized_coordinates=True,
line_thickness=4)
#if here, to check whether there is a detected object and then calculate
if (scores[0]<minScoreThreshold).all():
print("Nothing has been detected")
else:
print("Object has been detected. Continuing with calculations")
ymin = int((boxes[0][0][0]*imageHeight))
xmin = int((boxes[0][0][1]*imageWidth))
ymax = int((boxes[0][0][2]*imageHeight))
xmax = int((boxes[0][0][3]*imageWidth))
boxWidth=xmax-xmin
boxHeight=ymax-ymax
#Distance calculation
distance=round(W*F/boxWidth,2) #distance from the object
我正在为小型无人机编写程序。我正在计算每一帧平台的距离和坐标。无人机根据边界框的坐标顺时针或逆时针旋转,直到边界框居中。
maxBoxes=1 #max boxes to draw
vis_util.visualize_boxes_and_labels_on_image_array(
image,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
max_boxes_to_draw=maxBoxes,
min_score_thresh=0.5,
use_normalized_coordinates=True,
line_thickness=4)
#if here, to check whether there is a detected object and then calculate
ymin = int((boxes[0][0][0]*imageHeight))
xmin = int((boxes[0][0][1]*imageWidth))
ymax = int((boxes[0][0][2]*imageHeight))
xmax = int((boxes[0][0][3]*imageWidth))
boxWidth=xmax-xmin
boxHeight=ymax-ymax
#Distance calculation
distance=round(W*F/boxWidth,2) #distance from the object
我的问题是如何检查给定帧是否有检测到的物体(边界框),因为有时它无法找到物体但仍然在随机方向上旋转。
所以,通过github查看源代码后,我已经能够弄明白了。方法是检查第一个分数是否低于阈值,就像我下面的例子。
maxBoxes=1 #max boxes to draw
minScoreThreshold=0.5 #minimum score threshold
vis_util.visualize_boxes_and_labels_on_image_array(
image,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
max_boxes_to_draw=maxBoxes,
min_score_thresh=minScoreThreshold,
use_normalized_coordinates=True,
line_thickness=4)
#if here, to check whether there is a detected object and then calculate
if (scores[0]<minScoreThreshold).all():
print("Nothing has been detected")
else:
print("Object has been detected. Continuing with calculations")
ymin = int((boxes[0][0][0]*imageHeight))
xmin = int((boxes[0][0][1]*imageWidth))
ymax = int((boxes[0][0][2]*imageHeight))
xmax = int((boxes[0][0][3]*imageWidth))
boxWidth=xmax-xmin
boxHeight=ymax-ymax
#Distance calculation
distance=round(W*F/boxWidth,2) #distance from the object