Python 从带有坐标的名片图像中提取徽标和文本
我有一张名片。我想从带有坐标的名片上获取徽标和所有文字。所以我可以使上传的图像在HTML画布上可编辑。我看过这么多的例子,但我找不到确切的我要找的。我只发现从图像中获取文本。我也尝试过谷歌视觉API,但它也只提供文本。 我是python新手 这是一个示例图像 在下面的代码中,我必须选择要提取的徽标。我需要它自动查找和提取Python 从带有坐标的名片图像中提取徽标和文本,python,opencv,ocr,html2canvas,google-vision,Python,Opencv,Ocr,Html2canvas,Google Vision,我有一张名片。我想从带有坐标的名片上获取徽标和所有文字。所以我可以使上传的图像在HTML画布上可编辑。我看过这么多的例子,但我找不到确切的我要找的。我只发现从图像中获取文本。我也尝试过谷歌视觉API,但它也只提供文本。 我是python新手 这是一个示例图像 在下面的代码中,我必须选择要提取的徽标。我需要它自动查找和提取 # import the necessary packages import argparse import cv2 # initialize the list of ref
# import the necessary packages
import argparse
import cv2
# initialize the list of reference points and boolean indicating
# whether cropping is being performed or not
ref_point = []
cropping = False
def shape_selection(event, x, y, flags, param):
# grab references to the global variables
global ref_point, cropping
# if the left mouse button was clicked, record the starting
# (x, y) coordinates and indicate that cropping is being
# performed
if event == cv2.EVENT_LBUTTONDOWN:
ref_point = [(x, y)]
cropping = True
# check to see if the left mouse button was released
elif event == cv2.EVENT_LBUTTONUP:
# record the ending (x, y) coordinates and indicate that
# the cropping operation is finished
ref_point.append((x, y))
cropping = False
# draw a rectangle around the region of interest
cv2.rectangle(image, ref_point[0], ref_point[1], (0, 255, 0), 2)
cv2.imshow("image", image)
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="Path to the image")
args = vars(ap.parse_args())
# load the image, clone it, and setup the mouse callback function
image = cv2.imread(args["image"])
clone = image.copy()
cv2.namedWindow("image")
cv2.setMouseCallback("image", shape_selection)
# keep looping until the 'q' key is pressed
while True:
# display the image and wait for a keypress
cv2.imshow("image", image)
key = cv2.waitKey(1) & 0xFF
# if the 'r' key is pressed, reset the cropping region
if key == ord("r"):
image = clone.copy()
# if the 'c' key is pressed, break from the loop
elif key == ord("c"):
break
# if there are two reference points, then crop the region of interest
# from teh image and display it
if len(ref_point) == 2:
crop_img = clone[ref_point[0][1]:ref_point[1][1], ref_point[0][0]:ref_point[1][0]]
cv2.imshow("crop_img", crop_img)
cv2.waitKey(0)
# close all open windows
cv2.destroyAllWindows()
您可以尝试一下ABBYY云API: API将为您获取所有带有坐标的文本,并且您可以将图像元素(尽可能可检测)恢复为纯图像。通过一些逻辑,您可以将其组合在一起,形成一个文档,其中包含所有文本元素作为真实文本,所有图像作为图像,位于正确的位置 但请记住,在OCR开始之前,对图像进行一些预处理。这意味着图像的质量可能已经改变了。因此,使用从API获得的坐标从原始扫描中提取图像部分可能是一个好主意
API真的很好,它提供的OCR结果与谷歌的云视觉非常相似。你有更多的功能和参数来调整结果。但是ABBYY API要比google API贵得多。请参观并阅读帮助中心的信息指南,特别是如何提出一个好问题以及如何创建一个最小的、可复制的示例。@fmw42 hi我已经添加了我尝试过的代码。请帮我解决这个问题。我从过去一个半月就开始尝试,但仍然没有成功。我尝试了互联网上几乎所有可用的代码。@fmw42正在等待您的答案。我没有任何好的解决方案