我正在使用Python 3.6中的pylibdmtx来检测条码类型(Datamatrix),这些类型无法被zbar检测到。不幸的是,文档很少,并且条形码检测速度非常慢,即使在硬件相对较新的计算机上,每张图像需要花费长达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)