ubuntu12.04 opencv2.4.1编译自己的例子
2012-11-07 12:45
316 查看
编译命令:
g++ -o test test.cpp `pkg-config opencv --cflags --libs`
若用:
g++ `pkg-config --cflags --libs opencv` -o test test.cpp
会出错:
/tmp/ccIHQrph.o: In function `main':
test.cpp:(.text+0x6c): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
test.cpp:(.text+0x10c): undefined reference to `cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
test.cpp:(.text+0x13a): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
安装过程:(转载)
http://www.samontab.com/web/2012/06/installing-opencv-2-4-1-ubuntu-12-04-lts/
The latest Long Term Support version of Ubuntu(12.04 LTS) is out and a new version of OpenCV was released as well. This means that now is a great opportunity to update my OpenCV installation guide to the latest versions, Ubuntu 12.04 LTS and OpenCV 2.4.1.
We are going to setup OpenCV to use the new Qt highgui interface, which is much better than the simple highgui interface. Also, we will install OpenCV with support for OpenGL, as well as reading and writing videos, access to a webcam, Python, C and C++ interfaces,
and Intel Threading Building Blocks (TBB).
OK, so the first step is to make sure that everything in the system is updated and upgraded:
Now, you need to install many dependencies, such as support for reading and writing image files, drawing on the screen, some needed tools, etc… This step is very easy, you only need to write the following command in the Terminal:
Time to get the OpenCV 2.4.1 source code:
Now we have to generate the Makefile by using cmake. In here we can define which parts of OpenCV we want to compile. Since we want to use Python, TBB, OpenGL, Qt, work with videos, etc, here is where we need to set that. Just execute the following line at
the terminal to create the appropriate Makefile. Note that there are two dots at the end of the line, it is an argument for the cmake program and it means the parent directory (because we are inside the build directory, and we want to refer to the OpenCV directory,
which is its parent).
Check that the above command produces no error and that in particular it reports FFMPEG as YES. If this is not the case you will not be able to read or write videos. Also, check that Python, TBB, OpenGL, V4L, OpenGL and Qt are detected.
If anything is wrong, go back, correct the errors by maybe installing extra packages and then run cmake again. You should see something similar to this:
Now, you are ready to compile and install OpenCV 2.4.1:
Now you have to configure OpenCV. First, open the opencv.conf file with the following code:
Add the following line at the end of the file(it may be an empty file, that is ok) and then save it:
Run the following code to configure the library:
Now you have to open another file:
Add these two lines at the end of the file and save it:
Finally, close the console and open a new one, restart the computer or logout and then login again. OpenCV will not work correctly until you do this.
Now you have OpenCV 2.4.1 installed in your computer with Python, TBB, OpenGL, video, and Qt support.
Check out the cool Qt interface which provides image viewing capabilities with zoom, as well as the ability to save the current image with just one click.
If you zoom in enough, you can see the RGB (or intensity) values for each pixel.
Now let’s build some samples included in OpenCV:
Now we are ready to run the examples:
Posted in
Image Processing,
Programming.
g++ -o test test.cpp `pkg-config opencv --cflags --libs`
若用:
g++ `pkg-config --cflags --libs opencv` -o test test.cpp
会出错:
/tmp/ccIHQrph.o: In function `main':
test.cpp:(.text+0x6c): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
test.cpp:(.text+0x10c): undefined reference to `cv::namedWindow(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
test.cpp:(.text+0x13a): undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
安装过程:(转载)
http://www.samontab.com/web/2012/06/installing-opencv-2-4-1-ubuntu-12-04-lts/
The latest Long Term Support version of Ubuntu(12.04 LTS) is out and a new version of OpenCV was released as well. This means that now is a great opportunity to update my OpenCV installation guide to the latest versions, Ubuntu 12.04 LTS and OpenCV 2.4.1.
We are going to setup OpenCV to use the new Qt highgui interface, which is much better than the simple highgui interface. Also, we will install OpenCV with support for OpenGL, as well as reading and writing videos, access to a webcam, Python, C and C++ interfaces,
and Intel Threading Building Blocks (TBB).
OK, so the first step is to make sure that everything in the system is updated and upgraded:
1 | sudo apt-get update |
2 | sudo apt-get upgrade |
1 | sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev |
1 | cd ~ |
2 | wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.1/OpenCV-2.4.1.[/code]tar.bz2 |
3 | tar -xvf OpenCV-2.4.1. tar .bz2 |
4 | cd OpenCV-2.4.1 |
the terminal to create the appropriate Makefile. Note that there are two dots at the end of the line, it is an argument for the cmake program and it means the parent directory (because we are inside the build directory, and we want to refer to the OpenCV directory,
which is its parent).
1 | mkdir build |
2 | cd build |
3 | cmake -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 .. |
If anything is wrong, go back, correct the errors by maybe installing extra packages and then run cmake again. You should see something similar to this:
Now, you are ready to compile and install OpenCV 2.4.1:
1 | make |
2 | sudo make install |
1 | sudo gedit /etc/ld.so.conf.d/opencv.conf |
1 | /usr/ local /lib |
Run the following code to configure the library:
1 | sudo ldconfig |
1 | sudo gedit /etc/ bash .bashrc |
1 | PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/ local /lib/pkgconfig |
2 | export PKG_CONFIG_PATH |
Finally, close the console and open a new one, restart the computer or logout and then login again. OpenCV will not work correctly until you do this.
Now you have OpenCV 2.4.1 installed in your computer with Python, TBB, OpenGL, video, and Qt support.
Check out the cool Qt interface which provides image viewing capabilities with zoom, as well as the ability to save the current image with just one click.
If you zoom in enough, you can see the RGB (or intensity) values for each pixel.
Now let’s build some samples included in OpenCV:
1 | cd ~/OpenCV-2.4.1/samples/c |
2 | chmod +x build_all.sh |
3 | ./build_all.sh |
1 | ./facedetect --cascade= "/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg |
1 | ./facedetect --cascade= "/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml" --nested-cascade= "/usr/local/share/OpenCV/haarcascades/haarcascade_eye.xml" --scale=1.5 lena.jpg |
1 | ~/OpenCV-2.4.1/build/bin/grabcut ~/OpenCV-2.4.1/samples/cpp/lena.jpg |
1 | ~/OpenCV-2.4.1/build/bin/calibration_artificial |
1 | python ~/OpenCV-2.4.1/samples/python2/turing.py |
Posted in
Image Processing,
Programming.
相关文章推荐
- ubuntu12.04安装OpenCv2.4.1并编译测试
- MAC os下自己编译opencv源码得到opencv2.framework的简单使用例子
- ubuntu12.04上Using cairo with OpenGL 例子编译
- 秒算下自己编译安装opencv
- Ubuntu12.04上Opencv的编译与安装
- ubuntu安装opencv(自己编译)
- ubuntu12.04交叉编译opencv移植到arm板
- ubuntu12.04 升级自己编译的内核
- ubuntu12.04编译安装opencv2.4.8过程记录
- 使用命令行编译打包运行自己的MapReduce程序 Hadoop2.4.1
- ubuntu12.04下Python 3.5.3 +OpenCV 3.2.0编译环境搭建
- Opencv3.2+VS2015环境配置(VS2015以下版本需要自己编译dll)
- Ubuntu12.04利用CMake-2.8.10.4编译OpenCV-2.4.4
- Windows下编译自己的opencv3.1库
- Win8(win7) x64位OS + VS2012 + OpenCV2.4.5 + CMake2.8 + TBB42自己编译OpenCV
- ubuntu12.04交叉编译opencv移植到arm板
- ubuntu12.04 安装 opencv 2.4.8(非源代码编译)
- Opencv3.2+VS2015环境配置(VS2015以下版本需要自己编译dll)
- ubuntu12.04安装opencv2.4.1
- 如何降低自己的gcc版本--解决ubuntu12.04编译layer的问题