def worker(file): """thread worker function""" # time.sleep(0.5) print '\nWorker' + image scan_image(file) get_qr_code(file + "-result.png") # print image return
def index(): if request.method == 'POST': imageFile = request.files['imageFile'] imageFile.save(UPLOADED_FILE) scanned_image = scan_image(UPLOADED_FILE) scanned_image.save('scanned_images/scanned_image.png') return send_file('scanned_images/scanned_image.png') return render_template('index.html')
def ocr_scan_deal(self): #OCR识别 global image, img2 #cv2.imshow('image',image) img2 = scan.scan_image(image) img3 = cv2.cvtColor(img2, cv2.COLOR_GRAY2BGR) img4 = cv2.resize(img3, (image_height, image_width), interpolation=cv2.INTER_AREA) self.label2_image_show(img4) cv2.imwrite('ocr_scan.jpg', img3) text = pytesseract.image_to_string(Image.open('ocr_scan.jpg')) print(text) self.textEdit.setText(text) self.pushButton_3.setEnabled(True)
def scan_data(scanarium, data): with tempfile.TemporaryDirectory(prefix='scanarium-scan-data-') as dir: image_file = os.path.join(dir, 'image') with open(image_file, 'wb') as f: f.write(base64.standard_b64decode(data)) # Temporarily switching the image source to the new image for scanning scanarium.set_config('scan', 'source', f'image:{image_file}') # As we switched from the configured image source to the passed image, # the calibration data for the configured image source no longer fits, # and we drop it as it may otherwise distort colors/geometry. scanarium.set_config('scan', 'calibration_xml_file', '') scanarium.set_config('scan', 'max_brightness', '') return scan_image(scanarium)
def photo_to_dict(photo): scanned_text = scan.scan_image(photo) final_dict = {} amounts = extract.amounts_extraction(scanned_text) # dict final_dict.update(amounts) final_dict['mjesto_izdavanja'] = extract.postal_numbers( scanned_text) # string dates = extract.payment_dates(scanned_text) # dict final_dict.update(dates) # Na temelju oib-a se iz baze povlace podaci o korisniku i izdavacu racuna user_data, company_data = extract.oib_numbers(scanned_text) final_dict.update(user_data) company_data['iban_primatelja'] = extract.iban_numbers( scanned_text, company_data) del company_data['iban'] final_dict.update(company_data) return final_dict
# compute the new bounding dimensions of the image nW = int((h * sin) + (w * cos)) nH = int((h * cos) + (w * sin)) # adjust the rotation matrix to take into account translation M[0, 2] += (nW / 2) - cX M[1, 2] += (nH / 2) - cY # perform the actual rotation and return the image return cv2.warpAffine(image, M, (nW, nH)) if img.shape[1] < img.shape[0]: res = rotate_bound(img, 90) else: res = img scanned = scan.scan_image(img) #文本内容边框识别,变换处理,若需要则将下面第二行的img改为scanned #cv_show('scan',scanned) print(res.shape) print(img.shape) cv_show('res', res) cv_show('img', img) roi = res[0:int(res.shape[0] * 0.08), int(res.shape[1] * 0.7):res.shape[1]] #cv_show('roi',roi) ret, roi_binary = cv2.threshold(roi, 127, 255, cv2.THRESH_BINARY_INV) #翻转二值化处理 cv_show('roi_binary', roi_binary) number = pytesseract.image_to_string(roi_binary) print(number)