How to install OpenCV on arch linux
Question:
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
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
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:
sudo pacman -S hdf5 vtk
(takes about 231.24 MiB
of memory)
- 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.
for opencv4
sudo pacman -Sy opencv vtk hdf5
optionally, install Qt
sudo pacman -Sy qt5-base qtcreator qt5-doc gdb cmake
create a CMake project in QtCreator
paste the following
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(opencv LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(opencv main.cpp)
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
target_link_libraries( opencv ${OpenCV_LIBS} )
main.cpp
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
if ( argc != 2 )
{
printf("usage: DisplayImage.out <Image_Path>n");
return -1;
}
Mat image;
image = imread( argv[1], 1 );
if ( !image.data )
{
printf("No image data n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}
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
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
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:
sudo pacman -S hdf5 vtk
(takes about231.24 MiB
of memory)- If your program don’t require
hdf5
andvtk
, remove-lopencv_hdf
and-lopencv_viz
from/usr/lib/pkgconfig/opencv4.pc
(in case the program usepkg-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.
for opencv4
sudo pacman -Sy opencv vtk hdf5
optionally, install Qt
sudo pacman -Sy qt5-base qtcreator qt5-doc gdb cmake
create a CMake project in QtCreator
paste the following
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(opencv LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(opencv main.cpp)
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
target_link_libraries( opencv ${OpenCV_LIBS} )
main.cpp
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
if ( argc != 2 )
{
printf("usage: DisplayImage.out <Image_Path>n");
return -1;
}
Mat image;
image = imread( argv[1], 1 );
if ( !image.data )
{
printf("No image data n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}