如何识别两段水平排列的文字?
#12331
Replies: 4 comments
-
同求解决方案。关注。 |
Beta Was this translation helpful? Give feedback.
0 replies
-
GPT叫我先把图片拆了,然后给我一个代码用来拆分图片,我测试了可行。
|
Beta Was this translation helpful? Give feedback.
0 replies
-
我试试👍
HuZhengWei ***@***.***>于2024年3月7日 周四23:31写道:
GPT叫我先把图片拆了,然后给我一个代码用来拆分图片,我测试了可行。
`
import cv2
import numpy as np
def split_image(image_path):
# 读取图片
img = cv2.imread(image_path)
# 将图片转换为灰度图并进行二值化处理
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
_, thresh = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY_INV)
# 计算图像的垂直投影
projection = np.sum(thresh == 255, axis=0)
# 寻找最窄的间隔,这可能是页面之间的分割线
min_val = np.min(projection)
min_indices = np.where(projection == min_val)[0]
# 取中点作为潜在的分割点
mid_point = int(np.mean(min_indices))
# 判断是否为两页
if mid_point > img.shape[1] * 0.2 and mid_point < img.shape[1] * 0.8: # 假设分割线位于图片20%到80%之间
# 拆分图片
left_page = img[:, :mid_point]
right_page = img[:, mid_point:]
# 保存拆分后的图片
cv2.imwrite('left_page.png', left_page)
cv2.imwrite('right_page.png', right_page)
else:
print(f"图片 {image_path} 是单页文档.")
测试函数
split_image('D:\split-image-test\0a59560d-0fd8-4081-a60c-1e5c6023e88d.jpg')
`
—
Reply to this email directly, view it on GitHub
<#11693 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFRNJMT3XRXKEX2RXTVKN5TYXCB65AVCNFSM6AAAAABEKTWPEKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBTG43DMMBUGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
*Tank *
|
Beta Was this translation helpful? Give feedback.
0 replies
-
手写代码拆分图片太麻烦了, 有没有大神分享一个拆分工具包啊~ |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
请提供下述完整信息以便快速定位问题/Please provide the following information to quickly locate the problem
请尽量不要包含图片在问题中/Please try to not include the image in the issue.
这是一个技术问题,我不知道该选择什么工具来实现。就比如说纸质杂志,排版上是一块块的,我现在用基础的识别没有加任何其他的功能命令,识别出来就是由左向右的识别,结果当然是混乱的。如何指定OCR模型,左边识别完了识别右边?

Beta Was this translation helpful? Give feedback.
All reactions