ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Well, flailing seemed to get me where I needed to go, but it is not pretty. I would really appreciate someone telling me there was a better way.
First, you must get the source tarball for OpenCV 4.2.0 from the OpenCV website, https://github.com/opencv/opencv/archive/4.2.0.zip, unzip it and you will have a directory opencv-4.2.0
Then, in the same directory above opencv-4.2.0 (for the purposes of these instructions), get the source of the opencv debian package,
apt-get source libopencv-dev
which will create a directory opencv-4.2.0+dfsg
Now, I found that the source directory from the package is missing some critical files for enabling the Qt back end, so copy them over from the original OpenCV source (this is why you have to download it as well):
cp -a opencv-4.2.0/modules/highgui/src/files_Qt/Milky opencv-4.2.0+dfsg/modules/highgui/src/files_Qt
Now, cd to opencv-4.2.0+dfsg and we can forget about the OpenCV source. Edit debian/rules, and change the line that says
-DWITH_QT=OFF \
to be
-DWITH_QT=ON \
We need to make sure a new support library that is created as a result gets installed with highgui, so edit debian/libopencv-highgui-dev.install and add the lines
usr/include/opencv4/opencv2/cvv/*
usr/include/opencv4/opencv2/cvv.hpp
usr/lib/*/libopencv_cvv.a
usr/lib/*/libopencv_cvv.so
and then edit the file debian/libopencv-highgui4.2.install and add the line
usr/lib/*/libopencv_cvv.so.*
Then you have to get setup to build and actually build the .deb files
sudo apt-get update
sudo apt-get install dpkg-dev devscripts
sudo apt build-dep opencv
sudo apt-get install qt5-default
sudo debuild -b -uc -us
You should have a bunch of .deb files in .., and the two important ones are libopencv-highgui4.2_4.2.0+dfsg-5_amd64.deb and libopencv-highgui-dev_4.2.0+dfsg-5_amd64.deb. I gather those two .debs in a debs subdirectory of my developer dockerenv directory that overlays what I as a developer need on top of the images used for deploying on the robots. I add the following to dockerenv/Dockerfile
# below is a highly risky way of enabling the Qt backend for OpenCV highgui.
# If you are not actively debugging image processing code, you may want to
# comment it out
COPY debs /home/acr/debs
RUN dpkg -r --force-depends libopencv-highgui-dev libopencv-highgui4.2
RUN dpkg -i /home/acr/debs/libopencv-highgui4.2_4.2.0+dfsg-5_amd64.deb /home/acr/debs/libopencv-highgui-dev_4.2.0+dfsg-5_amd64.deb
This is a fairly alarming and risky feeling maneuver, and it leaves the apt system in my docker pretty much crippled, as everything that depends on highgui is all borked up.
Even more alarming and an indication of how risky this is, when I run with this I got a core dump in an invocation of pcl::ConvexHull::reconstruct. Googling led me to a fortunate thing: I just changed
#include <pcl/surface/convex_hull.h>
to
#include <pcl/surface/impl/convex_hull.hpp>
That doesn't make me worried at all. Fortunately, this is only in my "debugging" code for use when I am developing the algorithms, and the weirdness doesn't extend to what is deployed to customers.
Again, I ask, was there a better way to do any of this, or do the ROS developers just really, really not want people to actually develop openCV code under noetic? Is there a similar problem in ROS2 with openCV, or is it all better there and this is another reason I should switch?