Fatal error: opencv2/alphamat.hpp: No such file or directory

Fatal error building opencv from tarball
fatal error: opencv2/alphamat.hpp: No such file or directory

However, I confirmed that alphamat.hpp exists and it is located at opencv_contrib

pi@SMSNG003:~/Applications/opencv/opencv/build ls -la ../../opencv_contrib/modules/alphamat/include/opencv2/ total 12 drwxr-xr-x 2 pi pi 4096 May 3 17:51 . drwxr-xr-x 3 pi pi 4096 May 3 17:51 .. -rw-r--r-- 1 pi pi 1769 May 3 17:51 alphamat.hpp pi@SMSNG003:~/Applications/opencv/opencv/build

As well as other dependencies, which I noticed the show as unavalable at “cmake” building stage

– OpenCV modules:
– To be built: aruco barcode bgsegm bioinspired calib3d ccalib core cvv datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python2 python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
– Disabled: world
– Disabled by dependency: -
– Unavailable: alphamat cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java julia matlab ovis sfm viz
– Applications: perf_tests examples apps

installation source has been built with the following command line

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/pi/Applications/opencv/opencv_contrib/modules -D ENABLE_NEON=ON -D ENABLE_VFPV3=ON -D OPENCV_PYTHON3_INSTALL_PATH=/home/pi/.local/lib/python3.7/site-packages -D WITH_OPENMP=ON -D BUILD_TIFF=ON -D WITH_FFMPEG=ON -D WITH_TBB=ON -D BUILD_TBB=ON -D BUILD_TESTS=OFF -D WITH_EIGEN=OFF -D WITH_V4L=ON -D WITH_LIBV4L=ON -D WITH_VTK=OFF -D WITH_QT=ON -D WITH_OPENGL=ON -D OPENCV_ENABLE_NONFREE=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_opencv_python3=TRUE -D OPENCV_GENERATE_PKGCONFIG=ON -D BUILD_EXAMPLES=OFF …

How could I make that build aware of alphamat location path?

[ 83%] Linking CXX executable …/…/bin/example_stereo_export_param_file
In file included from /home/pi/Applications/opencv/opencv/modules/python/src2/cv2.cpp:41:
/home/pi/Applications/opencv/opencv/build/modules/python_bindings_generator/pyopencv_generated_include.h:55:10: fatal error: opencv2/alphamat.hpp: No such file or directory
#include “opencv2/alphamat.hpp”
^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [modules/python2/CMakeFiles/opencv_python2.dir/build.make:63: modules/python2/CMakeFiles/opencv_python2.dir/__/src2/cv2.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:16951: modules/python2/CMakeFiles/opencv_python2.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs…
[ 83%] Linking CXX executable …/…/bin/opencv_perf_stereo
[ 83%] Linking CXX executable …/…/bin/example_stereo_sample
[ 83%] Built target example_stereo_export_param_file
[ 83%] Built target opencv_perf_stereo
[ 83%] Built target example_stereo_sample
make: *** [Makefile:163: all] Error 2

you need to install Eigen, else it won’t build the opencv_alphamat module.

then – no, there are NO python bindings for this

Sure?
>>> help(cv.alphamat.infoFlow)
Help on built-in function infoFlow:

infoFlow(...)
    infoFlow(image, tmap[, result]) -> result
    .   * @brief Compute alpha matte of an object in an image
    .    * @param image Input RGB image
    .    * @param tmap Input greyscale trimap image
    .    * @param result Output alpha matte image
    .    *
    .    * The function infoFlow performs alpha matting on a RGB image using a greyscale trimap image, and outputs a greyscale alpha matte image. The output alpha matte can be used to softly extract the foreground object from a background image. Examples can be found in the samples directory.
    .    *
1 Like

@laurent.berger – oooh, you’re right i’m wrong.
(confused it with something else)

1 Like

It’s weird because last week I ran the very same procedure in another Raspberry device and the installation went through successfully.

So,What must be done in order to enable alphamat library/module?

Best wishes,
I

Problem solved.

It turned out to be an issue related with permission. Because the installation directory was /usr/local/, installation source files were not properly created. One of them was alphamat.hpp.

… -D CMAKE_INSTALL_PREFIX=/usr/local -D …

by the way, I also tried to run “cmake” as sudo, however files were not created properly. That was weird too.

So I’ve changed the directory, then cmake ran just fine and files were properly created.

Best wishes,
I

cmake only creates build files (Makefile).

if you run something with sudo, it’s got to be make install. make isn’t cmake. different things.

I understand and agree. However, that was not what I had witnessed.

“make install”, which I ran right after “cmake …” , as per installation manual, also returns errors related to alphamat, as expected Of course.

Thus, the error originally begins in the “cmake” procedure. So, it must be fixed there, instead of amending “make install” procedure.

Anyway, the fact is that after I changed the installation directory, the installation process finished successfully.

In fact that was even better , because it made me aware that having openCV 4.5 release located within user’s home directory and libraries installed within virtualenv, gives more flexibility.

So, if, in the future, we decide to run 2 releases of opencv in the same machine, we will have that flexibility.

Now, I’m going deeper in the installation parameters and how I could optimize scanning and image processing. What arguments must I add in the “cmake” procedure in order to achieve better and more optimized results, saving hardware resources. btw, it’s a Rasp Pi device.

Best wishes,
I

when you run make install, it doesn’t simply install things. it builds them first, because they weren’t there already.

and when you sudo make install, all those build files will be created with root privileges… and who knows, root might own them.

it is conceivable that that’s causing issues.

never ever run anything as root unless you know precisely what’s gonna happen.

you could build first, using simply make, and only then sudo make install.

btw, if you’re only interested in the python bindings, you should build cv2.so statically so it won’t depend on further opencv so’s using

BUILD_SHARED_LIBS=OFF

in cmake

not only, but also!

I’m not attached to python bindings.

If .cpp, or even JAVA, perform better I must use them.

Any suggestions?

Best wishes,
I