我在 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)
Run Code Online (Sandbox Code Playgroud)