shitushili=PaddleOCR() def shituf(self,loadjietu,leirong,x,y,x1,y1): suzu=np.array(loadjietu) cvshuju=cv2.cvtColor(suzu,cv2.COLOR_RGB2BGR) fanwei=cvshuju[y:y1,x:x1] shibies=self.shitushili.ocr(fanwei) for liang in shibies: for end in liang: over=end[1] if over[0]!=None: return over[0] 修改返回识别内容和坐标
时间: 2024-02-14 12:13:21 浏览: 23
好的,你的问题是如何修改这段代码,使它可以返回识别内容和坐标。那么我可以给你一些修改的建议。
首先,在函数定义处添加两个参数,用于返回识别内容和坐标:
```
def shituf(self,loadjietu,leirong,x,y,x1,y1):
suzu=np.array(loadjietu)
cvshuju=cv2.cvtColor(suzu,cv2.COLOR_RGB2BGR)
fanwei=cvshuju[y:y1,x:x1]
shibies=self.shitushili.ocr(fanwei)
for liang in shibies:
for end in liang:
over=end[1]
if over[0]!=None:
return over[0], (x+over[1][0], y+over[1][1])
return None, None
```
这里我们使用了一个元组来同时返回识别内容和坐标,其中识别内容是 `over[0]`,坐标是 `(x+over[1][0], y+over[1][1])`。需要注意的是,如果没有识别到内容,则返回 `None` 和 `None`。
然后在调用 `shituf` 函数的地方接收返回值即可:
```
content, pos = obj.shituf(loadjietu, leirong, x, y, x1, y1)
if content is not None and pos is not None:
print(f"识别内容:{content},坐标:{pos}")
else:
print("未能识别到内容")
```
这里我们使用了 `is not None` 来判断返回值是否为 `None`,如果不为 `None` 则打印识别内容和坐标,否则打印未能识别到内容。