34 lines
828 B
Python
34 lines
828 B
Python
|
|
import albumentations as a
|
||
|
|
import numpy as np
|
||
|
|
from os import listdir as ls
|
||
|
|
import cv2 as cv
|
||
|
|
from sys import argv, exit
|
||
|
|
|
||
|
|
if len(argv) != 2:
|
||
|
|
exit(1)
|
||
|
|
|
||
|
|
def b_c(b, s = (1920, 1080)):
|
||
|
|
return [
|
||
|
|
round(b[0] * s[0] - b[2] * s[0] / 2),
|
||
|
|
round(b[0] * s[0] + b[2] * s[0] / 2),
|
||
|
|
round(b[1] * s[1] - b[3] * s[1] / 2),
|
||
|
|
round(b[1] * s[1] + b[3] * s[1] / 2),
|
||
|
|
]
|
||
|
|
|
||
|
|
def sq(img, bbox):
|
||
|
|
for i in bbox:
|
||
|
|
b = b_c(i, s = (img.shape[1], img.shape[0]))
|
||
|
|
#print(b)
|
||
|
|
cv.rectangle(img, (b[0], b[2]), (b[1], b[3]), (255, 0, 0), 2)
|
||
|
|
|
||
|
|
img = cv.cvtColor(cv.imread(f"{argv[1]}.jpg"), cv.COLOR_BGR2RGB)
|
||
|
|
box = [tuple(map(float, j.split()[1:])) for j in open(f"{argv[1]}.txt").read().split("\n") if j]
|
||
|
|
|
||
|
|
box = np.array(box)
|
||
|
|
|
||
|
|
sq(img, box)
|
||
|
|
|
||
|
|
from matplotlib import pyplot as plt
|
||
|
|
plt.imshow(img)
|
||
|
|
plt.show()
|