JeVoisBase  1.21
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
Loading...
Searching...
No Matches
PyDMTX.py
Go to the documentation of this file.
1import pyjevois
2if pyjevois.pro: import libjevoispro as jevois
3else: import libjevois as jevois
4import cv2
5import numpy as np
6from pylibdmtx.pylibdmtx import decode
7
8## Decoding of DataMatrix (DMTX) 2D barcodes
9#
10# This module finds and decodes DataMatrix 2D barcodes.
11#
12# It uses libdmtx as a backend, and the pylibdmtx python wrapper.
13#
14# On host, you will need: sudo apt install libdmtx-dev; pip install pylibdmtx
15#
16# @author Laurent Itti
17#
18# @videomapping YUYV 320 280 30.0 YUYV 320 240 30.0 JeVois PyDMTX
19# @email itti\@usc.edu
20# @address University of Southern California, HNB-07A, 3641 Watt Way, Los Angeles, CA 90089-2520, USA
21# @copyright Copyright (C) 2017 by Laurent Itti, iLab and the University of Southern California
22# @mainurl http://jevois.org
23# @supporturl http://jevois.org/doc
24# @otherurl http://iLab.usc.edu
25# @license GPL v3
26# @distribution Unrestricted
27# @restrictions None
28# @ingroup modules
29class PyDMTX:
30 # ###################################################################################################
31 ## Constructor
32 def __init__(self):
33 # Instantiate a JeVois Timer to measure our processing framerate:
34 self.timer = jevois.Timer("dmtx", 100, jevois.LOG_INFO)
35
36 # ###################################################################################################
37 ## Process function with USB output
38 def process(self, inframe, outframe):
39 # Get the next camera image (may block until it is captured) as OpenCV BGR:
40 inimg = inframe.getCvBGR()
41
42 # Start measuring image processing time (NOTE: does not account for input conversion time):
43 self.timer.start()
44
45 # Create dark-gray (value 80) image for the bottom panel, 40 pixels tall:
46 msgbox = np.zeros((40, inimg.shape[1], 3), dtype = np.uint8) + 80
47
48 # Find and decode any DataMatrix symbols:
49 dec = decode(inimg)
50
51 # Draw the results in the input image (which we will copy to output):
52 y = 13
53 for d in dec:
54 cv2.rectangle(inimg, (d.rect.left, d.rect.top), (d.rect.left+d.rect.width-1, d.rect.top+d.rect.height-1),
55 (255,0,0), 2)
56 cv2.putText(msgbox, d.data.decode("utf-8"), (3, y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,255))
57 y = y + 12
58
59 # Create our output image as a copy of the input plus our message box:
60 outimg = np.vstack((inimg, msgbox))
61
62 # Write a title:
63 cv2.putText(outimg, "JeVois Python DataMatrix", (3, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,255))
64
65 # Write frames/s info from our timer into the edge map (NOTE: does not account for output conversion time):
66 fps = self.timer.stop()
67 cv2.putText(outimg, fps, (3, inimg.shape[0] - 6), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,255))
68
69 # Convert our OpenCv output image to video output format and send to host over USB:
70 outframe.sendCv(outimg)
Decoding of DataMatrix (DMTX) 2D barcodes.
Definition PyDMTX.py:29
__init__(self)
Constructor.
Definition PyDMTX.py:32
process(self, inframe, outframe)
Process function with USB output.
Definition PyDMTX.py:38