How to install latest openCV from source in openSuse 64

Hi,

I’m a new user of openSuse, I think that it is a great distribution. I’m an old Ubuntu user and I have to learn many things about the difference between them. When I was in Ubuntu I found a very useful script to build openCV from source. The script is the following:


version="$(wget -q -O - http://sourceforge.net/projects/opencvlibrary/files/opencv-unix | egrep -m1 -o '\"[0-9](\.[0-9])+' | cut -c2-)"
echo "Installing OpenCV" $version
mkdir OpenCV
cd OpenCV
echo "Removing any pre-installed ffmpeg and x264"
sudo apt-get -qq remove ffmpeg x264 libx264-dev
echo "Installing Dependenices"
sudo apt-get -qq install libopencv-dev build-essential checkinstall cmake pkg-config yasm libtiff4-dev libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils ffmpeg
echo "Downloading OpenCV" $version
wget -O OpenCV-$version.tar.gz http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/opencv-"$version".tar.gz/download
echo "Installing OpenCV" $version
tar -xvf OpenCV-$version.tar.gz
cd opencv-$version
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
make -j2
sudo make install
sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
echo "OpenCV" $version "ready to be used"

I can reuse all the part except the following:


echo "Removing any pre-installed ffmpeg and x264"
sudo apt-get remove ffmpeg x264 libx264-dev
echo "Installing Dependencies"
sudo apt-get install libopencv-dev build-essential checkinstall cmake pkg-config yasm libtiff4-dev libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils ffmpeg

Can you provide me the corresponding command package in openSuse?


echo "Removing any pre-installed ffmpeg and x264"
sudo zypper remove ffmpeg x264 libx264-dev
echo "Installing Dependencies"
sudo zypper install libopencv-dev build-essential checkinstall cmake pkg-config yasm libtiff4-dev libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils ffmpeg

Thank you very much
Best Regards

3 points.

  1. You do know you can simply install opencv using YaST’s Software Manager since it’s located in the OSS repo (which is
    enabled by default). Or you can use zypper:

sh-4.2$ su -c "zypper in opencv"

  1. Unlike Ubuntu, openSUSE is not obssessed by sudo': if you going to run a script that installs software, you shouldn't need to begin any line with sudo’ because you can simply run your installation script in openSUSE thus…

sh-4.2$ su -c "sh yourscript.sh"

… obviating the need for `sudos’ inside your script.

  1. The default package installations for Ubuntu and openSUSE differ and by switching defaults, you can’t assume that the
    dependency are going to fulfilled identically between the distributions. If you really want to install from source, you
    should read the dependencies of opencv that should be listed on the SourceForge site. But I really think it’s a lot
    easier to install with dependencies auto-installed using YaST or zypper (see Point 1).

Thank you for your reply. I’m interested about installing openCV from source since I want to add custom codecs and custom compiling options. I’m trying to achieve this in all major distributions. I started with Debian, Ubuntu and Mint and Fedora. Now I want to do this with openSuse.


echo "Removing any pre-installed ffmpeg and x264"
su -c "zypper remove ffmpeg x264 libx264-dev"
echo "Installing Dependencies"
su -c "zypper install libopencv-dev build-essential checkinstall cmake pkg-config yasm libtiff4-dev libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils ffmpeg"


What I need is a way to locate the corresponding packages in openSUSE. For instance in Ubuntu the command to find a package is apt-cache search name while in Fedora is yum list name.
How can I do this in openSuse?

Thank you

I assume your starting point is

man zypper

On 2014-01-24, erotavlas <erotavlas@no-mx.forums.opensuse.org> wrote:
> What I need is a way to locate the corresponding packages in openSUSE.
> For instance in Ubuntu the command to find a package is apt-cache search
> name while in Fedora is yum list name.
> How can I do this in openSuse?
>
> Thank you


sh-4-2$ su -c "zypper se *name*"

On 2014-01-24 11:46, erotavlas wrote:

> Thank you for your reply. I’m interested about installing openCV from
> source since I want to add custom codecs and custom compiling options.
> I’m trying to achieve this in all major distributions. I started with
> Debian, Ubuntu and Mint and Fedora. Now I want to do this with openSuse.

You could consider then the open buildservice. You get an account, and
build there your package for several distributions. Caveat: those codecs
have to be entirely legal (on the USA, I think).

>
>
> Code:
> --------------------
>
> echo “Removing any pre-installed ffmpeg and x264”
> su -c “zypper remove ffmpeg x264 libx264-dev”
> echo “Installing Dependencies”
> su -c “zypper install libopencv-dev build-essential checkinstall cmake pkg-config yasm libtiff4-dev libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils ffmpeg”
>
>
> --------------------

Calling “su” or “sudo” often inside a script causes it to be requesting
the root password every time. This is highly inconvenient. Normally I
would expect to run such a script simply by root directly.

After all, it is the administrator who does maintenance tasks, not the
users.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

Ok with the command zypper se name I have found the majority of the libraries. The following libraries are not present in the repositories. Some of them are not open and in the other distributions I added non-free repositories to get them.


pkgconfig ffmpeg x264 libavformat libavfilter libavdevice libavcodec tbb libfaac libmp3lame libamrnb libopencore-amrnb0 libopencore-amr-devel libxvidcore-devel

What are the repository in case of openSUSE?

This being in the Multimedia forums, did you read the stickies at the top og the threads in this forum?

“pkgconfig” is called “pkg-config” in openSUSE (part of the standard repo of course).

The rest is available in the Packman repo, the standard repo for Multimedia on openSUSE:
http://packman.links2linux.de/

PS: I overlooked “tbb”, sorry. No idea what that would be though, and therefore I don’t know where to get it either.
PPS: Well, it’s available here:
http://software.opensuse.org/package/tbb
But I guess you would need libtbb2 and tbb-devel, since tbb seems to be only the name of the src rpm.
http://software.opensuse.org/package/libtbb2
Anyway, I would suggest to use that repo for tbb:
http://download.opensuse.org/repositories/devel:/libraries:/c_c++/

Hmmm. 3 more points.

  1. See hcvv’s comments.
  2. Be grateful to wolfi323 for his searching for you.
  3. Familiarise yourself with http://software.opensuse.org/search?baseproject=openSUSE:13.1

Thank you very much at all for the support (in particular to wolfi323). You allow to me to save a lot of time. I have attached the script that do all the work so in future other new user, like me, will have the life simplified :slight_smile:

Best Regards


version="$(wget -q -O - http://sourceforge.net/projects/opencvlibrary/files/opencv-unix | egrep -m1 -o '\"[0-9](\.[0-9])+' | cut -c2-)"
downloadfilelist="opencv-$version.tar.gz opencv-$version.zip"
downloadfile=
for file in $downloadfilelist;
do
        wget --spider http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/$file/download
        if  $? -eq 0 ]; then
                downloadfile=$file
        fi
done
if  -z "$downloadfile" ]; then
        echo "Could not find download file on sourceforge page. Please find the download file for version $version at"
        echo "http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/ and update this script"
        exit 1
fi
echo "Installing OpenCV, ffmpeg and zlib" $version
mkdir OpenCV
cd OpenCV
echo "Installing repository"
su -c "zypper ar -f -n packman-multimedia http://packman.inode.at/suse/openSUSE_$(cat /etc/SuSE-release | grep "VERSION =" | awk -F "=" '{gsub(" ", "", $2); print $2}')/Multimedia/ packman-multimedia"
su -c "zypper ar -f -n devel-libraries-c++ http://download.opensuse.org/repositories/devel:/libraries:/c_c++/openSUSE_$(cat /etc/SuSE-release | grep "VERSION =" | awk -F "=" '{gsub(" ", "", $2); print $2}')/ devel-libraries-c++"
su -c "zypper refresh"
echo "Removing any pre-installed ffmpeg and x264"
su -c "zypper remove ffmpeg x264 libx264-devel"
echo "Installing Dependenices ffmpeg, codecs and zlib"
su -c "zypper install gcc gcc-c++ make cmake checkinstall pkg-config yasm opencv-devel libavutil51 libavformat51 libavfilter1 libavdevice51 libavcodec55 libtiff-devel openjpeg-devel libopenjpeg1 libdc1394-devel libXinerama-devel libgstreameexitr-0_10-0 gstreamer-plugins-base libv4l-devel python-devel python-numpy-devel tbb libtbb2 libqt4-devel gtk2-devel libfaac-devel libmp3lame-devel libamrnb-devel libopencore-amrnb0 libtheora-devel libvorbis-devel libvpx1 libxvidcore-devel x264 v4l-utils ffmpeg ffmpeg unzip zlib-devel"
echo "Downloading OpenCV" $version
wget -O $downloadfile http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/$downloadfile/download
echo "Installing OpenCV" $version
echo $downloadfile | grep ".zip"
if  $? -eq 0 ]; then
        unzip $downloadfile
else
        tar -xvf $downloadfile
fi
cd opencv-$version
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=ON -D WITH_TBB=ON -D WITH_OPENMP=ON -D WITH_OPENCL=ON -D WITH_CUDA=ON -D WITH_GTK=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=OFF -D BUILD_EXAMPLES=OFF -D WITH_QT=ON -D WITH_OPENGL=ON -D BUILD_JPEG=ON -D BUILD_PNG=ON -D BUILD_JASPER=ON -D BUILD_ZLIB=ON -D WITH_JPEG=ON -D WITH_PNG=ON -D WITH_JASPER=ON -D WITH_ZLIB=ON -D WITH_OPENEXR=OFF ..
make -j 2
su -c "make install"
su -c "sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'"
su -c "ldconfig"
echo "OpenCV" $version "ready to be used"

On 2014-01-25 11:16, erotavlas wrote:

> Code:
> --------------------

> su -c “zypper ar -f -n packman-multimedia http://packman.inode.at/suse/openSUSE_$(cat /etc/SuSE-release | grep “VERSION =” | awk -F “=” '{gsub(” “, “”, $2); print $2}’)/Multimedia/ packman-multimedia”
> su -c “zypper ar -f -n devel-libraries-c++ http://download.opensuse.org/repositories/devel:/libraries:/c_c++/openSUSE_$(cat /etc/SuSE-release | grep “VERSION =” | awk -F “=” '{gsub(” “, “”, $2); print $2}’)/ devel-libraries-c++”
> su -c “zypper refresh”
> echo “Removing any pre-installed ffmpeg and x264”
> su -c “zypper remove ffmpeg x264 libx264-devel”
> echo “Installing Dependenices ffmpeg, codecs and zlib”
>
> --------------------

Have you actually tried to run that in openSUSE?

It will be asking for root’s password once per line!


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

Hi,

you are right this is ok since I don’t want to have folder of openCV with root permission. However the following script requires the password only one time when you launch it with sh -c “sh installOpenCV.sh”


version="$(wget -q -O - http://sourceforge.net/projects/opencvlibrary/files/opencv-unix | egrep -m1 -o '\"[0-9](\.[0-9])+' | cut -c2-)"
downloadfilelist="opencv-$version.tar.gz opencv-$version.zip"
downloadfile=
for file in $downloadfilelist;
do
        wget --spider http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/$file/download
        if  $? -eq 0 ]; then
                downloadfile=$file
        fi
done
if  -z "$downloadfile" ]; then
        echo "Could not find download file on sourceforge page. Please find the download file for version $version at"
        echo "http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/ and update this script"
        exit 1
fi
echo "Installing OpenCV, ffmpeg and zlib" $version
mkdir OpenCV
cd OpenCV
echo "Installing repository"
zypper ar -f -n packman-multimedia http://packman.inode.at/suse/openSUSE_$(cat /etc/SuSE-release | grep "VERSION =" | awk -F "=" '{gsub(" ", "", $2); print $2}')/Multimedia/ packman-multimedia
zypper ar -f -n devel-libraries-c++ http://download.opensuse.org/repositories/devel:/libraries:/c_c++/openSUSE_$(cat /etc/SuSE-release | grep "VERSION =" | awk -F "=" '{gsub(" ", "", $2); print $2}')/ devel-libraries-c++
zypper refresh
echo "Removing any pre-installed ffmpeg and x264"
zypper remove ffmpeg x264 libx264-devel
echo "Installing Dependenices ffmpeg, codecs and zlib"
zypper install gcc gcc-c++ make cmake checkinstall pkg-config yasm opencv-devel libavutil51 libavformat51 libavfilter1 libavdevice51 libavcodec55 libtiff-devel openjpeg-devel libopenjpeg1 libdc1394-devel libXinerama-devel libgstreameexitr-0_10-0 gstreamer-plugins-base libv4l-devel python-devel python-numpy-devel tbb libtbb2 libqt4-devel gtk2-devel libfaac-devel libmp3lame-devel libamrnb-devel libopencore-amrnb0 libtheora-devel libvorbis-devel libvpx1 libxvidcore-devel x264 v4l-utils ffmpeg ffmpeg unzip zlib-devel"
echo "Downloading OpenCV" $version
wget -O $downloadfile http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/$downloadfile/download
echo "Installing OpenCV" $version
echo $downloadfile | grep ".zip"
if  $? -eq 0 ]; then
        unzip $downloadfile
else
        tar -xvf $downloadfile
fi
cd opencv-$version
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=ON -D WITH_TBB=ON -D WITH_OPENMP=ON -D WITH_OPENCL=ON -D WITH_CUDA=ON -D WITH_GTK=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=OFF -D BUILD_EXAMPLES=OFF -D WITH_QT=ON -D WITH_OPENGL=ON -D BUILD_JPEG=ON -D BUILD_PNG=ON -D BUILD_JASPER=ON -D BUILD_ZLIB=ON -D WITH_JPEG=ON -D WITH_PNG=ON -D WITH_JASPER=ON -D WITH_ZLIB=ON -D WITH_OPENEXR=OFF ..
make -j 2
make install
sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
ldconfig
echo "OpenCV" $version "ready to be used"

???
Why not just ./installOpenCV.sh ? :wink:

And use “sudo” instead of “su -c” inside your script. “sudo” will remember the password for a while, so you would only have to enter it once.

Because there is no shebang in the “script”, just starting it, it will not be quite clear which shell will be used. By starting the POSIX shell through the sh command and then offering it the file with commands to be executed, the OP is sure which shell is used. (But I would prefer to add the shebang of course).

You are right probably it is the best.


version="$(wget -q -O - http://sourceforge.net/projects/opencvlibrary/files/opencv-unix | egrep -m1 -o '\"[0-9](\.[0-9])+' | cut -c2-)"
downloadfilelist="opencv-$version.tar.gz opencv-$version.zip"
downloadfile=
for file in $downloadfilelist;
do
        wget --spider http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/$file/download
        if  $? -eq 0 ]; then
                downloadfile=$file
        fi
done
if  -z "$downloadfile" ]; then
        echo "Could not find download file on sourceforge page. Please find the download file for version $version at"
        echo "http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/ and update this script"
        exit 1
fi
echo "Installing OpenCV, ffmpeg and zlib" $version
mkdir OpenCV
cd OpenCV
echo "Installing repository"
sudo zypper ar -f -n packman-multimedia http://packman.inode.at/suse/openSUSE_$(cat /etc/SuSE-release | grep "VERSION =" | awk -F "=" '{gsub(" ", "", $2); print $2}')/Multimedia/ packman-multimedia
sudo zypper ar -f -n devel-libraries-c++ http://download.opensuse.org/repositories/devel:/libraries:/c_c++/openSUSE_$(cat /etc/SuSE-release | grep "VERSION =" | awk -F "=" '{gsub(" ", "", $2); print $2}')/ devel-libraries-c++
sudo zypper refresh
echo "Removing any pre-installed ffmpeg and x264"
sudo zypper remove ffmpeg x264 libx264-devel
echo "Installing Dependenices ffmpeg, codecs and zlib"
sudo zypper install gcc gcc-c++ make cmake checkinstall pkg-config yasm opencv-devel libavutil51 libavformat51 libavfilter1 libavdevice51 libavcodec55 libtiff-devel openjpeg-devel libopenjpeg1 libdc1394-devel libXinerama-devel libgstreameexitr-0_10-0 gstreamer-plugins-base libv4l-devel python-devel python-numpy-devel tbb libtbb2 libqt4-devel gtk2-devel libfaac-devel libmp3lame-devel libamrnb-devel libopencore-amrnb0 libtheora-devel libvorbis-devel libvpx1 libxvidcore-devel x264 v4l-utils ffmpeg ffmpeg unzip zlib-devel
echo "Downloading OpenCV" $version
wget -O $downloadfile http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/$downloadfile/download
echo "Installing OpenCV" $version
echo $downloadfile | grep ".zip"
if  $? -eq 0 ]; then
        unzip $downloadfile
else
        tar -xvf $downloadfile
fi
cd opencv-$version
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=ON -D WITH_TBB=ON -D WITH_OPENMP=ON -D WITH_OPENCL=ON -D WITH_CUDA=ON -D WITH_GTK=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=OFF -D BUILD_EXAMPLES=OFF -D WITH_QT=ON -D WITH_OPENGL=ON -D BUILD_JPEG=ON -D BUILD_PNG=ON -D BUILD_JASPER=ON -D BUILD_ZLIB=ON -D WITH_JPEG=ON -D WITH_PNG=ON -D WITH_JASPER=ON -D WITH_ZLIB=ON -D WITH_OPENEXR=OFF ..
make -j 2
sudo make install
sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
echo "OpenCV" $version "ready to be used"

So what?
If he cares which shell is used, he should add the shebang anyway. Better than having to specify the right shell when calling the script IMHO.

But actually I was mostly aiming at the two “sh”'s in the command line:

sh -c “sh installOpenCV.sh”

But I think now that this was just a typo, the first one was meant to be “su” I guess…

That was the meaning of my remark.

That is why we ask copy/paste inside CODE tags.

On 2014-01-25 18:06, wolfi323 wrote:
> But I think now that this was just a typo, the first one was meant to be
> “su” I guess…

I thought so, as well.

In which case, all the “su” inside the script are absurd.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

On 2014-01-25 17:56, erotavlas wrote:
>
> You are right probably it is the best.

If you are calling the script with “su”, you need neither “su” nor
“sudo” inside the script. All that is absurd.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)