개정판 903dd7f5
issue #655: apply grid img before box
DTI_PID/DTI_PID/TrainingImageListDialog.py | ||
---|---|---|
244 | 244 |
totalHeight += maxLineH |
245 | 245 |
maxLineH = areaH ##sung |
246 | 246 |
totalHeight += maxLineH |
247 |
#print('total area real : ' + str(totalBaseWidth * totalHeight) +', total width : ' + str(totalBaseWidth) + ', total height : ' + str(totalHeight) + ', ratio : ' + str(totalHeight / totalBaseWidth)) |
|
247 |
totalSeedHeight = totalHeight |
|
248 |
#print('total area real : ' + str(totalBaseWidth * totalSeedHeight) +', total width : ' + str(totalBaseWidth) + ', total height : ' + str(totalHeight) + ', ratio : ' + str(totalHeight / totalBaseWidth)) |
|
248 | 249 |
|
249 |
trainingTextImg = Image.new("RGB", (totalBaseWidth, totalHeight), (256,256,256)) |
|
250 |
trainingTextImg = Image.new("RGB", (totalBaseWidth, totalSeedHeight), (256,256,256))
|
|
250 | 251 |
seedHeight, seedWidth = trainingTextImg.height, trainingTextImg.width |
251 | 252 |
maxLineH, lineW, totalHeight, currentX, currentY = 0, 0, 0, 0, 0 |
252 | 253 |
outBox = "" |
... | ... | |
292 | 293 |
|
293 | 294 |
trainingImgPath = os.path.join(project.getTrainingFilePath(), self.oCRLang + '.' + self.oCRLang + 'F.exp0.tif') |
294 | 295 |
trainingBoxPath = os.path.join(project.getTrainingFilePath(), self.oCRLang + '.' + self.oCRLang + 'F.exp0.box') |
295 |
trainingTextImg.save(trainingImgPath, compression='tiff_lzw') |
|
296 |
fw = open(trainingBoxPath, 'w', encoding='utf8') |
|
297 |
fw.write(outBox) |
|
298 |
fw.close() |
|
296 |
#trainingTextImg.save(trainingImgPath, compression='tiff_lzw') |
|
297 |
#fw = open(trainingBoxPath, 'w', encoding='utf8') |
|
298 |
#fw.write(outBox) |
|
299 |
#fw.close() |
|
300 |
|
|
301 |
# 1112 |
|
302 |
boxes = outBox.split('\n') |
|
303 |
boxes = boxes[:-1] |
|
304 |
maxBoxWidth, maxBoxHeight = 0, 0 |
|
305 |
for box in boxes: |
|
306 |
boxComponent = box.split(' ') |
|
307 |
boxWidth = abs(int(boxComponent[3]) - int(boxComponent[1])) |
|
308 |
boxHeight = abs(int(boxComponent[4]) - int(boxComponent[2])) |
|
309 |
if boxWidth > maxBoxWidth: |
|
310 |
maxBoxWidth = boxWidth |
|
311 |
if boxHeight > maxBoxHeight: |
|
312 |
maxBoxHeight = boxHeight |
|
313 |
maxBoxHeight += 2 |
|
314 |
|
|
315 |
countOfOneSide = math.ceil(math.sqrt(len(boxes))) |
|
316 |
totalGridWidth = maxBoxWidth * countOfOneSide |
|
317 |
totalGridHeight = maxBoxHeight * countOfOneSide |
|
318 |
trainingGridImg = Image.new("RGB", (totalGridWidth, totalGridHeight), (256,256,256)) |
|
319 |
|
|
320 |
boxCount = 0 |
|
321 |
for rowCount in range(countOfOneSide): |
|
322 |
for colCount in range(countOfOneSide): |
|
323 |
boxComponent = boxes[boxCount].split(' ') |
|
324 |
gridX = int(boxComponent[1]) |
|
325 |
gridY = totalSeedHeight - int(boxComponent[4]) |
|
326 |
gridW = abs(int(boxComponent[3]) - int(boxComponent[1])) |
|
327 |
gridH = abs(int(boxComponent[4]) - int(boxComponent[2])) |
|
328 |
gridBoxImg = trainingTextImg.crop((gridX, gridY, gridX + gridW, gridY + gridH)) |
|
329 |
trainingGridImg.paste(gridBoxImg, (colCount * maxBoxWidth, rowCount * maxBoxHeight, colCount * maxBoxWidth + gridW, rowCount * maxBoxHeight + gridH)) |
|
330 |
boxCount += 1 |
|
331 |
if boxCount == len(boxes): |
|
332 |
break |
|
333 |
rowCount += 1 |
|
334 |
if boxCount == len(boxes): |
|
335 |
break |
|
336 |
trainingGridImg.save(trainingImgPath, compression='tiff_lzw') |
|
337 |
# 1112 |
|
299 | 338 |
|
300 | 339 |
self.ui.labelProgress.setText('학습 이미지 파일을 생성했습니다.') |
301 | 340 |
QApplication.processEvents() |
내보내기 Unified diff