环境:CB A10 + lubuntu1.05 + opencv2.6.4.1
准备:2G以上空闲空间. 直接在CB上编译,交叉编译可参见:移植Qt和OpenCV做图像处理方面的开发中matson的提示
Arm-linux-gnueabihf-
要用硬浮点的compiler (说明:我没做过交叉编译,因为直接编译成功了。但在CB上直接编译我等了足足2个小时才编译完,可见速度之慢,当然,这与我在SD卡上编译也有关系。SD卡只有1.8G,果断把我坑得好惨,编译到93%的时候空间不足 ,幸好Cmake和make有记忆功能,我把相应文件拷到4G的U盘中,挂载到相同的目录下,直接从93%开始往下编译,还不是很坑。)
个人下载地址:opencv2.6.4.1
官方下载地址:lubuntu1.05 + opencv
主要过程如下:
1. 安装与opencv相关的包和工具
2. make && sudo make install
3. gcc -ggdb `pkg-config --cflags opencv` -o opencv0 opencv0.c `pkg-config --libs opencv`
1. 安装与opencv相关的包和工具:
install.sh- #!/bin/bash
- apt-get install build-essential -y
- apt-get install cmake -y
- apt-get install pkg-config -y
- apt-get install libpng12-0 libpng12-dev libpng++-dev libpng3 -y
- apt-get install libpnglite-dev libpngwriter0-dev libpngwriter0c2 -y
- apt-get install zlib1g-dbg zlib1g zlib1g-dev -y
- apt-get install libjasper-dev libjasper-runtime libjasper1 -y
- apt-get install pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools -y
- apt-get install libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-prog -y
- apt-get install ffmpeg libavcodec-dev libavcodec52 libavformat52 libavformat-dev -y
- apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev -y
- apt-get install libxine1-ffmpeg libxine-dev libxine1-bin -y
- apt-get install libunicap2 libunicap2-dev -y
- apt-get install libdc1394-22-dev libdc1394-22 libdc1394-utils -y
- apt-get install swig -y
- apt-get install libv4l-0 libv4l-dev -y
- apt-get install python-numpy -y
- apt-get install libgtk2.0-deb -y
- apt-get install libavformat-dev libswscale-dev -y
- ######you can not install follow pakage if you donot need follow.
- apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk <font color="Red">libtbb-dev</font> 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 -y
- apt-get install libpython2.6 python-dev python2.6-dev -y # Only if you want to use python
复制代码 (说明:有些软件找不到,如可选项中的libtbb-dev,确实有那么几个软件没装,不过不影响使用,无所谓了。细心的人会发现,前面一部分是官方要求下的,后面一部分,网上乱搜乱装的。因为安装opencv之前没装libgtk2.0-deb,所以大装特装,再重装 ,果断不再失败)
sudo chmod +x install.sh
sudo ./install.sh
2. make && sudo make install:- $ cmake CMakeLists.txt
- $ make && sudo make install
- $ sudo leafpad /etc/ld.so.conf
- /usr/local/lib #add in the last line.
- $ ldconfig
复制代码 (说明:在相应的目录下执行相应的命令,解压opencv.XX后,cd 到opencv.XX, 然后执行上面的一系列命令,注意你的磁盘格式,要支持链接哦,不然只有格式化成其它形式,我用的是ext4格式, 检测可使用命令: ln -s filenamea filenameb;
修改/etc/ld.so.conf是将opencv的库加入系统路径中,不然会报找不到XXX.so的错误,opencv默认安装到/usr/local/lib,这可以从sudo make install 的输出看出来,记得保存输出,出了错方便谷歌\百度\论坛)
3. gcc -ggdb `pkg-config --cflags opencv` -o opencv0 opencv0.c `pkg-config --libs opencv`
(说明:以上是C语言的编译命令,也可以用C++,opencv源码包中也自带一些例子,这个编译命令就是从里面找出来的,网上的编译命令大多不能用。上面的点是`,在数字键12345那一排,Tab的上面,Esc的下面。使用时也可以直接复制。
opencv0.c 是一个看图片的程序,将图片怎么怎么处理。运行: ./opencv0.c opencv1.bmp
video0.c 是一个使用摄像头的程序,lubuntu1.05 自带驱动,官方支持的USB摄像头应该都能用,我用的环宇飞扬V6。
运行 ./video0 )
opencv0.c- #include "stdlib.h"
- #include "stdio.h"
- #include "math.h"
- #include "cv.h"
- #include "highgui.h"
- int main(int argc, char *argv[])
- {
- IplImage* img = 0; //IPL(Intel Image Processing Library)图像头
- int height, width, step, channels;
- uchar* data;
- int i, j, k;
- if (argc < 2)
- {
- printf("Usage: main<image-file-name>\n\7");
- exit(0);
- }
- // 加载图片
- img = cvLoadImage(argv[1],0);
- if (!img)
- {
- printf("Could not load image file: %s\n", argv[1]);
- exit(0);
- }
- // 获得图像数据
- height = img->height;
- width = img->width;
- step = img->widthStep;
- channels = img->nChannels;
- data = (uchar*)img->imageData;
- printf("Processing a %d x %d image with %d channels\n", height, width, channels);
- // 创建窗体
- cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
- cvMoveWindow("mainWin", 100, 100);
- // 翻转图像
- for(i = 0; i < height; i++)
- {
- for(j = 0; j < width; j++)
- {
- for(k = 0; k < channels; k++)
- {
- data[i * step + j * channels] = 255 - data[i * step + j * channels + k];
- }
- }
- }
- // 显示图像
- cvShowImage("mainWin", img);
- // 等待一个任意键
- cvWaitKey(0);
- // 释放图像
- cvReleaseImage(&img);
- return 0;
- }
复制代码 video0.c- //#include "stdafx.h"
- #include "cv.h"
- #include "highgui.h"
- #include "stdio.h"
- // 实现将拍下来的图片缩放一倍
- IplImage* DoPyrDown(IplImage* image)
- {
- // 设置大小缩小一倍
- CvSize size = cvSize(image->width / 2,image->height / 2);
- //初始化图片
- IplImage* outImage = cvCreateImage(size,image->depth,image->nChannels);
- //实现缩放
- cvPyrDown(image,outImage,CV_GAUSSIAN_5x5);
- cvReleaseImage(&image);
- return outImage;
- };
- int main(int argc, char** argv)
- {
- cvNamedWindow("vedio",0);
- CvCapture* capture;
- // 首先是要通过摄像设备来得到一个CvCapture对象
- if(1 == argc)
- {
- capture = cvCreateCameraCapture(0);
- }
- else
- {
- capture = cvCreateCameraCapture(atoi(argv[1]));
- }
- assert(NULL != capture);
- IplImage* frame;
- char keyCode;
- // 每隔30ms捕捉一次视频图像
- // 可以设为while(1) 使得实时捕捉视频画面
- while((keyCode = cvWaitKey(30)))
- {
- //表示按下了ESC键,退出
- if(keyCode == 27)
- {
- break;
- }
- //表示按下了回车键,此时应当保存照片
- if(keyCode == 13)
- {
- //初始化一张图片
- IplImage* outImage = cvCreateImage(cvGetSize(frame),frame->depth,frame->nChannels);
- // 将原图拷贝过来
- cvCopy(frame,outImage,NULL);
- //实现缩放操作
- outImage = DoPyrDown(outImage);
- //设置保存的图片名称和格式
- char* outImageName = "test.jpg";
- //保存图片
- cvSaveImage(outImageName,outImage,0);
- cvReleaseImage(&outImage);
- printf(" 恭喜你,保存图片成功!\n");
- }
- // 得到摄像设备的下一帧图像
- frame = cvQueryFrame(capture);
- if(!frame)
- {
- break;
- }
- cvShowImage("vedio",frame);
- }
- cvReleaseImage(&frame);
- cvDestroyAllWindows();
- return 0;
- }
复制代码 |