tensorflow / tensorflow/models

Object Detection API : bounding Boxes only in specified region of frame

Open
#9,444 1 comment 0 reactions 3 assignees View on GitHub

@pkulzc is already working on this.

Since Nov 5, 2020.

models:research:odapi stat:awaiting model gardener type:support
Dominant language
Python
Stars
77.7k
Forks
44.8k
PR merge metrics
No merged PRs in 30d

Description

I am using TensorFlow Object Detection API for custom object detection. I have trained my model on custom object detection using RetinaNet Model Zoo, and the result are really good.

Now I want to define a region in my input frame, i,e only in this defined region my object detection should be working. The object detected outside the region of interest should be ignored.

import cv2
cap = cv2.VideoCapture('video.mp4') 

def run_inference(model, cap):
    while cap.isOpened():
        ret, image_np = cap.read()
        # Actual detection.
        output_dict = run_inference_for_single_image(model, image_np)
        # Visualization of the results of 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)
        cv2.imshow('object_detection', cv2.resize(image_np, (800, 600)))
        if cv2.waitKey(1) & 0xFF == ord('q'):
            cap.release()
            cv2.destroyAllWindows()
            break

run_inference(detection_model, cap)

I have tried using cv2 function polylines to define lines on my input frames.

cv2.polylines(image, [pts], isClosed, color, thickness)

but couldn't activate object detection API to work only in the specified region

Expected Final Output: In the incoming input video frame It should a polygon box representing as Region of Interest(ROI) and whenever objected is detected inside the ROI it should give me bounding boxes (outside this ROI, it can neglect)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.