失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > ViSP创建之VS工程详细创建步骤(命令行方式)

ViSP创建之VS工程详细创建步骤(命令行方式)

时间:2023-11-29 16:23:09

相关推荐

ViSP创建之VS工程详细创建步骤(命令行方式)

接上一篇文章:配置好VISP

Windows系统基于VS编译器编译获得VISP动态库Win32的Debug模式

官网介绍(英文):

How to create and build a project that uses ViSP and CMake on Unix or Windows

接下来介绍了怎么创建该工程

In this tutorial you will learn how to use ViSP either on unix-like operating system (including OSX, Fedora, Ubuntu, Debian, …) or on Windows.

最简单的方式

The easiest way of using ViSP in your project is to use CMake. If you are not familiar with CMake, you can check the tutorial.

用以下的命令可以下载要用到的文件

Note also that all the material (source code and images) described in this tutorial is part of ViSP source code and could be downloaded using the following command:

$ svn export /lagadic/visp.git/trunk/tutorial/image

上面就是说使用CMake工具作为帮助最为简单

CMake官网:

CMake下载

用法:

CMake使用

Quick getting started

快速开始的方法

In this section we show how to build an existing project that uses ViSP as third-party and CMake for the build mechanism. As a use case we will use the image project that is part of ViSP tutorials.

这部分要用的代码包含在源代码

The source code comes from /lagadic/visp/tutorial/image. It contains a set of source files tutorial-viewer.cpp, tutorial-image-viewer.cpp and a CMakeLists.txt file. We show here how to get these files and build them.

后面就是讲解两种操作系统之下的不同配置方法

类unix系统的操作方式:

具体命令从最上方官网复制

windows系统操作方法:

自己敲一遍也挺好的

Advanced getting started

Create a workspace

创建工作空间

We suppose here that you have already setup a workspace and defined VISP_WS environment var.(默认已经完成上面的步骤)

We recall here after the instructions to create a workspace:

Enter VISP_WS folder and create a new folder let say started that will contain your first project that uses ViSP as third-party:

Get tutorial-viewer.cpp file

Let’s start to write our first C++ example to see how to read an image and open a window to display the image with ViSP. This example is provided in tutorial-viewer.cpp example and given below.(写我们第一个cpp代码)

Open your favorite editor and copy/paste the content of this example in VISP_WS/started/tutorial-viewer.cpp source file.(随意用什么编辑器书写都行)

The code to copy/paste is the following:(复制或者敲出来如下代码)

#include <visp3/gui/vpDisplayD3D.h>#include <visp3/gui/vpDisplayGDI.h>#include <visp3/gui/vpDisplayGTK.h>#include <visp3/gui/vpDisplayOpenCV.h>#include <visp3/gui/vpDisplayX.h>#include <visp3/io/vpImageIo.h>int main(int argc, char **argv){if (argc != 2) {printf("Usage: %s <image name.[pgm,ppm,jpeg,png,tiff,bmp,ras,jp2]>\n", argv[0]);return -1;}vpImage<vpRGBa> I;try {vpImageIo::read(I, argv[1]);} catch (...) {std::cout << "Cannot read image \"" << argv[1] << "\"" << std::endl;return -1;}try {#if defined(VISP_HAVE_X11)vpDisplayX d(I, vpDisplay::SCALE_AUTO);#elif defined(VISP_HAVE_GDI)vpDisplayGDI d(I, vpDisplay::SCALE_AUTO);#elif defined(VISP_HAVE_OPENCV)vpDisplayOpenCV d(I, vpDisplay::SCALE_AUTO);#elif defined(VISP_HAVE_GTK)vpDisplayGTK d(I, vpDisplay::SCALE_AUTO);#elif defined(VISP_HAVE_D3D9)vpDisplayD3D d(I, vpDisplay::SCALE_AUTO);#elsestd::cout << "No image viewer is available..." << std::endl;#endifvpDisplay::setTitle(I, "My image");vpDisplay::display(I);vpDisplay::flush(I);std::cout << "A click to quit..." << std::endl;vpDisplay::getClick(I);} catch (const vpException &e) {std::cout << "Catch an exception: " << e << std::endl;}}

Here is the detailed explanation of the source, line by line:

下面是具体解释

#include <visp3/gui/vpDisplayD3D.h>#include <visp3/gui/vpDisplayGDI.h>#include <visp3/gui/vpDisplayGTK.h>#include <visp3/gui/vpDisplayOpenCV.h>#include <visp3/gui/vpDisplayX.h>

Include all the headers for image viewers.The twofirst one are forWindows systems. They require thatDirect 3Dor theGraphical Device Interface (GDI)coming with the installation ofVisual Studioare available.The thirdone needs GTK that is cross-platform.The fourthis for unix-like systems and requires that libX11 is available.The lastone is also cross-platform and requires that OpenCV is available.

五个分别在什么条件下用的

#include <visp3/io/vpImageIo.h>

Include the header that allows to read/write PGM, PPM, PNG and JPEG images from the disk using vpImageIo class.(包含这个可以操作图片文件)

vpImage<vpRGBa> I;

Create an instance of a color image where each pixel is coded in RGBa.

try {vpImageIo::read(I, argv[1]);} catch (...) {std::cout << "Cannot read image \"" << argv[1] << "\"" << std::endl;return -1;}

The image I is initialized by reading an image file from the disk. If the image format is not supported we throw an exception.

#if defined(VISP_HAVE_X11)vpDisplayX d(I, vpDisplay::SCALE_AUTO);#elif defined(VISP_HAVE_GDI)vpDisplayGDI d(I, vpDisplay::SCALE_AUTO);#elif defined(VISP_HAVE_OPENCV)vpDisplayOpenCV d(I, vpDisplay::SCALE_AUTO);#elif defined(VISP_HAVE_GTK)vpDisplayGTK d(I, vpDisplay::SCALE_AUTO);#elif defined(VISP_HAVE_D3D9)vpDisplayD3D d(I, vpDisplay::SCALE_AUTO);#elsestd::cout << "No image viewer is available..." << std::endl;#endif

Create an instance of an image display window for image I. (为该图片创建窗口显示)

The first viewer that is available is used. Here we create the link between the image I and the display d. Note that an image can only have one display.(把两个链接起来,一一对应关系)

vpDisplay::setTitle(I, "My image");

The title of the display is then set to “My image”.(设置标题)

vpDisplay::display(I);vpDisplay::flush(I);

First we display the content of the image I, then we flush the display to render the image.

vpDisplay::getClick(I);

Here we handle mouse events. We are waiting for a blocking mouse click to end the program.

上面这个例子简单说明了一下使用的方式。

Get CMakeLists.txt file

书写CMakeLists.txt文件的方法

Now you have to create a CMakeLists.txt file that gives the instructions on how to build tutorial-viewer.cpp example. A minimalistic CMakeLists.txt should contain the following lines.

一般的格式如下

Open your editor and copy/paste the following lines in VISP_WS/started/CMakeLists.txt file.

敲入或者复制下面的代码

project(tutorial-image)cmake_minimum_required(VERSION 3.0)find_package(VISP REQUIRED)include_directories(${VISP_INCLUDE_DIRS})//安装路径add_executable(tutorial-viewer tutorial-viewer.cpp)target_link_libraries(tutorial-viewer ${VISP_LIBRARIES})//具体库的名字和路径

Here after we explain the content of the CMakeLists.txt file.(解释一下这个文件格式)

这个比较容易理解,可以搜一些其他的关于这个文件如何书写

The find_package() CMake command searches for a VISPConfig.cmake file that will define the corresponding variables:

VISP_INCLUDE_DIRS : ViSP and third-party headers locationVISP_LIBRARIES : ViSP and third-party libraries name and location

Note that the previous CMakeLists.txt file can also be:

project(tutorial-image)cmake_minimum_required(VERSION 3.0)find_package(VISP REQUIRED)if(VISP_FOUND)include(${VISP_USE_FILE})endif(VISP_FOUND)add_executable(tutorial-viewer tutorial-viewer.cpp)

where VISP_USE_FILE variable is set to the full path to VISPUse.cmake file that contains all the CMake material that allow to build your project with ViSP.

In other terms, the line

include(${VISP_USE_FILE})

will include the following lines to your CMakeFile.txt

(也就是说这一个包含了两者的内容)

include_directories(${VISP_INCLUDE_DIRS})link_libraries(${VISP_LIBRARIES})

Get monkey.ppm file

Get monkey.ppm image and copy it to VISP_WS/started either:

copying it from ViSP source code; the file is in

VISP_WS/tutorial/image/monkey.ppmusing Subversion:

svn export /lagadic/visp.git/trunk/tutorial/image/monkey.ppm

by copy/paste from GitHub using the Raw button

接下来本来原文是介绍了两种操作系统的方法,我们只要用windows的。

On windows operating system

We suppose from now, that you have created a folder %VISP_WS%\started that contains CMakeLists.txt, tutorial-viewer.cpp and monkey.ppm files.(假设我们已经完成上面步骤了)

Create a build folder

Proceed now as with any other project using CMake by first creating a build folder:

C:\> cd %%VISP_WS%\startedC:\> mkdir build

Configure your project

Launch “CMake (cmake-gui)” from Windows “Start” menu. Set the source

code location as %VISP_WS%\started and the build location to

%VISP_WS%\started\build folder.

也就是类似于我们平时的操作,上面是被编译的,下面是编译到的地址。

Press “Configure” button and select your compiler. In our case we will use Visual Studio 15 Win64.

选择编译器

Press then “Finish” button. The configuration is now under progress and should lead to the following image.

点击完成按钮后应该出现这样界面

In the previous image you may notice that CMake has automatically found the location of ViSP install folder; %VISP_WS/visp-build-vc15/install. This was possible because you Set VISP_DIR environment var.

这种情况是可能发生的

Press then “Configure” button to remove the red lines, and then “Generate” button. As presented in the following image, all the red lines should disappear.

按下Configure按键再按下Generate按键,变成下面的,红色消失

From now, in %VISP_WS%\started\build folder you should have tutorial-image.sln Visual Studio solution file.

这样就可以创建VS工程了

Generate the executable

Open the project in Visual Studio C++ just by double click on

%VISP_WS%\stated\build\tutorial-image.sln solution file.Modify the configuration to “Release”

Now to build the solution, enter “BUILD > Build Solution” menu or hit Ctrl+Shift+B keys.

In %VISP_WS%\started\build\Release folder you have now

tutorial-viewer.exe executable.

Run the executable

运行可执行文件

In your “Start” menu click on “Run” and type in cmd.exe to run a

Command Prompt.

Enter in %VISP_WS%\started\build\Release folder, and run

tutorial-viewer.exe with an image location as argument:

C:\> cd %VISP_WS%\started\build\ReleaseC:\> tutorial-viewer ..\..\monkey.ppm

Here is a screen shot of the resulting output window :

得到结果

如果觉得《ViSP创建之VS工程详细创建步骤(命令行方式)》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。