I am using pylibdmtx in Python 3.6 to detect barcode types (Datamatrix) which can't be detected by zbar. Unfortunately, documentation is sparse and the barcode detection is painfully slow, taking up to 30 seconds per image on a machine with relatively recent hardware. What are some ways I can speed up the detection time? My current code is as follows which gets me down to about 20 seconds but is still way too slow.
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)