移步至Pylon C++ Programmer's Guide观看效果更佳

Getting Started

pylon编程指南是一个关于如何使用Basler pylon C++ API进行编程的快速指南。它可以与pylon示例代码一起使用,以帮助初学者入门。此外,API renfence提供了有关Basler pylon C++接口的描述。接口的描述也可在pylon的头文件中找到。在使用Microsoft Visual Studio 时,右键点击所需的方法或类,并从上下文菜单中选择“转到声明”,以访问相关的文档。

对于为Basler blaze相机编程的信息,请参考pylon为blaze提供的补充包(可在Basler网站上下载)。这包括了一个C++ API和一个.NET API,以及示例代码。

Common Settings for Building Applications with pylon (Linux)

这一部分展示了使用pylon和GNU工具链构建应用程序的最常见的Linux构建设置。有关更多信息,请查阅Advanced Topics部分。

为了集中管理负责构建基于pylon的应用程序所需的所有参数,我们创建了pylon-config工具。它的工作方式类似于pkg-config,您可以调用pylon-config --help来获取支持的参数列表。

在典型的基于GNU Make的项目中,您可以在Makefile中添加以下行:

PYLON_ROOT ?= /opt/pylon
CPPFLAGS += $(shell $(PYLON_ROOT)/bin/pylon-config --cflags)
LDFLAGS += $(shell $(PYLON_ROOT)/bin/pylon-config --libs-rpath)
LDLIBS += $(shell $(PYLON_ROOT)/bin/pylon-config --libs)

如有需要,您现在可以使用环境变量<PYLON_ROOT>覆盖默认的安装路径。例如:

PYLON_ROOT=/path/to/your/pylon/install make

Initialization/Uninitialization of the pylon Runtime Library

在使用pylon API前必须初始化pylon运行时系统。基于pylon的应用程序在使用pylon运行时系统的任何其他功能之前必须调用PylonInitialize()。应用程序退出前,必须调用PylonTerminate()方法以释放pylon运行时系统分配的资源。

Pylon::PylonAutoInitTerm便利类有助于执行上述操作。Pylon::PylonAutoInitTerm的构造函数调用PylonInitialize(),析构函数调用PylonTerminate()。这确保了在Pylon::PylonAutoInitTerm类型对象的生命周期内,pylon运行时系统被初始化。

示例如下:

#include <pylon/PylonIncludes.h>
using namespace Pylon; int main(int argc, char* argv[])
{ Pylon::PylonAutoInitTerm autoInitTerm; // PylonInitialize() will be called now // Use pylon
// .. } // autoInitTerm's destructor calls PylonTerminate() now

Advanced Topics包含MFC用户的附加信息

Error Handling

在出现错误的情况下,pylon类中的方法可能会抛出C++异常。pylon C++ API抛出的异常类型为GenericException或其子类。您应该使用捕获GenericException的异常处理程序来保护pylon调用。例如:

try
{
camera.Width.SetValue(640);
}
catch (const GenericException & e)
{
cerr << "设置AOI宽度失败。原因:"
<< e.GetDescription() << endl;
}

Creating a pylon Device

在 pylon 中,物理相机设备由pylon Devices表示。以下示例展示了如何创建一个pylon设备:

CInstantCamera camera(CTlFactory::GetInstance().CreateFirstDevice());

创建第一个找到的相机设备,例如用于仅使用一个相机的视觉系统。Advanced Topics展示了如何处理多个相机设备以及如何找到特定的相机设备。

The Instant Camera Classes

即时相机(Instant Camera)类使得仅通过几行代码就可以抓取图像,将编程工作量降至最低。即时相机类内部使用一个pylon设备(ptlon Device)。需要创建pylon设备并将其附加到即时相机对象上以进行操作。

示例:

// Create an instant camera object with the camera device found first.
CInstantCamera camera( CTlFactory::GetInstance().CreateFirstDevice() ); // Print the model name of the camera.
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl; // Start the grabbing of c_countOfImagesToGrab images.
// The camera device is parameterized with a default configuration which
// sets up free-running continuous acquisition.
camera.StartGrabbing( c_countOfImagesToGrab ); // This smart pointer will receive the grab result data.
CGrabResultPtr ptrGrabResult; // Camera.StopGrabbing() is called automatically by the RetrieveResult() method
// when c_countOfImagesToGrab images have been retrieved.
while (camera.IsGrabbing())
{
// Wait for an image and then retrieve it. A timeout of 5000 ms is used.
camera.RetrieveResult( 5000, ptrGrabResult, TimeoutHandling_ThrowException ); // Image grabbed successfully?
if (ptrGrabResult->GrabSucceeded())
{
// Access the image data.
cout << "SizeX: " << ptrGrabResult->GetWidth() << endl;
cout << "SizeY: " << ptrGrabResult->GetHeight() << endl;
const uint8_t* pImageBuffer = (uint8_t*) ptrGrabResult->GetBuffer();
cout << "Gray value of first pixel: " << (uint32_t) pImageBuffer[0] << endl << endl; }
else
{
cout << "Error: " << std::hex << ptrGrabResult->GetErrorCode() << std::dec << " " << ptrGrabResult->GetErrorDescription() << endl;
}
}

上述代码可以在示例代码中的Grab Sample中找到。

The Main Features of an Instant Camera Class

即时相机类为访问相机设备提供了便捷的途径,同时具有高度的可定制性。以下列表展示了即时相机类的主要功能:

  • 它作为单一访问点用于访问相机功能。
  • 它可以“开箱即用”,无需设置任何参数。相机使用设备的默认配置。默认配置可以被覆盖。
  • 它管理pylon设备的生命周期。
  • 它自动打开和关闭pylon设备。
  • 它处理缓冲区的创建、重用和销毁。
  • 如有需要,它提供一个抓取循环线程。
  • 它可以检测相机设备的移除。
  • 它支持高级相机功能,如块模式和事件报告(相机事件)。
  • 可以通过派生来扩展。
  • 可以通过注册额外的事件处理器对象来扩展。

Types of Instant Camera Classes

在开始编程之前,你需要确定要使用哪种即时相机类。下表显示了可用的即时相机类:

Name of Class Usable for Device Type Device-specific
Pylon::CInstantCamera (推荐) All cameras No
Pylon::CBaslerUniversalInstantCamera (新手推荐) All cameras No

CInstantCameraCBaslerUniversalInstantCamera允许你操作所有类型的相机设备。

CBaslerUniversalInstantCamera类是CInstantCamera类的一个特化,它通过一个参数类对其进行了扩展。参数类为每个相机参数提供了一个成员。附加的参数类提供了IDE自动补全功能(例如,Visual Studio中的IntelliSense),在开发应用程序时非常有帮助。虽然这会增加一点运行时开销,但这种开销非常小,可以忽略不计。

后续内容请移步至Pylon C++ Programmer's Guide

Pylon C++ Programmer's Guide的更多相关文章

  1. [转帖]Programmer’s guide to the big tech companies 💻

    Programmer’s guide to the big tech companies

  2. TensorFlow 官方文档 Programmer's Guide 中文翻译 —— 引言

    TensorFlow Programmer's Guide (Introduction) TensorFlow 编程手册 (引言) #(本项目对tensorflow官网上给出的指导手册(TF1.3版本 ...

  3. [翻译] TensorFlow Programmer's Guide之Frequently Asked Questions(问得频率最多的几个问题)

    目录: 特点和兼容性(Features and Compatibility) 建立一个TensorFlow图(Building a TensorFlow graph) 运行一个TensorFlow计算 ...

  4. 转载:ZooKeeper Programmer's Guide(中文翻译)

    本文是为想要创建使用ZooKeeper协调服务优势的分布式应用的开发者准备的.本文包含理论信息和实践信息. 本指南的前四节对各种ZooKeeper概念进行较高层次的讨论.这些概念对于理解ZooKeep ...

  5. chapter3:Collaborative Filtering ---------A Programmer's Guide to Data Mining

    Implicit rating and item based filtering Explicit rating: 用户明确的对item评分 Implicit rating:反之 明确评分所存在的问题 ...

  6. zookeeper[1] (转)ZooKeeper Programmer's Guide(zookeeper编程向导)---中文

    原文:http://www.cnblogs.com/Xrinehart/p/3512509.html 本文是为想要创建使用ZooKeeper协调服务优势的分布式应用的开发者准备的.本文包含理论信息和实 ...

  7. Zookeeper Tutorial 2 -- Programmer's Guide

    数据模型 ZooKeeper跟分布式文件系统一样, 有一系列的命名空间. 唯一不同的地方是命名空间中的每个节点都有数据和他相关联. 它类似于一个允许文件同时是一个目录的文件系统. 节点的路径永远是以斜 ...

  8. ZooKeeper Getting Started Guide

    http://zookeeper.apache.org/doc/trunk/zookeeperStarted.html What is ZooKeeper? ZooKeeper is a centra ...

  9. ZooKeeper Administrator's Guide A Guide to Deployment and Administration(吃别人嚼过的馍没意思,直接看官网资料)

    Deployment System Requirements Supported Platforms Required Software Clustered (Multi-Server) Setup ...

  10. Apache ZooKeeper Getting Started Guide 翻译

    ZooKeeper 開始向导 開始:用zookeeper协调分布式程序 单例操作 管理zookeeper存储 连接zookeeper 执行zookeeper 以复制模式执行zookeeper 其他优化 ...

随机推荐

  1. armbian挂载sd卡记录

    mkdir -p /mnt/mmctouch  /etc/init.d/mount.shvim /etc/init.d/mount.sh内容见图mount /dev/mmcblk1p1 /mnt/mm ...

  2. 基于Material Design风格开源的Avalonia UI控件库

    前言 今天大姚给大家分享一款基于Material Design风格开源.免费(MIT License)的Avalonia UI控件库:Material.Avalonia. 当前项目还处于alpha阶段 ...

  3. 物体检测序列之一:ap, map

    准确率(Precision),也叫正确预测率(positive predictive value),在模式识别.信息检索.机器学习等研究应用领域,准确率用来衡量模型预测的结果中相关或者正确的比例.而召 ...

  4. 【JS设计模式笔记】神奇的魔术师-简单工厂模式(创建型)

    简单工厂模式(Simple Factory):又叫静态工厂方法,由一个工厂对象决定创建某一种产品对象类的实例.主要用来创建同一类对象. 第一次需求 开发一个登录模块的需求,用户名输入框如果输入的内容不 ...

  5. 小tips:使用vuecli2脚手架配置vant自定义主题

    一:工程安装less.less-loader 配置版本如下: "devDependencies": { "less": "^3.0.4", ...

  6. Time Zone, Leap Year, Date Format, Epoch Time 时区, 闰年, 日期格式

    前言 以前有写过一篇了, 但很乱, 这篇就作为它的整理版吧. Leap Year 闰年 闰年是指那些有 366 天, 二月份有 29号 的年份. 比如 2020年 有 2月29日, 所以 2020 就 ...

  7. ComfyUI 基础教程(五) —— 应用 IP-Adapter 实现图像风格迁移

    中秋假期,又可以玩玩 AI 了.前面介绍了 ComfyUI 的 Lora 模型以及 ControlNet,本文介绍另一个非常重要且使用的节点,IP-Adapter. 一. IP-Adapter 概念 ...

  8. MybatisPlus——入门案例

    MyBatisPlus MyBatisPlus(简称MP)是基于MyBatis框架基础上开发的增强型工具,旨在简化开发.提高效率 开发方式 基于MyBatis使用MyBatisPlus 基于Sprin ...

  9. Nuxt Kit 使用日志记录工具

    title: Nuxt Kit 使用日志记录工具 date: 2024/9/23 updated: 2024/9/23 author: cmdragon excerpt: 摘要:本文介绍在Nuxt 3 ...

  10. 离线安装Redis

    redis 直接去官网下载tar包就可以 主要是gcc 环境的安装包不太好找,我下载的还缺少 make 如果服务器比较干净,还得预装一下lrzsz-0.12.20.tar.gz 上传下载文件,unzi ...