当前位置:网站首页>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))
边栏推荐
- Development mode and Prospect of China's IT training industry strategic planning trend report Ⓣ 2022 ~ 2028
- Kali2021.4a build PWN environment
- Leetcode problem solving - 230 The k-th smallest element in the binary search tree
- Teach you how to install aidlux (1 installation)
- [dynamic programming] Jisuan Ke: Jumping stake (variant of the longest increasing subsequence)
- Base ring tree Cartesian tree
- Is the account opening of Guotai Junan Securities safe and reliable? How to open Guotai Junan Securities Account
- How to install sentinel console
- Ten minutes will take you in-depth understanding of multithreading. Multithreading on lock optimization (I)
- Tkinter Huarong Road 4x4 tutorial III
猜你喜欢
2 spark environment setup local
Buuctf, misc: sniffed traffic
2022 safety officer-a certificate registration examination and summary of safety officer-a certificate examination
Yyds dry inventory hcie security Day12: concept of supplementary package filtering and security policy
JS closure knowledge points essence
Farmersworld farmers world, no faith, how to talk about success?
Persistence of Nacos
[actual combat record] record the whole process of the server being attacked (redis vulnerability)
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)
[template summary] - binary search tree BST - Basics
随机推荐
What is the content of the securities practice examination?
Exness: the Central Bank of England will raise interest rates again in March, and inflation is coming
Go Technology Daily (2022-02-13) - Summary of experience in database storage selection
Ansible common usage scenarios
Data consistency between redis and database
Cognitive fallacy: what is dimensional curse
Rest参考
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)
Why should enterprises do more application activities?
LeetCode 1646. Get the maximum value in the generated array
gslb(global server load balance)技术的一点理解
China's TPMS industry demand forecast and future development trend analysis report Ⓐ 2022 ~ 2028
油猴插件
Luogu deep foundation part 1 Introduction to language Chapter 7 functions and structures
string
This time, thoroughly understand bidirectional data binding 01
China's Call Center Industry 14th five year plan direction and operation analysis report Ⓔ 2022 ~ 2028
Buuctf, misc: sniffed traffic
Functions and differences between static and Const
IPhone development swift foundation 09 assets