InitScanGrid: Assertion `maxExtent > 1' failed

32 Views Asked by At

I have a large image where I am trying to find the DMCs so I am trying to localize the Data matrix code using contour and decoding using pylibdmtx.

import cv2
from pylibdmtx import pylibdmtx

# Load the image
image = cv2.imread('capture.jpg')

# Find the DMCs in the image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
dmcs = []
for contour in contours:
    x, y, w, h = cv2.boundingRect(contour)
    if w > 10 and h > 10:  # Filter out small contours
        dmcs.append((x, y, w, h))

# Decode the cropped regions around the DMCs
decoded_data = []
for dmc in dmcs:
    x, y, w, h = dmc
    dmc_region = image[y:y+h, x:x+w]
    dmc_gray = cv2.cvtColor(dmc_region, cv2.COLOR_BGR2GRAY)
    decoded = pylibdmtx.decode(dmc_gray)
    if decoded:
        decoded_data.append(decoded[0].data.decode())

print(decoded_data)

I am getting an error "python: dmtxscangrid.c:45: InitScanGrid: Assertion `maxExtent > 1' failed". Any help is appreciated. Thanks!

0

There are 0 best solutions below