개정판 3f8fe436
build issue #655: with short path
DTI_PID/DTI_PID/TrainingImageListDialog.py | ||
---|---|---|
1 | 1 |
import sys |
2 |
import os, time, subprocess |
|
2 |
import os, time, subprocess, ctypes |
|
3 |
from ctypes import wintypes |
|
4 |
_GetShortPathNameW = ctypes.windll.kernel32.GetShortPathNameW |
|
5 |
_GetShortPathNameW.argtypes = [wintypes.LPCWSTR, wintypes.LPWSTR, wintypes.DWORD] |
|
6 |
_GetShortPathNameW.restype = wintypes.DWORD |
|
3 | 7 |
from PyQt5.QtCore import * |
4 | 8 |
from PyQt5.QtGui import * |
5 | 9 |
from PyQt5.QtWidgets import * |
... | ... | |
278 | 282 |
|
279 | 283 |
try: |
280 | 284 |
# 1111111111111111111111111111111 |
281 |
#trainCmd = tesseract_cmd + ' ' + trainingImgPath + ' ' + trainingBoxPath.replace('.box', '') + ' nobatch box.train' + ' >> output.log' |
|
282 |
trainCmd = '\"' + tesseract_cmd + '\" ' + trainingImgPath + ' ' + trainingBoxPath.replace('.box', '') + ' nobatch box.train &timeout 15' |
|
285 |
trainingImgPath = self.get_short_path_name(trainingImgPath) |
|
286 |
trainingBoxPathT = self.get_short_path_name(trainingBoxPath.replace('.box', '')) |
|
287 |
trainCmd = '\"' + tesseract_cmd + '\" ' + trainingImgPath + ' ' + trainingBoxPathT + ' nobatch box.train &timeout 15' |
|
288 |
#trainCmd = '\"' + tesseract_cmd + '\" ' + trainingImgPath + ' ' + trainingBoxPath.replace('.box', '') + ' nobatch box.train &timeout 15' |
|
283 | 289 |
#trainCmd = '\"' + tesseract_cmd + '\"' + ' \"' + trainingImgPath + '\" \"' + trainingBoxPath.replace('.box', '') + '\" nobatch box.train' + ' &timeout 15' |
284 | 290 |
print(trainCmd) |
285 | 291 |
#subprocess.call(trainCmd, shell = True) |
286 | 292 |
os.system(trainCmd) |
287 | 293 |
|
288 | 294 |
# 222222222222222222222222222222 |
289 |
#unicharsetExtractorCmd = unicharset_extractor_cmd + ' ' + trainingBoxPath + " >> output.log" |
|
290 |
unicharsetExtractorCmd = '\"' + unicharset_extractor_cmd + '\"' + ' ' + trainingBoxPath + ' &timeout 15' |
|
295 |
trainingBoxPathU = self.get_short_path_name(trainingBoxPath) |
|
296 |
unicharsetExtractorCmd = '\"' + unicharset_extractor_cmd + '\"' + ' ' + trainingBoxPathU + ' &timeout 15' |
|
297 |
#unicharsetExtractorCmd = '\"' + unicharset_extractor_cmd + '\"' + ' ' + trainingBoxPath + ' &timeout 15' |
|
291 | 298 |
#unicharsetExtractorCmd = '\"' + unicharset_extractor_cmd + '\"' + ' \"' + trainingBoxPath + '\" &timeout 15' |
292 | 299 |
print(unicharsetExtractorCmd) |
293 | 300 |
##subprocess.call(unicharsetExtractorCmd, shell = True) |
... | ... | |
296 | 303 |
|
297 | 304 |
# 3333333333333333333333333333333 |
298 | 305 |
inputUnicharset = os.path.join(runningPath, 'unicharset') |
299 |
#outputUnicharset = os.path.join(project.getTrainingFilePath(), 'unicharset')
|
|
306 |
inputUnicharset = self.get_short_path_name(inputUnicharset)
|
|
300 | 307 |
scriptPath = ' --script_dir=//langdata-master' |
301 | 308 |
setUnicharsetPropertiesCmd = '\"' + set_unicharset_properties_cmd + '\" -U ' + inputUnicharset + ' -O ' + inputUnicharset + scriptPath + ' &timeout 15' |
302 | 309 |
#setUnicharsetPropertiesCmd = '\"' + set_unicharset_properties_cmd + '\" -U \"' + inputUnicharset + '\" -O \"' + inputUnicharset + '\"' + scriptPath + ' &timeout 15' |
... | ... | |
312 | 319 |
|
313 | 320 |
# 5555555555555555555555555555555 |
314 | 321 |
trPath = os.path.join(project.getTrainingFilePath(), oCRLang + '.' + oCRLang + 'F.exp0.tr') |
322 |
trPath = self.get_short_path_name(trPath) |
|
323 |
fontProperty = self.get_short_path_name(fontProperty) |
|
315 | 324 |
shapeclusteringCmd = '\"' + shapeclustering_cmd + '\" -F ' + fontProperty + ' -U ' + inputUnicharset + ' ' + trPath + ' &timeout 15' |
316 | 325 |
#shapeclusteringCmd = '\"' + shapeclustering_cmd + '\" -F \"' + fontProperty + '\" -U \"' + inputUnicharset + '\" \"' + trPath + '\" &timeout 15' |
317 | 326 |
##subprocess.call(shapeclusteringCmd, shell = True) |
... | ... | |
443 | 452 |
''' |
444 | 453 |
def listCellDoubleClicked(self, row, col): |
445 | 454 |
self.pushButtonBoxClicked() |
455 |
|
|
456 |
def get_short_path_name(self, long_name): |
|
457 |
""" |
|
458 |
Gets the short path name of a given long path. |
|
459 |
http://stackoverflow.com/a/23598461/200291 |
|
460 |
""" |
|
461 |
output_buf_size = 0 |
|
462 |
while True: |
|
463 |
output_buf = ctypes.create_unicode_buffer(output_buf_size) |
|
464 |
needed = _GetShortPathNameW(long_name, output_buf, output_buf_size) |
|
465 |
if output_buf_size >= needed: |
|
466 |
return output_buf.value |
|
467 |
else: |
|
468 |
output_buf_size = needed |
|
446 | 469 |
|
447 | 470 |
|
448 | 471 |
|
내보내기 Unified diff