Installing OpenCV in Ubuntu 14.10

99封情书 提交于 2019-12-30 02:29:06

问题


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?


回答1:


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.




回答2:


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.




回答3:


You can try to build without a ffmpeg:

cmake -DCMAKE_BUILD_TYPE=RELEASE -DWITH_FFMPEG=OFF ..
make
sudo make install


来源:https://stackoverflow.com/questions/26592577/installing-opencv-in-ubuntu-14-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!