当前位置:网站首页>Rotating frame target detection -- about the definition and solution of rotating frame

Rotating frame target detection -- about the definition and solution of rotating frame

2022-06-22 00:53:00 qq_ forty-one million six hundred and twenty-seven thousand six

1、 The rotation box indicates

1、 How to represent a rotation box ?

 First , When the tag is generated , We will face a real problem ? How the rotation box should represent ? in fact , Although we said we could use 5 It's worth [ The formula ] To represent a rotating frame ( [ The formula ] ) In particular, it refers to the central position of the box , But notice that this box means that there is actually a bug: The representation of a box is not unique . So let's take this picture , When we take different sides as height and width , The calculated angle will also change ( By convention , We generally regard the angle of counterclockwise rotation as a negative value )
 Insert picture description here

2、Opencv notation

About different versions opencv Of cv2.minAreaRect Function output angle range is different .
Making a rotating rectangle ⽬ Encountered during calibration test ⼀ A question , What I do ⽤ The label of the dataset is the coordinates of the four points of the irregular quadrilateral (x1,y1,x2,y2,x3,y3,x4,y4), To convert it to rotation ⽬ Label detected (x,y,longside,shortside,angle). among , need ⽤ To opencv Medium cv2.minAreaRect function .
cv2.minAreaRect The operation of the function ⽤ Is the most important way to return an irregular quadrilateral ⼩ Outside rectangle ( Can I return the most ⼩ The circumscribed rectangle is not verified )
remarks :cv2.boxPoints The function can be based on cv2.minAreaRect The return value of the function gives the most ⼩ Four point coordinates of the circumscribed rectangle
In order to be more ⽅ I will go into ⾏ Visual description , Let's define two functions first draw_rect and rotate_rect

import numpy as np
import cv2
import matplotlib.pyplot as plt
defdraw_rect(rect):
 stay 
 Draw a rectangle on the canvas 
# 
im
rect
    im = np.zeros([240,320], dtype = np.uint8)
    cv2.polylines(im,[rect],1,255)
    plt.imshow(im)
    plt.show()
defrotate_rect(rect, angle):
 Output 
 Coordinates of four points of the rotated rectangle ,
 Positive and clockwise rotation , Negative and counterclockwise rotation 
# 
rect
angle
(x,y),(w,h),a = cv2.minAreaRect(rect)
    rect_r =((x,y),(w,h), a+angle)
return cv2.boxPoints(rect_r).astype(np.int32

About cv2.minAreaRect
transport ⼊: The four points of a quadrilateral ( Order is not required )
Output : most ⼩ Middle of circumscribed rectangle ⼼ Point coordinates x,y, wide ⾼w,h,⾓ degree anlge, The output form is tuple ((x,y),(w,h),anlge), The sequence format does not change
in ⼼ Point coordinates x,y⽐ It's easier to understand
wide w In the definition of 4.2 and 4.5 There's a difference , The exact version has not been determined

1、opencv4.2 edition (Doc)

OpenCV In version 4.5.1 Before , The expression is [ The formula ] , The schematic diagram is as follows
 Insert picture description here
** among 4.2 Version is defined as ,x The axis rotates counterclockwise and the first coincident edge is w, here x The shaft rotates counterclockwise ⾓ Degree is -angle( Minus sign yes )
Specifically explained as : Rotate rectangle rect There are two sides L and S( They are the long side and the short side ),x Counterclockwise rotation of shaft , If first with L Edge coincidence ( It can also be understood as ping ⾏), that L Namely

Opencv  format:   x_c         y_c        width       height      Θ

Parameter Introduction :

x_c And y_c: Rotate the center coordinates of the rectangle ;
width:x The axis rotates counterclockwise and touches the first edge of the rectangle ;
height: And width The opposite side ;
Θ:x The shaft rotates counterclockwise with width The angle between , Because the origin is in the upper left corner of the image , The counterclockwise rotation angle is negative ,Θ∈[-90, 0)
 Insert picture description here

2、opencv4.5 edition ((Doc’))

4.5 Version defined as ,x The axis rotates clockwise and the first coincident edge is w,angle by x The shaft rotates clockwise ⾓ degree ,angle The value is (0,90]
 Insert picture description here
 Insert picture description here

3、 Long side definition method 1(Dle)

 Insert picture description here

4、 Long side definition method 2((Dle’))

 Insert picture description here

5、 The conversion relationship between representations

Some understandings and thoughts about the definition of rotating frame
be based on MMRotate Training custom datasets Do rotating target detection 2022-3-30

 Insert picture description here
 Insert picture description here
 Insert picture description here
 Insert picture description here

原网站

版权声明
本文为[qq_ forty-one million six hundred and twenty-seven thousand six]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206212342190069.html