///
//源码安装cmake
1.下载cmake源码cmake-2.6.2.tar.gz,http://www.cmake.org/cmake/resources/software.html
2.编译安
tar xvf cmake-2.6.2.tar.gz
cd cmake-2.6.2/
//如果本机上不存在cmake,则:
./bootstrap
make
make install
//如果本机上存在cmake,想安装一个新版本,则:
cmake .
make
make install
参考:http://blog.csdn.net/sallyanna000/article/details/6579158
///
//源码安装opencv
1.下载opencv,http://www.opencv.org.cn/index.php/Download
2.安装opencv-2.3.0
tar -xvf OpenCV-2.3.0.tar.bz2
cd OpenCV-2.3.0/
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..
make
sudo make intall
3.添加库路径
sudo vim /etc/ld.so.conf.d/opencv.conf
/usr/local/lib(添加内容)
4.更新系统库
$sudo ldconfig
5.设置环境变量
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
6.测试
cd samples/c
chmod +x build_all.sh
./build_all.sh
./facedetect --cascade="/usr/local/share/opencv/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg
可以看到以下图片,说明opencv 安装正常
参考:http://www.linuxdiyf.com/viewarticle.php?id=205585
///
//编译执行第一个C实现的OpenCV程序
//OpenCV参考手册:http://www.opencv.org.cn/index.php
1.程序代码show.c
#include "cv.h"
#include "highgui.h"
int main(int argc, char **argv)
{
IplImage* pImage;
if(argc==2 && (pImage=cvLoadImage(argv[1],1))!=0)
{
cvNamedWindow("Image",1);
cvShowImage("Image",pImage);
cvWaitKey(0);
cvDestroyWindow("Image");
cvReleaseImage(&pImage);
return 0;
}
return -1;
}
2.编译代码
[kang@Gala opencv]$ gcc show.c -o show
show..c:1:16: error: cv.h: No such file or directory
show..c:2:21: error: highgui.h: No such file or directory
show..c: In function ‘main’:
show..c:6: error: ‘IplImage’ undeclared (first use in this function)
show..c:6: error: (Each undeclared identifier is reported only once
show..c:6: error: for each function it appears in.)
show..c:6: error: ‘pImage’ undeclared (first use in this function)
show..c:7: error: subscripted value is neither array nor pointer
由于highgui中采用了C++,所以一定要用g++编译才可以,编译命令如下:
//直接编译链接
g++ `pkg-config --cflags opencv` -o show show.c `pkg-config --libs opencv`
//先编译再链接:
g++ `pkg-config --cflags opencv` -c show.c
g++ `pkg-config --libs opencv` -o show show.o
再次编译,出现下述错误信息:
[kang@Gala opencv]$ g++ `pkg-config --cflags opencv` -c show.c
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
解决方法是将/usr/local/lib/pkgconfig中的opencv.pc拷贝到/usr/lib/pkgconfig中,否则程序将无法编译
sudo cp /usr/local/lib/pkgconfig/opencv.pc /usr/lib/pkgconf
参考:http://zwlforever.blog.163.com/blog/static/223325552007912929334/ ;http://blog.ednchina.com/fangcao8090/277677/Message.aspx
///
//OpenCV2.3.0 with Python2.6
//OpenCV2.1 Python Reference : http://opencv.willowgarage.com/documentation/python/index.html
1.程序代码show.py
import sys
import cv
if __name__ == '__main__':
image=cv.LoadImage("1.jpg")
cv.NamedWindow("mywin")
cv.ShowImage("mywin",image)
cv.WaitKey(0)
2.执行程序show.py
[kang@Gala opencv]$ python show.py
Traceback (most recent call last):
File "show.py", line 2, in <module>
import cv
ImportError: No module named cv
3.解决办法
[kang@Gala opencv]$ sudo cp /usr/local/lib/python2.6/dist-packages/cv.so /usr/lib/python2.6/site-packages
参考:http://opencv-users.1802565.n2.nabble.com/import-opencv-cv-module-error-in-python-td3741505.html