0

I am writing a program for a small drone. I am calculating the distance and the coordinates of a platform at each frame. With the coordinates of the bounding box the drone rotates clockwise or counter clockwise until the bounding box is centered.

                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

My question is how to check if there is a detected object (a bounding box) at a given frame, because sometimes it is unable to find the object but still rotates on random directions.

1 Answer 1

2

So, after looking to the source code through github, i have been able to figure it out. The way to do it is by checking if the first score is lower than the threshold, like my example below.

            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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.