Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The steps of compiling and installing OpenCV under Ubuntu14.04

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "the compilation and installation steps of OpenCV under Ubuntu14.04". In the daily operation, I believe many people have doubts about the compilation and installation steps of OpenCV under Ubuntu14.04. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "the compilation and installation steps of OpenCV under Ubuntu14.04". Next, please follow the editor to study!

Environment

System: Ubuntu 14.04 x64

Brief introduction

OpenCV, English full name Open Source Computer Vision Library. OpenCV is a cross-platform computer visual library based on (open source) distribution that can run on Linux, Windows and Mac OS operating systems. It is lightweight and efficient-it consists of a series of C functions and a small number of C++ classes, provides interfaces to Python, Ruby, MATLAB and other languages, and implements many general algorithms in image processing and computer vision.

Official home page: http://opencv.org/

Installation package

Download link: http://opencv.org/downloads.html

Installation package: opencv-2.4.10.zip

Please do not download opencv2.3.1, the error of ffmpeg will be reported. In addition, the latest version of opencv3 has a different architecture from opencv2. If you are comfortable with opencv2, don't upgrade opencv3 yet.

Installation

Install the dependency package that compiles opencv

Sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff5 libtiff5-dev cmake cmake-gui libswscale-dev libjasper-dev

Configure opencv, which is configured using cmake-gui here. If you use cmake to configure directly, an error will be reported, which will be described later.

Cd opencv_dir mkdir buildcd build cmake-gui..

The following interface appears, change the settings, untick the WITH-CUDA and BUILD_opencv_gpu options, and then generate the Configure file by clicking the Configure and Generate buttons.

Compile the installation so that the installation is successful.

Makesudo make install environment variable

After successful installation, you also need to set the environment variable of opencv.

Open a file

Sudo gedit / etc/profile # # individuals prefer to put environment variables in / etc/profile, like'~ / .bashrc'

Add at the end of the file

Export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

Execute the following command to make the environment variable take effect immediately

Source / etc/profilelib library path

Open a file

Sudo gedit / etc/ld.so.conf.d/opencv.conf

Generally, new files are created. Opencv libraries are usually installed in the'/ usr/local/lib' folder and added to the files.

/ usr/local/lib

Execute the following order to take effect immediately

Sudo ldconfig

After the above process, you can use opencv in eclipse or qtcreator. However, configure the corresponding path and lib file for the number.

Sample code

Compile and run the sample of opencv

Cd opencv_dir/samples/c./build_all.sh./facedetect-cascade= "/ usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml"-scale=1.5 lena.jpg

Running result

Python uses opencv

If you want to use opencv in python, you use the python virtual environment (http://blog.csdn.net/honyniu/article/details/46382929). You just need to copy the cv2.so compiled by opencv and the original cv.py to the site-packages path of python.

Cp opencv_dir/build/lib/cv2.so ENV/lib/python2.7/site-packages/cp opencv_dir/modules/python/src2/cv.py ENV/lib/python2.7/site-packages/

Simply resize the picture and save the python code

Import cv2 as cvim = cv.imread (IMAGE_FILE) # IMAGE_FILE picture path im = cv.resize (im, (500,500)) cv.imwrite (IMAGE_FILE_CP, im) # IMAGE_FILE_CP error saving picture path

As mentioned above, if you use cmake to configure directly, there will be an error of 'nvcc fatal: Unsupported gpu architecture' compute_11' when performing make compilation, mainly because cmake configuration will choose gpu and cuda options by default, but it seems that in this environment, opencv has not been successful in compiling gpu and cuda (of course, some people are successful, I don't know why), so use the cmake-gui command to choose not to install gpu and cuda. Not installing gpu and cuda will not affect the rest of the work.

Cv2.so not found

To compile opencv_python, you need to rely on the numpy library, you must make sure that when compiling opencv, the configuration file recognizes the numpy library of python to use, as shown below, BUILD_opencv_python and PYTHON_NUMPY_INCLUDER_DIR options can appear (this is automatically identified, you need to install numpy in the default python library of the system), so that you can compile cv2.so normally. If you can't find the numpy library correctly, you need to install numpy first, otherwise you won't be able to compile cv2.so.

At this point, the study on the "compilation and installation steps of OpenCV under Ubuntu14.04" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report