feat: 更新 README,优化 OCR 识别逻辑,调整高价值房间和预约数据结构

This commit is contained in:
Your Name committed 2025-12-15 20:43:00 +08:00
1 parent ea8d221543
commit 5bbf59f13f
5 files changed
+329 -302

No files matched your search

+55
View File
@@ -392,6 +392,61 @@ class underlying_operations:
return text
def analyse_pic_word_fast(self, picname='', change_color=0, max_side=600):
"""更快的 OCR 路径:对裁剪图像做轻量化预处理并只执行一次 OCR(不做放大重试),用于对小区域的快速判定。
参数:
picname: 图片在 pic/ 中的文件名(不含后缀),空串表示默认 cut.png
change_color: 同 `analyse_pic_word` 的二值化模式(0=不二值化,1/2=两种二值化)
max_side: 若图片任一边超过该值,则按比例缩小到该尺寸,减少 OCR 计算量
返回: 识别到的文本(字符串)或空串
"""
self._ensure_ocr()
path = os.path.dirname(__file__) + '/pic'
if picname == '':
img_path = path + '/cut.png'
else:
img_path = path + '/' + picname + '.png'
try:
img = Image.open(img_path)
except Exception:
return ''
# 轻量化预处理:灰度/二值化 (若指定)
try:
if change_color in (1, 2):
img = img.convert('L')
if change_color == 1:
img = img.point(lambda x: 0 if x < 128 else 255)
else:
img = img.point(lambda x: 0 if x < 180 else 255)
img = img.convert('RGB')
else:
img = img.convert('RGB')
except Exception:
img = img.convert('RGB')
# 若图片较大,按比例缩小到 max_side,减小 OCR 负担
try:
w, h = img.size
m = max(w, h)
if max_side and m > max_side:
scale = max_side / float(m)
nw = max(1, int(w * scale))
nh = max(1, int(h * scale))
img = img.resize((nw, nh), Image.BILINEAR)
except Exception:
pass
try:
img_np = np.array(img.filter(ImageFilter.SHARPEN))
result = self.ocr.ocr(img_np)
if result == [None]:
return ''
return self.extract_ocr_content(result)
except Exception:
return ''
def extract_ocr_content(self, content=[]):
"""对OCR识别到的内容进行取值和拼接,变成完整的一段内容"""
ocr_result = content