基於opencv在攝像頭ubuntu根據視頻獲取



基於opencv在攝像頭ubuntu根據視頻獲取


1  工具 原料

    平臺 :UBUNTU12.04html

    安裝庫  Opencv-2.3     python

   

2  安裝編譯執行步驟

   安裝編譯opencv-2.3  參考http://blog.csdn.net/xiabodan/article/details/23547847ubuntu

  提早下載OPENCV源代碼包bash

  官方:http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/ide

 個人:http://download.csdn.net/detail/xiabodan/7176253

             

2

sudo apt-get update工具

sudo apt-get upgrade
ui

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-devspa

             解壓源代碼包.net

3 tar -xvf OpenCV-2.4.1.tar.bz2
4

cd OpenCV-2.4.1unix

1

mkdir build

cmake配置MAKEFILE

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 ..

        而後進行make

1 make
2 sudo make install

        配置opencv

    

1 sudo gedit /etc/ld.so.conf.d/opencv.conf

        Add the following line at the end of the file(it may be an empty file, that is ok) and then save it: 在opencv.conf中加入下面路徑

1 /usr/local/lib

           sudo ldconfig

1

sudo gedit /etc/bash.bashrc

        Add these two lines at the end of the file and save it: 在bash.bashrc中加入下面環境變量

1 PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
2 export PKG_CONFIG_PATH

        sudo   reboot 從新啓動電腦


注意:必定要提早安裝V4L等等庫,否則編譯能過,執行的時候沒有畫面。

   


3  測試代碼

編譯

g++ cameraCaptrue.cpp  -o  cameraCap `pkg-config --libs --cflags opencv`

生成文件cameraCap

執行  採集成功

./cameraCap

cameraCaptrue.cpp

#include<stdio.h>
#include<math.h>
#include "highgui.h"
#include <cv.h>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>

//#include <cvaux.h>
//#include <highgui\highgui_c.h>
//#include <core\types_c.h>
//#include <photo\photo_c.h>
//#include <imgproc\imgproc_c.h>
//#include <photo\photo

using namespace cv;


int main( int argc, char** argv )
{
	printf("I am start \n");
	VideoCapture cap(0); // open the default camera
	if(!cap.isOpened())  // check if we succeeded
		return -1;

	printf("%f, %f\n",cap.get(CV_CAP_PROP_FRAME_WIDTH),cap.get(CV_CAP_PROP_FRAME_HEIGHT));
	cap.set(CV_CAP_PROP_FRAME_WIDTH, 320);
	cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240);
	cap.set(CV_CAP_PROP_FPS, 15);
	printf("%f, %f\n",cap.get(CV_CAP_PROP_FRAME_WIDTH),cap.get(CV_CAP_PROP_FRAME_HEIGHT));
	Mat src_gray;
	cvNamedWindow( "video", CV_WINDOW_AUTOSIZE );

	while(1)
	{
		Mat frame;
		cvWaitKey(10);
		cap >> frame;
		imshow("video", frame);
	}


	return 0;
}



接下來移植到zedboard上去

參考:

     http://www.cnblogs.com/liu-jun/archive/2013/12/24/3489675.html

     http://xuxd32.blog.163.com/blog/static/48121933201192394550140/

ZedBoard-OpenCV打開攝像頭失敗解決方式及過程:

     http://www.openhw.org/wicoboy/blog/13-04/293302_71692.html


      超級天羣博客

     http://www.cnblogs.com/surpassal/

           
     OpenCV移植到ARM 全過程 :點擊打開連接

      【OpenHW12參賽手記】Zedboard-Linux-digilent3.6內核版本號不支持USB攝像頭問題的解決方式  :http://www.eefocus.com/jefby1990/blog/13-03/292301_988aa.html點擊打開連接





相關文章
相關標籤/搜索