hukaixuan19970627 / DOTA_devkit_YOLO

Trans DOTA OBB format(poly format) to YOLO format.
195 stars 39 forks source link

Parallelogram occurs from some inclined rectangle. #2

Closed XiaoXiLe2023 closed 2 years ago

XiaoXiLe2023 commented 3 years ago

QQ截图20210520171436 QQ截图20210520172256

Thanks for your precious work! 不愧是成电大佬。 I got the problem as the picture shows, some inclined rectangle have been translated into parallelograms while I am sure about my opencv, pillow and numpy version. I tried it both on Windows 10 and CentOS 7.5 but both didn't work perfectly.

Could you please help QAQ?

hukaixuan19970627 commented 3 years ago

确实有这个问题,不过我暂时也不清楚如何解决。 我先是利用cv2.minAreaRect()函数将 [x1 y1 x2 y2 x3 y3 x4 y4 ] 任意四边形的格式转为最小外接矩形 [x y w h θ] 格式,再接着转为[x y longside shortside θ] 长边表示法。 为了验证格式转换正确,绘制YOLO格式的旋转矩形框时,会将[x y longside shortside θ]格式转回[x y w h θ]格式,再利用cv2.boxPoints()函数返回最小外接旋转矩形的四个点,并绘制出来。 中间过程坐标数据可能会产生些许变化,由于大部分代码我都是调用的cv库,所以暂时也不知道是哪一个步骤出了问题; 但detect的结果图却显示正常(detect的可视化就是将长边表示法转为opencv表示法,再求得四点坐标进行绘制),所以问题可能发生在cv2.minAreaRect()这个函数中。 可能的解决办法就是改变opencv的版本吧,但是opencv升级的话又可能带来新的问题(θ的定义范围改变),我嫌麻烦就没改,因为根据我自己的测试结果来看,这点差异在DOTA数据集上没有多大影响

XiaoXiLe2023 commented 3 years ago

确实有这个问题,不过我暂时也不清楚如何解决。 我先是利用cv2.minAreaRect()函数将 [x1 y1 x2 y2 x3 y3 x4 y4 ] 任意四边形的格式转为最小外接矩形 [x y w h θ] 格式,再接着转为[x y longside shortside θ] 长边表示法。 为了验证格式转换正确,绘制YOLO格式的旋转矩形框时,会将[x y longside shortside θ]格式转回[x y w h θ]格式,再利用cv2.boxPoints()函数返回最小外接旋转矩形的四个点,并绘制出来。 中间过程坐标数据可能会产生些许变化,由于大部分代码我都是调用的cv库,所以暂时也不知道是哪一个步骤出了问题; 但detect的结果图却显示正常(detect的可视化就是将长边表示法转为opencv表示法,再求得四点坐标进行绘制),所以问题可能发生在cv2.minAreaRect()这个函数中。 可能的解决办法就是改变opencv的版本吧,但是opencv升级的话又可能带来新的问题(θ的定义范围改变),我嫌麻烦就没改,因为根据我自己的测试结果来看,这点差异在DOTA数据集上没有多大影响

感谢回复。 Before you put x1 y1 x2 y2 x3 y3 x4 y4 into cv2.minAreaRect(), you did NORMALIZATION with them. I haven't met the operation before neither seen it in any instance online. Maybe errors came from this. I'll try to train first and see what will happend. Thanks.

hukaixuan19970627 commented 3 years ago

https://zhuanlan.zhihu.com/p/385701722 可以试试这个

hukaixuan19970627 commented 2 years ago

https://github.com/hukaixuan19970627/yolov5_obb 我更新了一版代码,重构了一遍yolo预处理的逻辑,这个问题以后不会再出现了。 不过DOTA_devkit_YOLO这个repo也就没啥用了,poly与rbox之间的转换由内部代码自动完成