728x90
반응형
file("gt_%d.txt") : GT bounding box 정보를 담고 있음, 각 polygon 좌표값은 tab('\t')으로 구분했다고 가정
[x1 y1 x2 y2 x3 y3 x4 y4 label]
import cv2;
import numpy as np
input_id = 1
# Reading polygon txt file
file = './gt_%d.txt'%input_id
f = open(file,'r')
lines = f.readlines()
# Reading Image
image_file = './images/0/%d.jpg'%input_id
image = cv2.imread(image_file)
# Draw
for line in lines:
polygon = line.split('\t')[:-1]
polygon = [int(point) for point in polygon]
points = []
for idx in range(0, len(polygon), 2):
points.append([polygon[idx], polygon[idx+1]])
points = np.array(points)
image = cv2.polylines(image, [points], True, (255,0,0),2)
# Save Image
cv2.imwrite('./after_poly_%d.jpg'%input_id, image)
728x90
반응형