diff --git a/photo_review/photo_review.py b/photo_review/photo_review.py index 215152f..58c2ad1 100644 --- a/photo_review/photo_review.py +++ b/photo_review/photo_review.py @@ -74,9 +74,11 @@ def information_extraction(ie, phrecs, identity): img_path = ufile.get_private_url(phrec.cfjaddress) if not img_path: continue + image = image_util.read(img_path) angles = image_util.parse_rotation_angles(image) - angle_count = defaultdict(int, {"0": 0}) + angle_count = defaultdict(int, {"0": 0}) # 分割后图片的最优角度统计 + zx_ie_results = [] split_results = image_util.split(image) for split_result in split_results: rotated_img = image_util.rotate(split_result["img"], int(angles[0])) @@ -88,17 +90,18 @@ def information_extraction(ie, phrecs, identity): now = util.get_default_datetime() best_angle = ["0", 0] for ie_result in ie_results: + if not ie_result["result"]: + continue + result_json = json.dumps(ie_result["result"], ensure_ascii=False) if len(result_json) > 5000: result_json = result_json[:5000] - session = MysqlSession() - zx_ocr = ZxIeResult(pk_phhd=phrec.pk_phhd, pk_phrec=phrec.pk_phrec, id=identity, - cfjaddress=phrec.cfjaddress, content=result_json, rotation_angle=ie_result["angle"], - x_offset=split_result["x_offset"], y_offset=split_result["y_offset"], - create_time=now, creator=HOSTNAME, update_time=now, updater=HOSTNAME) - session.add(zx_ocr) - session.commit() - session.close() + zx_ie_results.append(ZxIeResult(pk_phhd=phrec.pk_phhd, pk_phrec=phrec.pk_phrec, id=identity, + cfjaddress=phrec.cfjaddress, content=result_json, + rotation_angle=int(ie_result["angle"]), + x_offset=split_result["x_offset"], + y_offset=split_result["y_offset"], create_time=now, creator=HOSTNAME, + update_time=now, updater=HOSTNAME)) result = merge_result(result, ie_result["result"]) @@ -114,11 +117,19 @@ def information_extraction(ie, phrecs, identity): cv2.imwrite(temp_file.name, image) try: ufile.upload_file(phrec.cfjaddress, temp_file.name) + # 修正旋转角度 + for zx_ie_result in zx_ie_results: + zx_ie_result.rotation_angle -= int(img_angle) except Exception as e: logging.error(f"上传图片({phrec.cfjaddress})失败", exc_info=e) finally: util.delete_temp_file(temp_file.name) + session = MysqlSession() + session.add_all(zx_ie_results) + session.commit() + session.close() + return result