【发布时间】:2021-05-28 08:54:30
【问题描述】:
我在 Python 3.6 中使用 pylibdmtx 来检测 zbar 无法检测到的条形码类型(Datamatrix)。不幸的是,文档很少,条码检测速度非常慢,在硬件相对较新的机器上,每张图像最多需要 30 秒。有哪些方法可以加快检测时间?我当前的代码如下,它可以让我缩短到大约 20 秒,但仍然太慢了。
from PIL import Image
import cv2
from pylibdmtx.pylibdmtx import decode as dmtxdecode
image = cv2.imread(imagepath, cv2.IMREAD_UNCHANGED);
scale_percent = 50
width = int(image.shape[1] * scale_percent / 100)
height = int(image.shape[0] * scale_percent / 100)
dsize = (width, height)
# calculate the 50 percent of original dimensions
output = cv2.resize(image, dsize)
gray = cv2.cvtColor(output, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
pylibresult = dmtxdecode(thresh)
【问题讨论】:
-
我也试过了,只要把 scale_percent 设置为 5 或 10 就超级快了!
标签: python image-processing ocr