This tutorial explores how to add new functionality to JeVois in the form of libraries that are accessible from Python. We use the example of libdmtx, a library to decode DataMatrix tags.
We want to be able to decode DataMatrix tags in Python modules running on JeVois.
We first need to identify the relevant source code. A bit of web searching in this case suggests:
Looking at the examples provided with pylibdmtx, it looks like it will support numpy images as used by OpenCV, which is great since this is the image format used by Python modules in JeVois. So we should be able to easyly write a JeVois Python module that receives video frames from the camera sensor as OpenCV numpy arrays and processes them using pylibdmtx (invoking the libdmtx core algorithm).
For this tutorial, we will add the core library, python bindings, and JeVois module to the jevoisextra repository. You are invited to do the same and then let us know once you have something that works great and send us a pull request so we can integrate your new libraries and modules for all to enjoy.
cd git clone https://github.com/jevois/jevoisextra.git
reinstall.sh
downloads all dependenciescheck.sh
checks whether dependencies should be downloaded, by comparing the number in file RELEASE (part of the repository and updated manually each time new dependencies are added) to that in file .installed (generated by reinstall.sh when it runs).Here we add the following to reinstall.sh:
The syntax for get_github
is creator name, repo name, and commit version. It is desirable to use a specific commit version so that users do not get bad surprises if they run this script at a later time when the dependencies may have changed significantly and the head revision may not be compatible with our code anymore.
Then we increase the version number in RELEASE and just run:
./reinstall.sh
To allow for concurrent native compilation and cross-compilation, we will use the CMake build tool, and the CMake macros and scripts provided by the JeVois framework. We will compile libdmtx in a similar way as libjevoisbase is compiled in JeVois.
One hurdle is that libdmtx does not use CMake for building, rather it uses autoconf and a configure script plus a Makefile. Since this project is not very complex, we will just here bypass the configure script and write our own CMakeLists.txt instead. We just need to figure out, by inspecting the configure script and the makefile:
In this particular case, looking at configure.ac of libdmtx, we note:
Now, looking at Makefile.am, we see:
Using the CMakeLists.txt of repository jevoisbase as an example (since it also builds a library, libjevoisbase.so), we create the following new CMakeLists.txt
Since Contrib/libdmtx/ is an externally-fetched repository, let use another location for our CMakeLists.txt. To avoid confusion and possible interference with other versions of libdmtx that might be installed on the host machine (e.g., from Ubunty packages), we will call our library libjvdmtx.so as opposed to plain libdmtx.so:
cd ~/jevoisextra mkdir libjvdmtx cd libjvdmtx
And in there we create CMakeLists.txt as follows:
We also copy rebuild-host.sh, rebuild-platform.sh, COPYING, INSTALL and README from the jevoisbase repository and edit them to adapt them to this project.
Lets' try to compile for host:
itti@iLab0:~/jevoisextra/libjvdmtx$ ./rebuild-host.sh -- JeVois version 1.11.0 -- JEVOIS_PLATFORM: OFF -- JEVOIS_VENDOR: JeVois -- JeVois microSD card mount point: /media/itti/JEVOIS -- JeVois serial-over-USB device: /dev/ttyACM0 -- Install prefix for executable programs: /usr -- Host path to jevois modules root: /jevois -- The C compiler identification is GNU 7.3.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- JeVois SDK root: /lab/itti/jevois/software/jevois-sdk -- Host path to jevois lib and data install root: /jevois -- Configuring done -- Generating done -- Build files have been written to: /lab/itti/jevois/software/jevoisextra/libjvdmtx/hbuild Scanning dependencies of target jvdmtx [ 50%] Building C object CMakeFiles/jvdmtx.dir/lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtx.c.o In file included from /lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtx.c:71:0: /lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtxdecode.c: In function ‘dmtxDecodeCreateDiagnostic’: /lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtxdecode.c:492:84: warning: parameter ‘style’ set but not used [-Wunused-but-set-parameter] dmtxDecodeCreateDiagnostic(DmtxDecode *dec, int *totalBytes, int *headerBytes, int style) ^~~~~ In file included from /lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtx.c:78:0: /lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtxreedsol.c: In function ‘RsDecode’: /lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtxreedsol.c:151:48: warning: unused parameter ‘fix’ [-Wunused-parameter] RsDecode(unsigned char *code, int sizeIdx, int fix) ^~~ In file included from /lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtx.c:83:0: /lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtxtime.c: In function ‘dmtxTimeNow’: /lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtxtime.c:92:7: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body] ; /* XXX handle error better here */ ^ [100%] Linking C shared library libjvdmtx.so [100%] Built target jvdmtx [100%] Built target jvdmtx Install the project... -- Install configuration: "" -- Installing: /usr/lib/libjvdmtx.so.1.0.0 -- Installing: /usr/lib/libjvdmtx.so -- Installing: /usr/share/doc/libjvdmtx-host/README -- Installing: /usr/share/doc/libjvdmtx-host/INSTALL -- Installing: /usr/share/doc/libjvdmtx-host/COPYING
It worked ok (just a couple warnings), and we end up with /usr/lib/libjvdmtx.so which we will later link against.
Now for platform:
itti@iLab0:~/jevoisextra/libjvdmtx$ ./rebuild-platform.sh --staging -- JeVois version 1.11.0 -- JEVOIS_PLATFORM: ON -- JEVOIS_VENDOR: JeVois -- JeVois microSD card mount point: /media/itti/JEVOIS -- JeVois serial-over-USB device: /dev/ttyACM0 -- JEVOIS_MODULES_TO_STAGING: ON -- JEVOIS_MODULES_TO_MICROSD: OFF -- JEVOIS_MODULES_TO_LIVE: OFF -- Install prefix for executable programs: /var/lib/jevois-build/usr -- Host path to jevois modules root: /var/lib/jevois-microsd -- The C compiler identification is GNU 7.2.0 -- Check for working C compiler: /lab/itti/jevois/software/jevois-sdk/out/sun8iw5p1/linux/common/buildroot/host/usr/bin/arm-buildroot-linux-gnueabihf-gcc -- Check for working C compiler: /lab/itti/jevois/software/jevois-sdk/out/sun8iw5p1/linux/common/buildroot/host/usr/bin/arm-buildroot-linux-gnueabihf-gcc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- JeVois SDK root: /lab/itti/jevois/software/jevois-sdk -- Host path to jevois lib and data install root: /var/lib/jevois-microsd -- Configuring done -- Generating done -- Build files have been written to: /lab/itti/jevois/software/jevoisextra/libjvdmtx/pbuild Scanning dependencies of target jvdmtx [ 50%] Building C object CMakeFiles/jvdmtx.dir/lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtx.c.o In file included from /lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtx.c:71:0: /lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtxdecode.c: In function ‘dmtxDecodeCreateDiagnostic’: /lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtxdecode.c:492:84: warning: parameter ‘style’ set but not used [-Wunused-but-set-parameter] dmtxDecodeCreateDiagnostic(DmtxDecode *dec, int *totalBytes, int *headerBytes, int style) ^~~~~ In file included from /lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtx.c:78:0: /lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtxreedsol.c: In function ‘RsDecode’: /lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtxreedsol.c:151:48: warning: unused parameter ‘fix’ [-Wunused-parameter] RsDecode(unsigned char *code, int sizeIdx, int fix) ^~~ In file included from /lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtx.c:83:0: /lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtxtime.c: In function ‘dmtxTimeNow’: /lab/itti/jevois/software/jevoisextra/Contrib/libdmtx/dmtxtime.c:92:7: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body] ; /* XXX handle error better here */ ^ [100%] Linking C shared library libjvdmtx.so [100%] Built target jvdmtx [100%] Built target jvdmtx Install the project... -- Install configuration: "" -- Installing: /var/lib/jevois-microsd/lib/JeVois/libjvdmtx.so -- Set runtime path of "/var/lib/jevois-microsd/lib/JeVois/libjvdmtx.so" to "" -- Installing: /var/lib/jevois-build/usr/share/doc/libjvdmtx-platform/README -- Installing: /var/lib/jevois-build/usr/share/doc/libjvdmtx-platform/INSTALL -- Installing: /var/lib/jevois-build/usr/share/doc/libjvdmtx-platform/COPYING
Same warnings, and we end up with /var/lib/jevois-microsd/lib/JeVois/libjvdmtx.so which is cross-compiled for ARM.