如何进行TX1使用OpenCV3.1实时采集视频图像的分析
本篇文章为大家展示了如何进行TX1使用OpenCV3.1实时采集视频图像的分析,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
嵌入式平台(Target): Jeston TX1
OpenCV: OpenCV3.1
摄像头: USB 800W摄像头
1 前言
Jetpack3.0安装的OpenCV是OpenCV2.4.13,OpenCV2.4.13对于USB摄像头支持不好。NVIDIA以后更新的Jetpack会解决对USB摄像头支持不好的问题,在官方解决之前,一个临时的解决方案就是自己编译OpenCV3.1。
2 下载OpenCV3
URL : http://www.opencv.org/releases.html
点击Sources下载源码:
3 安装依赖库
# 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
4 编译并安装OpenCV3
cd ~mkdir srccd srcunzip ~/Downloads/opencv-3.1.0.zipcd opencv-3.1.0mkdir buildcd buildcmake -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
5 运行hog例程
5.1 编译并运行例程
cd ~/src/opencv-3.1.0/samples/gpug++ -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,这个只是临时添加,永久添加可以放到~/.bashrc中,并使用source ~/.bashrc"激活"设置的环境变量;
./hog -camera 0:最后一个参数0,代表使用/dev/video0设备,如果TX1插上板载的CSI摄像头,又插上USB摄像头,这个0,应该改为1。可以通过ls /dev/ | grep video*,查看有那些video设备。
5.2 运行结果
6 编写简单的摄像头采集程序
6.1 代码如下
#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; }
6.2 运行结果
PS : 阳光原因,图像有些泛白,见谅
7 可能遇到的问题
在make的时候,我们可能遇到如下error:
解决办法:需要修改一处源码,在graphcuts.cpp中将
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)
改为:
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)
如下图所示:
上述内容就是如何进行TX1使用OpenCV3.1实时采集视频图像的分析,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注行业资讯频道。