Image comparison and Angle Estimation

697 Views Asked by At

I have a target object and a lot of other objects in an image. Target object is pre-defined with a known shape in advance as shown in figure.

Target image

My task is to detect all the target object present in the image and find the angle at which the detected object is oriented with respect to target object. For the object detection purpose I am using YOLO-V5-OBB model which gives me detection confidence and the rotated bounding box coordinates.See the result below

detected result

I would like to know how rotation angle is predicted by yolo-obb model in order to make rotated bounding boxes around the detected objects?

2

There are 2 best solutions below

1
andy wong On

I think you may try to use YOLOv5-OBB to train and get the coordinates of bounding box, and then it is easy to find the angle of orientation. Look at the detect.py.

  1. https://www.youtube.com/watch?v=iRkCNo9-slY
  2. https://github.com/hukaixuan19970627/yolov5_obb
# Write results
for *poly, conf, cls in reversed(det):
                    if save_txt:  # Write to file
                        # xywh = 
(xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist()  
# normalized xywh
0
YScharf On

For finding the object:

Before using heavy machine learning models, try using classic computer vision algorithms.

For finding the object: If the object above is the only object you will be searching for: Use cv2.HoughCircles().

https://docs.opencv.org/3.4/d4/d70/tutorial_hough_circle.html

If you want to be able to search arbitrary objects: Try using template matching.

https://pyimagesearch.com/2021/03/22/opencv-template-matching-cv2-matchtemplate/

After detecting the objects:

Apply Hough transform to extract the top line and detect the angle by using a line fitting algorithm.

OpenCV line-fitting (Might be deprecated)