Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect bounding box positions in inference phase. #3

Open
gopikrishnabs opened this issue Apr 6, 2022 · 0 comments
Open

Incorrect bounding box positions in inference phase. #3

gopikrishnabs opened this issue Apr 6, 2022 · 0 comments

Comments

@gopikrishnabs
Copy link

cap = cv2.VideoCapture(output_video_path)
frame_width = int(cap.get(3))
frame_height = int(cap.get(4))

fps = FPS().start()
out = cv2.VideoWriter('./videos/output_video1.mp4', cv2.VideoWriter_fourcc('M','P','4','V'), 30, (frame_width,frame_height))

currentframe = 0
while (cap.isOpened() and currentframe<2000):
ret, image_np = cap.read()
if len((np.array(image_np)).shape) == 0:
break

input_tensor = np.expand_dims(image_np, 0)
#start_time = time.time()
detections = detect_fn(input_tensor)
#end_time = time.time()
#print(end_time - start_time)
#print(detections)

label_id_offset = 1
image_np_with_detections = image_np.copy()
#print(cv2.imwrite('./images/frame' + str(currentframe) + '.jpg',image_np_with_detections))
viz_utils.visualize_boxes_and_labels_on_image_array(
    image_np_with_detections,
    detections['detection_boxes'][0].numpy(),
    detections['detection_classes'][0].numpy().astype(np.int32),
    detections['detection_scores'][0].numpy(),
    category_index,
    use_normalized_coordinates=True,
    max_boxes_to_draw=1,
    min_score_thresh=.002,
    agnostic_mode=False)

# save image every n frames
if currentframe % 100 == 0:
    name = './images/frame' + str(currentframe) + '.jpg'
    cv2.imwrite(name, image_np_with_detections)

currentframe += 1
fps.update()
out.write(image_np_with_detections)

fps.stop()
print("[INFO] elasped time: {:.2f}".format(fps.elapsed()))
print("[INFO] approx. FPS: {:.2f}".format(fps.fps()))
cap.release()
out.release()

The above code is used for detecting objects and drawing bounding boxes but for some reason the bounding box is drawn on the top-left corner of the output frame. The output image looks like this.

frame90

The intended output image looks like this:

image

I trained the model for small epochs so I reduced the threshold values(0.01-0.40) as well as the number of boxes(from 200 to 1) to draw but finally thought there may be an issue with resizing the bounding box on the original image size.

Any help would be appreciated thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant