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...
driver = init_driver('edge', GlobalParam.get_edge_driver_path()) open_browser_single_tab(driver, 'https://www.12306.cn/index/') # wait dom return complete state wait_for_page_full_loaded(driver) loading_element = find_element_by_xpath(driver, '//div[@id="page-loading"]') wait_for_element_disappeared(driver, loading_element) try: wait_for_element_to_be_clickable(driver, '//a[text()="登录"]') wait_for_page_full_loaded(driver) wait_for_element_to_be_clickable(driver, '//a[text()="账号登录"]') # get captcha picture img_text = find_element_by_xpath(driver, '//img[@id="J-loginImg"]').get_attribute( 'src')[len('data:image/jpg;base64,'):] write_binary_to_file(GlobalParam.get_image_input(), img_text) find_element_by_xpath(driver, '//input[@id="J-userName"]').send_keys('username') find_element_by_xpath(driver, '//input[@id="J-password"]').send_keys('password') # find_element_by_xpath(driver, "//a[text()='立即登录']").click() except (NoAlertPresentException, TimeoutException) as py_ex: print("Alert not present") print(py_ex) print(py_ex.args)
from opencv.cvutils import * from python_common.global_param import GlobalParam 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)