方法1:def find_texthwnd area text left top right bottom = win32guiGetClientRecthwnd width = right - left height = bottom - top wDC = win32guiGetWindowDChwnd dcObj = win32uiCreateDCFromHan
为了成功调用方法2,你需要对方法1进行以下修改:
- 将方法1的代码放入一个函数中,例如命名为
def find_text_with_classification(hwnd, area, text):。 - 在方法1中,将截取的图像转换成bytes格式,可以使用PIL库中的
ImageToBytes函数。修改方法1的最后一行代码为return res。 - 在方法1中,调用方法2时,将图像的bytes作为参数传递给方法2。修改方法1的倒数第二行代码为
res = ocr.classification(image_bytes)。 - 在方法2中,将
img参数的类型从bytes改为PIL.Image.Image。 - 在方法2中,将第一行代码的
image = Image.open(io.BytesIO(img))改为image = img。
修改后的代码如下所示:
方法1:
def find_text_with_classification(hwnd, area, text):
# 截取图像代码...
# 将图像转换为bytes格式
image_bytes = ImageToBytes(im)
# 调用方法2
ocr = ddddocr.DdddOcr()
res = ocr.classification(image_bytes)
return res
方法2:
def classification(self, img: PIL.Image.Image):
image = img.resize((int(image.size[0] * (64 / image.size[1])), 64), Image.ANTIALIAS).convert('L')
# 其他代码...
这样,你就可以成功调用方法2了。
AI 优化版
原文地址:https://www.cveoy.top/t/topic/i12b 著作权归作者所有。请勿转载和采集!