2

I'm trying to install OpenCV for use with Pastec on an Amazon Linux instance. This is my first time using an Amazon service, and I don't have much experience using linux...

How would I install OpenCV and it's dependencies on Amazon Linux?

I have tried adding the EPEL repository using this command:

$ sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

... which works but it still won't install OpenCV...

$ sudo yum --enablerepo=epel install opencv-core
Loaded plugins: priorities, update-motd, upgrade-helper
948 packages excluded due to repository priority protections
Nothing to do
jjv360
  • 4,120
  • 3
  • 23
  • 37

2 Answers2

16

It seems that default yum repo for Amazon AMI doesn't contain OpenCV packages.

You can compile it from sources by yourself with the following simple steps:

  • install necessary packages:

sudo yum install git cmake gcc-c++

  • clone OpenCV from repository:

git clone https://github.com/opencv/opencv.git

  • (optionally) choose required version, if you do not do it, the master branch will be built:

git checkout <required version>

  • compile and install - create folder where you want to build it, enter there and type:
cmake <path to sources>
make
sudo make install

It's basic steps - after this you will have OpenCV with some default modules. You can read cmake output and adjust your installation before actual build. Possibly you should install additional packages for your needs (like libpng, libjpg, python etc.).

avtomaton
  • 4,725
  • 1
  • 38
  • 42
  • Thanks, it works well. The only problem now is that it takes a very long time to build whenever an instance starts up (like 40 minutes)... Would it be safe to just copy the build folder after running `make` onto every instance, and then just run `sudo make install` with a startup script? – jjv360 Dec 15 '15 at 10:38
  • @jjv360: yes, it's safe if OS and instances are the same, and you have all necessary packages on the target system. It should install everything to the folder specified in cmake first run. – avtomaton Dec 15 '15 at 14:33
  • When I try to checkout 3.1.0; I get this error: `HEAD is now at 92387b1... Fix java version++` I switch between openjdk 1.7 and openjdk 1.8 . But it didn't help. – bodoroman Jan 13 '17 at 14:36
  • @bodoroman Why do you think that it is a error? Seems like normal update at specified head. Now you can try to build it. – avtomaton Jan 13 '17 at 23:19
  • FATAL: In-source builds are not allowed. You should create a separate directory for build files. – Elia Weiss Jan 14 '23 at 07:52
  • 1
    @EliaWeiss that's exactly what I said: "create folder in which you want to build it, enter there and type". The following commands should be executed from that separate directory, and `` is a command-line parameter where your source directory is – avtomaton Jan 15 '23 at 15:14
  • @EliaWeiss if you tried to run cmake and saw this error, you need to rm /path/to/repo/CMakeCache.txt before running again or you'll continue to see the error – Cory Mawhorter May 19 '23 at 19:53
1

cmake should be higher than 3.5 in latest linux versions for the purpose of installing opencv and other packages. To install in Fedora or similar flavour use sudo yum install cmake3

Raj karthy
  • 11
  • 3