개정판 d86f328a
Azure OCR에서 회전된 텍스트 제거 및 Scene Item으로 출력
DTI_PID/DTI_PID/DTI_PID.py | ||
---|---|---|
69 | 69 |
|
70 | 70 |
WHITE_LIST_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-" |
71 | 71 |
|
72 |
MIN_TEXT_SIZE = 10 |
|
72 | 73 |
#DB_NAME = "db/DTI_PID_test.db" |
73 | 74 |
#DB_NAME = AppDocData.instance().getCurrentProject().getPath() + "/db/" + "DTI_PID.db" |
74 | 75 |
#DB_NAME = os.path.dirname(os.path.realpath(__file__)) + "\\db\\DTI_PID.db" |
... | ... | |
107 | 108 |
roi = img[y:y+height, x:x+width] |
108 | 109 |
temp = roi.copy() |
109 | 110 |
tempBin = cv2.bitwise_not(temp) |
110 |
roi = cv2.bitwise_xor(roi, tempBin, roi)
|
|
111 |
roi = cv2.bitwise_xor(roi, tempBin) |
|
111 | 112 |
|
112 | 113 |
#Convert into Grayscale image |
113 | 114 |
def cvtGrayImage(img): |
... | ... | |
646 | 647 |
tw = tex - tsx |
647 | 648 |
th = tey - tsy |
648 | 649 |
|
649 |
MIN_TEXT_SIZE = 10
|
|
650 |
global MIN_TEXT_SIZE
|
|
650 | 651 |
if WHITE_LIST_CHARS.find(text) >= 0: |
651 | 652 |
if tw >= MIN_TEXT_SIZE or th >= MIN_TEXT_SIZE: |
652 | 653 |
realTextSp = (-1, -1) |
... | ... | |
695 | 696 |
canvas = np.zeros((height, width, 3), np.uint8) |
696 | 697 |
canvas[::] = (255, 255, 255) |
697 | 698 |
|
699 |
try: |
|
700 |
#pool = futures.ThreadPoolExecutor(max_workers = THREAD_MAX_WORKER) |
|
701 |
for symbol in searchedSymbolList: |
|
702 |
#pool.submit(drawFoundSymbols, symbol) |
|
703 |
drawFoundSymbols(symbol, listWidget) |
|
704 |
#pool.shutdown(wait = True) |
|
705 |
|
|
706 |
for text in textInfoList: |
|
707 |
if not checkTextInSymbol((text.getX(), text.getY())): |
|
708 |
cv2.putText(canvas, text.getText(), (text.getX(), text.getY()+text.getH()), 2, 1.0, (0, 0, 0)) |
|
709 |
|
|
710 |
srcName = os.path.splitext(os.path.basename(mainRes))[0] |
|
711 |
cv2.imwrite(os.path.dirname(os.path.realpath(__file__)) + '\\res\\Result\\result_moved_'+srcName+'_600dpi.png', canvas) |
|
698 | 712 |
|
699 |
#pool = futures.ThreadPoolExecutor(max_workers = THREAD_MAX_WORKER) |
|
700 |
for symbol in searchedSymbolList: |
|
701 |
#pool.submit(drawFoundSymbols, symbol) |
|
702 |
drawFoundSymbols(symbol, listWidget) |
|
703 |
#pool.shutdown(wait = True) |
|
704 |
|
|
705 |
for text in textInfoList: |
|
706 |
if not checkTextInSymbol((text.getX(), text.getY())): |
|
707 |
cv2.putText(canvas, text.getText(), (text.getX(), text.getY()+text.getH()), 2, 1.0, (0, 0, 0)) |
|
708 |
|
|
709 |
srcName = os.path.splitext(os.path.basename(mainRes))[0] |
|
710 |
cv2.imwrite(os.path.dirname(os.path.realpath(__file__)) + '\\res\\Result\\result_moved_'+srcName+'_600dpi.png', canvas) |
|
713 |
except Exception as ex: |
|
714 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
711 | 715 |
|
712 | 716 |
|
713 | 717 |
#def drawTempLine(sym): |
... | ... | |
800 | 804 |
srcGray = cvtGrayImage(src) |
801 | 805 |
else: |
802 | 806 |
srcGray = src.copy() |
803 |
|
|
804 |
(ocrCompletedSrc, textInfoList) = OCR.removeTextFromNpArray(srcGray) |
|
805 |
for textInfo in textInfoList: |
|
806 |
removeText(ocrCompletedSrc, textInfo.getText(), textInfo.getX(), textInfo.getY(), textInfo.getW(), textInfo.getH()) |
|
807 | 807 |
|
808 |
ocrCompletedSrc = srcGray.copy() |
|
809 |
|
|
808 | 810 |
area = AppDocData.instance().getArea('Drawing') |
809 | 811 |
if area is not None: |
810 | 812 |
area.img = srcGray[int(area.y):int(area.y+area.height), int(area.x):int(area.x+area.width)] |
813 |
|
|
814 |
(_tempOcrSrc, textInfoList) = OCR.removeTextFromNpArray(area.img if area is not None else srcGray, area.x if area is not None else 0, area.y if area is not None else 0) |
|
815 |
|
|
816 |
global MIN_TEXT_SIZE |
|
817 |
for textInfo in textInfoList: |
|
818 |
if textInfo.getW() >= MIN_TEXT_SIZE or textInfo.getH() >= MIN_TEXT_SIZE: |
|
819 |
removeText(ocrCompletedSrc, textInfo.getText(), textInfo.getX(), textInfo.getY(), textInfo.getW(), textInfo.getH()) |
|
811 | 820 |
except Exception as ex: |
812 | 821 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
813 | 822 |
|
... | ... | |
874 | 883 |
#threadLock.release() |
875 | 884 |
pool.shutdown(wait = True) |
876 | 885 |
|
877 |
(srcGray, tInfoList) = OCR.removeTextFromNpArray(srcGray) |
|
886 |
area = AppDocData.instance().getArea('Drawing') |
|
887 |
(_tempOcrSrc, tInfoList) = OCR.removeTextFromNpArray(area.img if area is not None else srcGray, area.x if area is not None else 0, area.y if area is not None else 0) |
|
888 |
#(srcGray, tInfoList) = OCR.removeTextFromNpArray(area.img if area is not None else srcGray) |
|
889 |
if area is not None: |
|
890 |
srcGray[int(area.y):int(area.y+area.height), int(area.x):int(area.x+area.width)] = _tempOcrSrc |
|
891 |
else: |
|
892 |
srcGray = _tempOcrSrc |
|
878 | 893 |
#srcGray = TOCR.removeTextFromNpArray(srcGray, TOCR.FLAG_IMAGE_TO_DATA) |
879 |
|
|
894 |
global MIN_TEXT_SIZE |
|
880 | 895 |
for textInfo in textInfoList: |
881 | 896 |
#if not checkTextInSymbol((textInfo.getX(), textInfo.getY())): |
882 |
removeText(srcGray, textInfo.getText(), textInfo.getX(), textInfo.getY(), textInfo.getW(), textInfo.getH()) |
|
897 |
if textInfo.getW() >= MIN_TEXT_SIZE or textInfo.getH() >= MIN_TEXT_SIZE: |
|
898 |
removeText(srcGray, textInfo.getText(), textInfo.getX(), textInfo.getY(), textInfo.getW(), textInfo.getH()) |
|
883 | 899 |
|
884 | 900 |
## Remove Noise |
885 | 901 |
kernel1 = np.ones((2, 2), np.uint8) |
내보내기 Unified diff