| 123456789101112131415161718192021222324252627 |
- import cv2
- from pylibdmtx.pylibdmtx import decode
- # TODO[SG]: add real datamatrix code. This is just a placeholder.
- class DataMatrixReader:
- def __init__(self, camera_id: int = 0):
- self.camera_id = camera_id
- self.camera = None
- def initialize(self):
- self.camera = cv2.VideoCapture(self.camera_id)
- def read_datamatrix(self) -> str:
- ret, frame = self.camera.read()
- if not ret:
- raise Exception("Failed to capture image")
-
- decoded = decode(frame)
- if not decoded:
- raise Exception("No data matrix found")
-
- return decoded[0].data.decode('utf-8')
- def cleanup(self):
- if self.camera:
- self.camera.release()
|