상세 컨텐츠

본문 제목

image data export code for Python

Tech

by Enjoy Something 2019. 9. 17. 13:16

본문

import csv

from projects.models import *


def get_on_off(img):
if img.image_type.title == '직접촬영':
OnOff = 'Y'
else:
OnOff = 'N'
return OnOff


def has_label(image_label):
if len(image_label) > 0:
return True
else:
return False


work_subs = ImageDataLabelingWorkSub.objects.all()



with open('letter_labeling3.csv', 'w', encoding='utf-8') as csvfile:
fieldnames = ['ImageID', 'LabelName', 'x', 'y', 'width', 'height', 'rotate', 'scaleX', 'scaleY', 'Text', 'category']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for w in work_subs:
data_work = w.data_work
category = w.labeling
image_work = data_work.image_work
path = image_work.path
ImageID = path
answers = w.answer
number_of_letters = len(answers)
print(number_of_letters, answers)
is_working_data = False
if number_of_letters != 0:
is_working_data = True
answers = answers.replace(" ", "")
if is_working_data:
i = 0
for a in answers:
LabelName = str(w.id) + '-' + str(i)
width = w.width
width = width / number_of_letters
x = w.x + width * i
y = w.y
height = w.height
rotate = w.rotate
scaleX = w.scaleX
scaleY = w.scaleY
Text = w.answer[i]
i += 1
print(
{
'ImageID': ImageID, 'LabelName': LabelName, 'x': x, 'y': y, 'width': width,
'height': height, 'rotate': rotate, 'scaleX': scaleX, 'scaleY': scaleY,
'Text': Text, 'category': category
})
writer.writerow(
{
'ImageID': ImageID, 'LabelName': LabelName, 'x': x, 'y': y, 'width': width,
'height': height, 'rotate': rotate, 'scaleX': scaleX, 'scaleY': scaleY,
'Text': Text, 'category': category
})

관련글 더보기

댓글 영역