当前位置:网站首页>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))
边栏推荐
- China's coal industry investment strategic planning future production and marketing demand forecast report Ⓘ 2022 ~ 2028
- Report on the development status and investment planning trends of China's data center industry Ⓡ 2022 ~ 2028
- gslb(global server load balance)技术的一点理解
- 1068. Consolidation of ring stones (ring, interval DP)
- AST (Abstract Syntax Tree)
- Report on the current situation and development trend of ethoxylated sodium alkyl sulfate industry in the world and China Ⓞ 2022 ~ 2027
- Teach you how to run two or more MySQL databases at the same time in one system
- Cognitive fallacy: Wittgenstein's ruler
- 油猴插件
- What is the difference between res.send() and res.end() in the node express framework
猜你喜欢
What is the difference between res.send() and res.end() in the node express framework
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
[actual combat record] record the whole process of the server being attacked (redis vulnerability)
Mysql database - Advanced SQL statement (I)
4 environment construction -standalone ha
Team collaborative combat penetration tool CS artifact cobalt strike
Nacos common configuration
使用dnSpy對無源碼EXE或DLL進行反編譯並且修改
[SRS] build a specified version of SRS
UC Berkeley proposes a multitask framework slip
随机推荐
Development mode and Prospect of China's IT training industry strategic planning trend report Ⓣ 2022 ~ 2028
Development trend and market demand analysis report of China's energy storage battery industry Ⓩ 2022 ~ 2028
Summary of basic knowledge of exception handling
Common problems in multi-threaded learning (I) ArrayList under high concurrency and weird hasmap under concurrency
Data consistency between redis and database
What is the content of the securities practice examination?
Supply and demand situation and market scale calculation report of China's portable energy storage power PES industry Ⓛ 2022 ~ 2028
1068. Consolidation of ring stones (ring, interval DP)
What indicators should be paid attention to in current limit monitoring?
The White House held an open source security summit, attended by many technology giants
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
Asynchronous artifact: implementation principle and usage scenario of completable future
Cognitive fallacy: what is Fredkin's paradox
油猴插件
2022 G3 boiler water treatment registration examination and G3 boiler water treatment examination papers
Why use pycharm to run the use case successfully but cannot exit?
Team collaborative combat penetration tool CS artifact cobalt strike
[SRS] build a specified version of SRS
3 environment construction -standalone
Electronic tube: Literature Research on basic characteristics of 6j1