本篇文章為大家展示了如何進(jìn)行TX1使用OpenCV3.1實(shí)時(shí)采集視頻圖像的分析,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
創(chuàng)新互聯(lián)為客戶提供專業(yè)的成都網(wǎng)站制作、做網(wǎng)站、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)、程序、域名、空間一條龍服務(wù),提供基于WEB的系統(tǒng)開發(fā). 服務(wù)項(xiàng)目涵蓋了網(wǎng)頁設(shè)計(jì)、網(wǎng)站程序開發(fā)、WEB系統(tǒng)開發(fā)、微信二次開發(fā)、手機(jī)網(wǎng)站制作等網(wǎng)站方面業(yè)務(wù)。
嵌入式平臺(tái)(Target):Jeston TX1
OpenCV:OpenCV3.1
攝像頭:USB 800W攝像頭
Jetpack3.0安裝的OpenCV是OpenCV2.4.13,OpenCV2.4.13對(duì)于USB攝像頭支持不好。NVIDIA以后更新的Jetpack會(huì)解決對(duì)USB攝像頭支持不好的問題,在官方解決之前,一個(gè)臨時(shí)的解決方案就是自己編譯OpenCV3.1。
URL : http://www.opencv.org/releases.html
點(diǎn)擊Sources下載源碼:
# Some general development librariessudo apt-get install -y build-essential make cmake cmake-curses-gui g++# libav video input/output development librariessudo apt-get install -y libavformat-dev libavutil-dev libswscale-dev# Video4Linux camera development librariessudo apt-get install -y libv4l-dev# Eigen3 math development librariessudo apt-get install -y libeigen3-dev# OpenGL development libraries (to allow creating graphical windows)sudo apt-get install -y libglew1.6-dev# GTK development libraries (to allow creating graphical windows)sudo apt-get install -y libgtk2.0-dev
cd ~ mkdir src cd src unzip ~/Downloads/opencv-3.1.0.zip cd opencv-3.1.0mkdir build cd build cmake -DWITH_CUDA=ON -DCUDA_ARCH_BIN="5.3" -DCUDA_ARCH_PTX="" -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DCUDA_FAST_MATH=ON -DCMAKE_INSTALL_PREFIX=/home/ubuntu/opencv-3.1.0 ..make -j4 install
cd ~/src/opencv-3.1.0/samples/gpu g++ -o hog -I /home/ubuntu/opencv-3.1.0/include -O2 -g -Wall hog.cpp -L /home/ubuntu/opencv-3.1.0/lib -lopencv_core -lopencv_imgproc -l opencv_flann -l opencv_imgcodecs -lopencv_videoio -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_objdetect -lopencv_photo -lopencv_features2d -lopencv_calib3d -lopencv_stitching -lopencv_videostab -lopencv_shape -lopencv_cudaobjdetect -lopencv_cudawarping -lopencv_cudaimgprocexport LD_LIBRARY_PATH=/home/ubuntu/opencv-3.1.0/lib:$LD_LIBRARY_PATH./hog --camera 0
export LD_LIBRARY_PATH=/home/ubuntu/opencv-3.1.0/lib:$LD_LIBRARY_PATH:添加LIBARARY,這個(gè)只是臨時(shí)添加,永久添加可以放到~/.bashrc中,并使用source ~/.bashrc“激活”設(shè)置的環(huán)境變量;
./hog –camera 0:最后一個(gè)參數(shù)0,代表使用/dev/video0設(shè)備,如果TX1插上板載的CSI攝像頭,又插上USB攝像頭,這個(gè)0,應(yīng)該改為1。可以通過ls /dev/ | grep video*,查看有那些video設(shè)備。
#include#include using namespace cv; using namespace std; int main(int argc, char** argv) { VideoCapture cap("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720,format=(string)I420, framerate=(fraction)24/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink"); if (!cap.isOpened()) { cout << "Failed to open camera." << endl; return -1; } for(;;) { Mat frame; cap >> frame; imshow("original", frame); //waitKey(1); if(waitKey(30) >= 0) break; } return 0; }
PS : 陽光原因,圖像有些泛白,見諒
在make的時(shí)候,我們可能遇到如下error:
解決辦法:需要修改一處源碼,在graphcuts.cpp中將
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
改為:
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)
如下圖所示:
上述內(nèi)容就是如何進(jìn)行TX1使用OpenCV3.1實(shí)時(shí)采集視頻圖像的分析,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。