Пример #1
0
from opencv.cvutils import *
from python_common.global_param import GlobalParam

#------------examples----------------#
'''
image read, modify, show and write functions
'''
input = cv.imread(GlobalParam.get_image_input(), cv.IMREAD_UNCHANGED)
output = resizeImage(input, 2, 1, 3)
output = reverse_color_image(input)
output = denoiseImage(input)
output = rotateImage(input, 20)
cv.imshow('12', output)
cv.waitKey(0)
cv.imwrite(GlobalParam.get_image_output(), output)
'''
combine two images
'''
input1 = cv.imread(GlobalParam.get_image_input(), cv.IMREAD_UNCHANGED)
input2 = cv.imread(GlobalParam.get_image_output(), cv.IMREAD_UNCHANGED)
output = resizeImage(combineTwoImages(input1, input2, 'portrait'), 1, 1, 2)
'''
write text in image
'''
# only can write ascii text
input = cv.imread(GlobalParam.get_sentence_output(), cv.IMREAD_UNCHANGED)
output = writeTextOnImageAscii(input, '12444', (20, 20),
                               cv.FONT_HERSHEY_SIMPLEX, 1, (209, 80, 0, 255),
                               3)

# write unicode text, like chinese, japanese...
Пример #2
0
import os

'''
clean characters images when characters folder isn't empty
'''
if len(os.listdir(GlobalParam.get_character_output())) > 0:
    for i in os.listdir(GlobalParam.get_character_output()):
        os.remove(GlobalParam.get_character_output() + i)

'''
get text area, and write to file
'''
input = cv.imread(GlobalParam.get_image_input(),cv.IMREAD_UNCHANGED)
# showAllContours(input,detectTextAreaFromImage(input), 10, 5)
input =findTextAreaContours(input,detectTextAreaFromImage(input),7,10,0,0,7,12)
cv.imwrite(GlobalParam.get_image_output(),input)


'''
split text area image to single character images, collect all images names and sort by names
'''
getLastWordsContour(GlobalParam.get_image_output(),
                    GlobalParam.get_character_output(), 50, 50,
                    GlobalParam.get_sentence_output())
char_image_list=[]
for i in os.listdir(GlobalParam.get_character_output()):
    char_image_list.append(int(i.replace('.png', '')))
char_length = len(char_image_list)
char_image_list.sort()

'''