妙算(manifold)上cuda、opencv以及qt的配置

回家第一天,配置妙算环境成功,写篇博客记录下过程,(之前配置qt一直没成功= =vs用多了vim实在用不惯)。

一、安装CUDA(同官方PDF)
1. 访问下链接:
http://developer.download.nvidia.com/embedded/L4T/r21_Release_v3.0/cuda-repo-l4t-r21.3-
6-5-prod_6.5-42_armhf.deb
2. 执行以下命令安装 “cuda-repo-l4t-r21.3-6-5-prod_6.5-42_armhf.deb”至操作系统。

sudo dpkg -i cuda-repo-l4t-r21.3-6-5-prod_6.5-42_armhf.deb
sudo apt-get update
sudo apt-get install cuda-toolkit-6-5
具体请参考以下链接:https://developer.nvidia.com/embedded/linux-tegra

(想跑CUDA例程的可参考http://blog.csdn.net/FRD2009041510/article/details/42042807)

二、安装OpenCV

(这一步主要参照两个网站

1.http://blog.csdn.net/FRD2009041510/article/details/42930113   //图文教程挺详细的

2.http://elinux.org/Jetson/Installing_OpenCV)

1.安装 OpenCV4tegra
访问以下链接以下载安装包“ libopencv4tegra-repo_l4t-r21_2.4.10.1_armhf.
deb ”
http://developer.download.nvidia.com/embedded/OpenCV/L4T_21.2/libopencv4tegra-repo_
l4t-r21_2.4.10.1_armhf.deb   //最新的库版本是2.4.12了
执行以下命令进行安装

sudo dpkg -i libopencv4tegra-repo_l4t-r21_2.4.10.1_armhf.deb
sudo apt-get update
sudo apt-get install libopencv4tegra libopencv4tegra-dev

2.安装函数库

sudo add-apt-repository universe
sudo apt-get update
# Some general development libraries
sudo apt-get install build-essential make cmake cmake-curses-gui g++
# libav video input/output development libraries
sudo apt-get install libavformat-dev libavutil-dev libswscale-dev
# Video4Linux camera development libraries
sudo apt-get install libv4l-dev
# Eigen3 math development libraries
sudo apt-get install libeigen3-dev
# OpenGL development libraries (to allow creating graphical windows)
sudo apt-get install libglew1.6-dev
# GTK development libraries (to allow creating graphical windows)
sudo apt-get install libgtk2.0-dev

3.安装opencv源码

①.下载源码(推荐2.4.10)

 

https://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.10/


②.解压

 
  
cd Downloads
unzip opencv-2.4.10.zip
mv opencv-2.4.10 ~

③.Make

cd ~/opencv-2.4.10
mkdir build
cd build
cmake -DWITH_CUDA=ON -DCUDA_ARCH_BIN="3.2" -DCUDA_ARCH_PTX="" -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF ..
sudo make -j4 install

 
  ④.配置环境变量 
  

echo "# Use OpenCV and other custom-built libraries." >> ~/.bashrc
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/" >> ~/.bashrc
source ~/.bashrc
.测试

第一个例子:边缘提取

# Test a simple OpenCV program. Creates a graphical window, hence you should plug a HDMI monitor in or use a remote viewer such as X Tunneling or VNC or TeamViewer on your desktop.
cd ~/opencv-2.4.10/samples/cpp
g++ edge.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -o edge
(Or for OpenCV 3.0: g++ edge.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs -o edge)
./edge
第二个例子:摄像头图像的拉普拉斯变换

# If you have a USB webcam plugged in to your board, then test one of the live camera programs and linking to every OpenCV module.
g++ laplace.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_calib3d -lopencv_contrib -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_video -lopencv_videostab -o laplace
(Or for OpenCV 3.0: g++ laplace.cpp -lopencv_adas -lopencv_bgsegm -lopencv_bioinspired -lopencv_calib3d -lopencv_ccalib -lopencv_core -lopencv_datasets -lopencv_face -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_latentsvm -lopencv_line_descriptor -lopencv_ml -lopencv_objdetect -lopencv_optflow -lopencv_photo -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_surface_matching -lopencv_text -lopencv_tracking -lopencv_videoio -lopencv_video -lopencv_videostab -lopencv_xfeatures2d -lopencv_ximgproc -lopencv_xobjdetect -lopencv_xphoto -o laplace)
./laplace
第三个例子:CPU和GPU进行图像的霍夫变换

# Test a GPU accelerated OpenCV sample.
cd ../gpu
g++ houghlines.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_calib3d -lopencv_contrib -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_video -lopencv_videostab -o houghlines
./houghlines ../cpp/logo_in_clutter.png

三、QT的安装与配置

1.安装,使用apt-get,编译opensource的方法没有通过//不过!!!貌似只安装qtcreater就行了,商店里有

sudo apt-get install qt4-dev-tools #开发包   
sudo apt-get install qtcreator #IDE  
sudo apt-get install qt4-doc #开发帮助文档   
sudo apt-get install qt4-qtconfig #配置工具   
sudo apt-get install qt4-demos #DEMO源码  QT
2 .配置

①.打开qt->Tools->Options->Build&Run

②.配置Qt Versions以及Compilers

在termial中输入which qmake以及which gcc把相应的地址添加进去

妙算(manifold)上cuda、opencv以及qt的配置_第1张图片

妙算(manifold)上cuda、opencv以及qt的配置_第2张图片

妙算(manifold)上cuda、opencv以及qt的配置_第3张图片

妙算(manifold)上cuda、opencv以及qt的配置_第4张图片

3.测试

新建一个控制台工程

在main.c中加入

#include 
#include 
#include 
#include 
#include 
#include 

using namespace cv;
using namespace std;

int main(int argc, char *argv[])
{
//    QCoreApplication a(argc, argv);

    namedWindow( "src", WINDOW_AUTOSIZE );
    printf("hello lena\n");
    Mat src1 = imread( "lena.jpg" );
    while(1)
    {
        imshow( "src", src1 );
        char c =  waitKey(30);
        if( 27==c )
            return 0;
    }

//    return a.exec();
}
在.pro文件中加入

SOURCES += main.cpp
INCLUDEPATH += /usr/local/include \
                /usr/local/include/opencv \
                /usr/local/include/opencv2

LIBS += /usr/local/lib/libopencv_highgui.so \
        /usr/local/lib/libopencv_core.so    \
        /usr/local/lib/libopencv_imgproc.so

在生成的调试文件夹中放入lena.jpg
然后运行

妙算(manifold)上cuda、opencv以及qt的配置_第5张图片


大功告成啦!

你可能感兴趣的:(OPENCV)