Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install OpenCV on arch linux

I have tried installing opencv on arch using the aur package. It has successfully installed but when I try to import opencv2 in python, I get the following error

ImportError: libhdf5.so.100: cannot open shared object file: No such file or directory

Not just python , even when I tried running a c++ sample code using this, I got the same error. I have tried searching the net, found a few people who faced a similar issue but still I am unable to fix it.

I have installed Open CV version 3.2

like image 281
Reuben_v1 Avatar asked Jul 18 '17 19:07

Reuben_v1


Video Answer


2 Answers

There are multiple packages with similar names but only one that works.

If you have not yet installed OpenCV, run:

pacman -S opencv
pacman -S python-opencv

Install hdf5:

pacman -S hdf5

Note that instructions for Sikuli, which depends on OpenCV, indicate that a symbolic link is required in /usr/lib. A system upgrade can break the link, which will have to be recreated to point to the most recent version of the OpenCV Java library:

# ls -la /usr/lib/libopencv_java*
-rwxr-xr-x 1 root root 2225952 Jul 18 02:48 /usr/lib/libopencv_java440.so
lrwxrwxrwx 1 root root      20 Aug  5 22:42 /usr/lib/libopencv_java.so -> libopencv_java440.so

This can be accomplished using the ln command:

sudo su -
cd /usr/lib
rm libopencv_java.so
ln -s libopencv_java440.so libopencv_java.so
like image 195
Reuben_v1 Avatar answered Sep 19 '22 21:09

Reuben_v1


In version 4, in the default configuration, compiling opencv requires hdf5 and vtk, however it's not listed as a dependency of opencv.

That is mentioned in the two bugs on archlinux page: 1, 2.

There are 2 possible workarounds:

  1. sudo pacman -S hdf5 vtk (takes about 231.24 MiB of memory)
  2. If your program don't require hdf5 and vtk, remove -lopencv_hdf and -lopencv_viz from /usr/lib/pkgconfig/opencv4.pc (in case the program use pkg-config), or remove the 2 flags while compiling.

Warning: If you use workaround 2, update of opencv package will revert those changes. You may want to add them as a NoUpgrade entry in pacman.conf (read man page for details), but the file will no longer be updated and something else may break.

like image 36
user202729 Avatar answered Sep 20 '22 21:09

user202729