Installing OpenCV in Ubuntu 14.10 - opencv

I'm trying to install OpenCV in Ubuntu 14.10 according to instruction.
I installed all mentioned dependencies, but when I'm trying to run make I get such errors:
/home/ilia/opencv-2.4.8/modules/highgui/src/ffmpeg_codecs.hpp:114:7: error: ‘CODEC_ID_H261’ was not declared in this scope
{ CODEC_ID_H261, MKTAG('H', '2', '6', '1') }
for all codecs, as I think.
And these errors:
In file included from /home/ilia/opencv-2.4.8/modules/highgui/src/cap_ffmpeg.cpp:45:0:
/home/ilia/opencv-2.4.8/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘double CvCapture_FFMPEG::getProperty(int)’:
/home/ilia/opencv-2.4.8/modules/highgui/src/cap_ffmpeg_impl.hpp:773:33: error: ‘AVStream’ has no member named ‘r_frame_rate’
return av_q2d(video_st->r_frame_rate);
^
/home/ilia/opencv-2.4.8/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘double CvCapture_FFMPEG::get_fps()’:
/home/ilia/opencv-2.4.8/modules/highgui/src/cap_ffmpeg_impl.hpp:820:49: error: ‘AVStream’ has no member named ‘r_frame_rate’
double fps = r2d(ic->streams[video_stream]->r_frame_rate);
^
In file included from /home/ilia/opencv-2.4.8/modules/highgui/src/cap_ffmpeg.cpp:45:0:
/home/ilia/opencv-2.4.8/modules/highgui/src/cap_ffmpeg_impl.hpp: In function ‘int icv_av_write_frame_FFMPEG(AVFormatContext*, AVStream*, uint8_t*, uint32_t, AVFrame*)’:
/home/ilia/opencv-2.4.8/modules/highgui/src/cap_ffmpeg_impl.hpp:1236:72: error: ‘avcodec_encode_video’ was not declared in this scope
out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
^
It looks like it can not find some header files, but I installed all necessary dev packages
libswscale-dev, libavdevice-dev, libavfilter-dev, libavformat-dev, libavcodec-dev. What should I do to resolve these problems?

Installing OpenCV from the Ubuntu repositories is a good choice for the most cases, but sometimes you need build OpenCV from sources yourself.
For example, if you need OpenCV's non-free functionality, or want to contribute to this project (you should use the latest version to create pull request), or want to change something (yes, OpenCV can also contain bugs).
Possible solution is building ffmpeg (it's rather simple) - I really don't understand why Debian/Ubuntu prefers libav without alternative.
For installing ffmpeg you should download its sources from official site or clone GIT repository (git://source.ffmpeg.org/ffmpeg.git), then enter source directory and run
./configure --enable-shared --disable-static
make
sudo make install
you can also add other parameters to configure.
You can build static libraries too, but OpenCV can't be built with static ffmpeg libraries (now I don't know why).
After this you can download OpenCV sources from OpenCV site or clone GitHub repository (OpenCV repository), create build folder and run from it the following:
cmake PATH_TO_SOURCES -DCMAKE_BUILD_TYPE=Release
make
sudo make install
Of course, PATH_TO_SOURCES must be actual path to your OpenCV sources.
After these steps you have working latest OpenCV build in your system.

Unless you have special reasons I would suggest installing the OpenCV that are already in the Ubuntu repository: sudo apt-get install libopencv-dev
For video codecs I suggest simply trying to install all ffmpeg and gstreamer related codec packages.

You can try to build without a ffmpeg:
cmake -DCMAKE_BUILD_TYPE=RELEASE -DWITH_FFMPEG=OFF ..
make
sudo make install

Related

Make the OpenCV libraries that the binary program really needs available to the customer

I have installed the OpenCV package in Ubuntu22.04 by sudo apt-get.
And the said OpenCV is one of the dependencies for my project.
The problem is that the target computer does not have installed OpenCV and it's impossible to use sudo permission.
How to make the OpenCV that I am using portable by the install command of Cmake? I intend to copy the OpenCV libraries when make install is invoked.
What I have tried is seen below.
Here is a portion of the CMakeLists.txt:
find_package( OpenCV REQUIRED )
message("OpenCV_LIBS:")
foreach(lib ${OpenCV_LIBS})
message("${lib}")
endforeach()
install(FILES ${OpenCV_LIBS} TYPE LIB)
Here is the output when cmake .. is invoked:
OpenCV_LIBS:
opencv_calib3d
opencv_core
opencv_dnn
opencv_features2d
opencv_flann
opencv_highgui
//omits some similar output
Here is the error message when make install is called:
CMake Error at cmake_install.cmake:130 (file):
file INSTALL cannot find "/home/john/myproject/opencv_calib3d":
No such file or directory.
And what's more, how to only make the libraries that the binary program really needs available to the customer other than sending all the libraries of OpenCV to the customer?
Tips: the customer uses the same OS.

fatal error: opencv2/xfeatures2d.hpp: No such file or directory

I am trying to build this code:
https://docs.opencv.org/3.2.0/d5/d6f/tutorial_feature_flann_matcher.html
I am using Ubuntu 16.04 with CLion 2017.3 and have OpenCV 3.4 installed.
xfeatures2d.hpp can't be found on the system.
I have looked at many different problems on the internet, but couldn't find a solution.
Any help?
You have to include cmake comiplation flag to opencv OPENCV_EXTRA_MODULES_PATH and set it to the opencv_contrib/modules.
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules
Here's what I had to do to compile OpenCV with xfeatures2d:
Download opencv_contrib (I took a release from the releases page). This step is what gives us xfeatures2d.
Unpack the tarball somewhere, e.g., ~/src/opencv_contrib-4.5.5
When configuring OpenCV (the main OpenCV source like opencv-4.5.2) with CMake, add the following option to cmake command line (adjusting the value to be your actual path to the modules subdirectory of the opencv_contrib tarball):
-DOPENCV_EXTRA_MODULES_PATH=$HOME/src/opencv_contrib-4.5.5/modules/
Now just build as you normally would and install.
The above actions gave me the expected file (among others): /usr/include/opencv4/opencv2/xfeatures2d.hpp.

Error in build project with opencv

I want to build YOLO in ubuntu 16.04 with opencv. I install opencv with
sudo apt-get install libopencv-dev
However when I run make I get
./src/image.c:509:29: error: unknown type name 'CvCapture'
image get_image_from_stream(CvCapture *cap)
Note that I can successfully build without opencv.(Sorry for my poor English).
How can I solve it?
You'd better refer to this link. Add the following header file inside #ifdef OPENCV blocks of those files.
#include "opencv2/videoio/videoio_c.h"

Unable to find Lua headers with find_package in cmake

I'm trying to use CMake to build generate the make file for a project of mine that uses Lua. When I run make I get this error:
/path/to/my/project/luaudio/luaudio.c:1:17: fatal error: lua.h: No such file or directory
In the CMakeLists.txt file, I have the following lines, which I thought would do it, but apparently they're not enough:
find_package(Lua51 REQUIRED)
set(Luaudio_INCLUDE_DIRS ${Luaudio_SOURCE_DIR} ${Lua51_INCLUDE_DIRS} PARENT_SCOPE)
include_directories(${Luaudio_INCLUDE_DIRS})
Lua51_Include_Dirs appears to be empty (attempting to run it though the message command doesn't print anything) so I suspect that it just can't find it. Do I need to specify where to look for Lua? I was under the impression that the whole point of find_package was that it would look in a set a predefined places so that I don't need to specify where it is specifically.
(This is on an Ubuntu machine and I do have the Lua packages installed.)
install lua bin:
sudo apt-get install lua5.1
install lua lib:
sudo apt-get install lua5.1-dev
Exploring FindLua51.cmake from cmake 2.8 I found that it sets LUA_INCLUDE_DIR variable instead of Lua51_INCLUDE_DIRS. So cmake code should be
find_package(Lua51 REQUIRED)
set(Luaudio_INCLUDE_DIRS ${Luaudio_SOURCE_DIR} ${LUA_INCLUDE_DIR} PARENT_SCOPE)
include_directories(${Luaudio_INCLUDE_DIRS})
for Ubuntu 14.04
sudo apt install lua5.2;
sudo apt install liblua5.2-dev;

CMake can't find FFMPEG in custom install path

I am compiling a dependency for a project on Ubuntu 10.10, and instead of having it install to /usr/local by default, I am instead installing it to /tmp/stage/usr/local. How do I go about informing CMake of the location of this custom installed dependency when I call it to generate the build files for said project.
I am running CMake 2.8.1, and I have tried to set CMAKE_PREFIX_PATH on the cmake command line, like so
cmake -D CMAKE_PREFIX_PATH=/tmp/stage/usr/local
but this doesn't seem to make a difference - the project doesn't seem to detect the dependency.
Also, if it matters, the project in question is OpenCV 2.2, and the dependency in question is FFMPEG...
I figured out how to fix my problem, and trying to point CMake at the appropriate install location isn't the issue.
Apparently, CMake is unable to find the pkg-config files for FFMPEG (i.e. libavcodec.pc, libavdevice.pc, etc.) that tell it where the FFMPEG headers and libraries are located. In a typical install scenario, these files would be located at /usr/lib/pkgconfig. However because of the custom install location, they are instead located at /tmp/stage/usr/local/lib/pkgconfig.
So that CMake could find these files, I had to add the following environment variable:
export PKG_CONFIG_PATH=/tmp/stage/usr/local/lib/pkgconfig
After which point, OpenCV built against FFMPEG as expected.

Resources