opencv3.0的编译安装(ubuntu14.04系统),opencv设置摄像头分辨率并捕获图片

时间:2015-08-04 15:28:20   收藏:0   阅读:1304

搭建C/C++编译环境:sudo apt-get install build-essential

安装关联库:sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev -y

到官网下载好linux源码后拉到ubuntu14.04虚拟机解压并进入opencv目录,切换到root权限

cmake .

make

make install

三部就搞定了,不过make的过程很久很久。注意上面的cmake后面有个空格和一个点.

 

接下来是测试代码,vi img.cpp

/*compile command:
g++ img.cpp -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -o img
*/
#include <opencv/highgui.h>
#include <stdio.h>
//using namespace std;
//using namespace cv;
#define IMAGE_WIDTH   320
#define IMAGE_HEIGHT  240

int main()
{
    IplImage * img;
    CvCapture * cap = cvCreateCameraCapture(0);
    cvSetCaptureProperty(cap, CV_CAP_PROP_FRAME_WIDTH, IMAGE_WIDTH);
    cvSetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT, IMAGE_HEIGHT);
    img = cvQueryFrame(cap); 
    printf("width: %d\t height: %d\t widthStep: %d\n",img->width, img->height, img->widthStep);
    cvSaveImage("img.jpg", img);

    return 0;
}

编译:g++ img.cpp -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -o img

执行:./img

就可以得到一幅指定分辨率的图片img.jpg了。

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!