当前位置:网站首页>Label coco format data and format data in the upper left corner and lower right corner are mutually converted
Label coco format data and format data in the upper left corner and lower right corner are mutually converted
2022-07-03 22:17:00 【Q742971636】
import cv2
class DataConvert():
""" The way of expression explain x1,y1,x2,y2 (x1,y1) Is the upper-left coordinate ,(x2,y2) Is the lower right coordinate x1,y1,w,h (x1,y1) Is the upper-left coordinate ,w Is the width of the target area ,h Is the height of the target area xc,yc,w,h (xc,yc) Is the central coordinate of the target area ,w Is the width of the target area ,h Is the height of the target area COCO mark """
def __init__(self):
pass
@staticmethod
def cvtx0y0whTox1y1x2y2(x0, y0, w, h, imgShape):
# "0.530921 0.666667 0.622368 0.666667"=>(167, 169, 639, 507)
# labelme Of COCO Dimension format is Center point x+ Center point y+ wide + high ( The normalized )
# The result of this function is Top left Lower right ( Not normalized )
height, width, c = imgShape
x1, y1, x2, y2 = int((x0 - w * 0.5) * width), \
int((y0 - h * 0.5) * height), \
int((x0 + w * 0.5) * width), \
int((y0 + h * 0.5) * height)
return x1, y1, x2, y2
@staticmethod
def cvtx1y1x2y2Tox0y0wh(x1, y1, x2, y2, imgShape):
# (167, 169, 639, 507)=>"0.530921 0.666667 0.622368 0.666667"
# Top left Lower right ( Not normalized ) => Center point x+ Center point y+ wide + high ( The normalized )
height, width, c = imgShape
x0, y0, w, h = (x1 + x2) / 2 / width, (y1 + y2) / 2 / height, (x2 - x1) / width, (y2 - y1) / height,
return x0, y0, w, h
if __name__ == '__main__':
img = cv2.imread("jg02387.jpg")
shape = img.shape
x1, y1, x2, y2 = DataConvert.cvtx0y0whTox1y1x2y2(0.530921, 0.666667, 0.622368, 0.666667, shape)
print(x1, y1, x2, y2)
print(DataConvert.cvtx1y1x2y2Tox0y0wh(x1, y1, x2, y2, shape))
边栏推荐
- Luogu deep foundation part 1 Introduction to language Chapter 7 functions and structures
- Awk getting started to proficient series - awk quick start
- How does sentinel, a traffic management artifact, make it easy for business parties to access?
- [Android reverse] application data directory (files data directory | lib application built-in so dynamic library directory | databases SQLite3 database directory | cache directory)
- [sg function] lightoj Partitioning Game
- What indicators should be paid attention to in current limit monitoring?
- Correlation
- 十大券商开户注册安全靠谱吗?有没有风险的?
- [secretly kill little partner pytorch20 days] - [day3] - [example of text data modeling process]
- Morning flowers and evening flowers
猜你喜欢

The latest analysis of crane driver (limited to bridge crane) in 2022 and the test questions and analysis of crane driver (limited to bridge crane)

On my first day at work, this API timeout optimization put me down!

1068. Consolidation of ring stones (ring, interval DP)

Decompile and modify the non source exe or DLL with dnspy

gslb(global server load balance)技術的一點理解

Code in keil5 -- use the code formatting tool astyle (plug-in)

2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions

Introduction to kubernetes

Some 5000+ likes, the development notes of a director of cosmic factory, leaked

Data consistency between redis and database
随机推荐
3 environment construction -standalone
Ansible common usage scenarios
Morning flowers and evening flowers
Blue Bridge Cup Guoxin Changtian MCU -- program download (III)
Electronic tube: Literature Research on basic characteristics of 6j1
Correlation
IPhone development swift foundation 09 assets
WFC900M-Network_ Card/Qualcomm-Atheros-AR9582-2T-2R-MIMO-802.11-N-900M-high-power-Mini-PCIe-Wi-Fi-Mod
国泰君安证券开户是安全可靠的么?怎么开国泰君安证券账户
Is it safe and reliable to open an account and register for stock speculation? Is there any risk?
(POJ - 2912) rochambau (weighted concurrent search + enumeration)
string
Redis concludes that the second pipeline publishes / subscribes to bloom filter redis as a database and caches RDB AOF redis configuration files
[sg function]split game (2020 Jiangxi university student programming competition)
1 Introduction to spark Foundation
Station B, dark horse programmer, employee management system, access conflict related (there is an unhandled exception at 0x00007ff633a4c54d (in employee management system.Exe): 0xc0000005: read locat
[golang] leetcode intermediate - alphabetic combination of island number and phone number
Development trend and market demand analysis report of China's energy storage battery industry Ⓩ 2022 ~ 2028
Covariance
[SRS] build a specified version of SRS