Error in build project with opencv - 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"

Related

Installing OpenCV using Virtual Environment (Ubuntu 16)

I want to install OpenCV. First thing I did was creating a virtual environment by following command in Ubuntu 16:
" conda create -n opencv3.4_py3.6 "
Then, I followed the official instruction here (Building OpenCV from source):
https://docs.opencv.org/3.4/d2/de6/tutorial_py_setup_in_ubuntu.html
However, when I tried to install dependencies, the following message came up:
Unable to locate package "Package Name"
As it can be seen int the attached image
My purpose is installing OpenCV in a Virtual Environment. Also, I want to import and use OpenCV in Spyder.
Any idea about how it can be done?
(Spyder maintainer here) After doing
conda create -n opencv3.4_py3.6
you need to run these other three commands to get what you want
source activate opencv3.4_py3.6
conda install opencv python=3.6*
conda install spyder
You don't need to compile Opencv because you can install it with conda.

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.

unable to run opencv with cuda 7.0

I have tried to build and run OpenCV on Ubuntu 14.04. I have previously installed CUDA 7.0 (which is working perfectly with other programs) and when I try to run openCV (opencv_traincascade) I get the following error:
error while loading shared libraries: libcudart.so.6.5: cannot open shared object file: No such file or directory
If I understand correctly, OpenCV expects CUDA v6.5 which is not installed. Does anyone know how to install OpenCV with CUDA 7.0?
try to find libcudart.so.6.5, use find or locate command, make sure it exists or link to the file exists.
then add path to your ~/.bashrc or ~/.profile(or sth else, I add it to bashrc on Ubuntu), like:
PATH=/usr/local/cuda-7.0/bin:$PATH
LD_LIBRARY_PATH=/usr/local/cuda-7.0/lib64:$LD_LIBRARY_PATH
if you change your path to install cuda, use your real path instead.

Installing OpenCV in Ubuntu 14.10

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

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;

Resources