Closed mikumifa closed 2 months ago
提前用set_ranges设定可能得结果 也就是把测试提前,没有就重试,从而提高一次的成功率 这种方式是否可行
def calculate_key(ocr, det, pic_url: str) -> str: pic_img_bytes = download_img(pic_url) pic_img = Image.open(io.BytesIO(pic_img_bytes)) bg_img = pic_img.crop((0, 0, 344, 344)) text_img = pic_img.crop((0, 344, 150, 384)) text_img_bytes = io.BytesIO() text_img.save(text_img_bytes, format='PNG') ocr.set_ranges(7) target = ocr.classification(text_img_bytes.getvalue()) bg_img_bytes = io.BytesIO() bg_img.save(bg_img_bytes, format='PNG') bg_det = det.detection(bg_img_bytes.getvalue()) clicked_path = [None for i in range(len(target))] ocr.set_ranges(target) for row in bg_det: corp = bg_img.crop(row) img_byte = io.BytesIO() corp.save(img_byte, 'png') word = ocr.classification(img_byte.getvalue(), probability=True) s = "" for i in word['probability']: s += word['charsets'][i.index(max(i))] if s and s in target and clicked_path[target.index(s)] is None: clicked_path[target.index(s)] = row else: raise ValueError("error") res = [] for path in clicked_path: x1, y1, x2, y2 = path x = (x1 + x2) / 2 y = (y1 + y2) / 2 position = f"{round((x / 333.375) * 10000)}_{round((y / 333.375) * 10000)}" res.append(position) return ",".join(res)
复活
提前用set_ranges设定可能得结果 也就是把测试提前,没有就重试,从而提高一次的成功率 这种方式是否可行