当前位置: 首页 > news >正文

图漾相机——C#语言属性设置

文章目录

  • 前言
  • 1.示例程序说明
  • 2.SDK API功能介绍
    • 2.1 ListDevice
    • 2.2 Open
    • 2.3 OpenDeviceByIP
    • 2.4 Close
    • 2.5 DeviceStreamEnable
    • 2.6 DeviceStreamFormatDump
    • 2.7 DeviceStreamFormatConfig
    • 2.8 DeviceReadCurrentEnumData
    • 2.9 DeviceReadCalibData
    • 2.10 DeviceStreamOn
    • 2.11 DeviceStreamOff
    • 2.12 DeviceStreamRead
    • 2.13 DeviceStreamDepthRender
    • 2.14 DeviceStreamImageDecode
    • 2.15 DeviceStreamIRRender
    • 2.16 DeviceControlLaserPowerAutoControlEnable
    • 2.17 DeviceControlLaserPowerConfig
    • 2.18 DeviceColorStreamIspEnable
    • 2.19 DeviceStreamMapDepthImageToColorCoordinate
    • 2.20 DeviceStreamMapRGBImageToDepthCoordinate
    • 2.21 DeviceStreamDoUndistortion
    • 2.22 DeviceControlTriggerModeEnable
    • 2.23 DeviceControlTriggerModeSendTriggerSignal
    • 2.24DeviceStreamMapDepthImageToPoint3D
    • 2.25 IPv4StringToInt
    • 2.26 DevParamFromInt
    • 2.27 DevParamFromEnum
    • 2.28 DevParamFromBool
    • 2.29 DevParamFromFloat
    • 2.30 DeviceSetParameter
    • 2.31 DeviceGetParameter
      • 2.31.1 Int型
      • 2.31.2 Enum型
      • 2.31.3 Bool型
      • 2.31.4 Float型
      • 2.31.5 Array型
      • 2.31.6 Struct(roi)型
    • 2.32 获取网络相机信息接口get_netinfo
    • 2.33 DeviceLoadDefaultParameters
    • 2.34 DeviceWriteDefaultParametersFromJSFile
    • 2.35 DeviceClearDefaultParameters
    • 2.36 DeviceHasStream
    • 2.37 DeviceReadRectifiedRotationData
    • 2.38 DeviceReadRectifiedIntrData

前言

请参考图漾官网的在线文档:
https://doc.percipio.xyz/cam/latest/getstarted/sdk-csharp-compile.html#windows-csharp-label
而如果不想配置环境,请参考预编译版本例子,下载地址:
https://doc.percipio.xyz/cam/latest/getstarted/compile.html

1.示例程序说明

示例程序存放在开发包根目录 csharp 文件夹内:
1.fetch_frame.cs:该示例在自由采集模式下采集深度图和彩色图。
2.fetch_IR.cs:该示例在自由采集模式下采集 IR 图。
3.fetch_isp.cs:该示例在软件层面对于彩色图像的 ISP 后处理,可将存在偏色的 RAW BAYER 图像处理成正常色彩空间的彩色图。
4.fetch_point3d.cs:该示例用于采集 3d 点云(未作显示),Log 信息显示点云个数和中心点云坐标(X,Y,Z)。
5.fetch_registration.cs:该示例用于采集 RGB-D 对齐图像。
6.fetch_trigger.cs:该示例用于设置相机工作在软触发模式下采集深度图。
7.offline_reconnection.cs :该例程⽤于处理因环境不稳定等因素造成的数据连接异常,并实现相机离线重连。
8.parameter_settings.cs:该例程⽤于设置不同数据类型的参数。例程中展⽰了如何关闭 RGB AEC(布尔型参数)、设置曝光时间(整型参数),以及设置图像分辨率和格式(枚举型参数)。

pcammls.dll :动态链接库。
pcammls.exp:中间⽂件。
pcammls.lib :依赖库。
pcammls_cs.dll :动态链接库。
注:前四个文件,均在编译后的camport _multi language/csharp_build_x64/Bin/Release 目录下。
tycam.dll:动态链接库。

如果不想编译,可下载预编译例程,链接如下:
https://gitee.com/percipioxyz/camport_multi_language_Release
在这里插入图片描述

2.SDK API功能介绍

本节主要介绍Csharp SDK中封装的一些接口。

2.1 ListDevice

该接口用于枚举与PC连接的所有相机。
示例如下

DeviceInfoVector dev_list= cl.ListDevice();

2.2 Open

该接口用于打开指定SN号的相机。
示例如下

System.IntPtr handle =cl.Open(207000145055);

2.3 OpenDeviceByIP

该接口用于打开指定p的相机。
示例如下:

System.IntPtr handle =cl.OpenDeviceByIP("192.168.6.85");

2.4 Close

该接口用于关闭相机
示例如下

cl.Close(handle);

2.5 DeviceStreamEnable

该接口用于使能数据流,如需使能Color和Depth数据流。
示例如下:

cl.DeviceStreamEnable(handle, PERCIPIO_STREAM_COLOR | PERCIPIO_STREAM_DEPTH);

2.6 DeviceStreamFormatDump

该接口用于列举数据流的分辨率格式。
示例如下

EnumEntryVector color_fmt_list = cl.DeviceStreamFormatDump(handle, PERCIPIO_STREAM_COLOR);
            if(color_fmt_list.Count() != 0) 
            { 
                Console.WriteLine(string.Format("color image format list:"));
                for (int i = 0; i < color_fmt_list.Count(); i++)
                {
                    TY_ENUM_ENTRY fmt = color_fmt_list[i];
                    Console.WriteLine(string.Format("\t{0} -size[{1}x{2}]\t-\t desc:{3}", i, cl.Width(fmt), cl.Height(fmt), fmt.getDesc()));
                }
            }

2.7 DeviceStreamFormatConfig

该接口用于配置数据流的分辨率,可与DeviceStreamFormatDump联合使用。
示例如下

cl.DeviceStreamFormatConfig(handle, PERCIPIO_STREAM_COLOR, color_fmt_list[0]);

表示配置列表中的第一个分辨率。

2.8 DeviceReadCurrentEnumData

该接口用于读取当前数据流所用的分辨率
示例如下

TY_ENUM_ENTRY color_enum_desc = new TY_ENUM_ENTRY();
cl.DeviceReadCurrentEnumData(handle, PERCIPIO_STREAM_COLOR, color_enum_desc);
Console.WriteLine($"current color image mode   {color_enum_desc.getDesc()}");  

2.9 DeviceReadCalibData

该接口用于读取数据流的标定参数。
示例如下:

PercipioCalibData color_calib_data   = cl.DeviceReadCalibData(handle, PERCIPIO_STREAM_COLOR);
int color_calib_width  = color_calib_data.Width();
int color_calib_height = color_calib_data.Height();
CalibDataVector color_calib_intr   = color_calib_data.Intrinsic();
CalibDataVector color_calib_extr   = color_calib_data.Extrinsic();
CalibDataVector color_calib_dis    = color_calib_data.Distortion();

2.10 DeviceStreamOn

开启数据流,类似于C++中TYStartCapture接口。
示例如下:

cl.DeviceStreamOn(handle);

2.11 DeviceStreamOff

关闭数据流,类似于C++中TYStopCapture接口。
示例如下:

cl.DeviceStreamOff(handle) ;

2.12 DeviceStreamRead

读取相机的传送的数据,类似于C++中TYFetchFrame接口。
示例如下:

FrameVector frames = cl.DeviceStreamRead(handle, 5000); 

2.13 DeviceStreamDepthRender

该接口用于解析和渲染深度图像。
示例如下:

image_data depth = new image_data();
cl.DeviceStreamDepthRender(frames[i], depth);
IntPtr pt = depth.buffer.getCPtr();
Bitmap bmp_depth = new Bitmap(depth.width, depth.height, depth.width * 3, PixelFormat.Format24bppRgb, pt);
pictureBox1.Image = (Image)(new Bitmap(bmp_depth, new Size(640, 480))).Clone();

2.14 DeviceStreamImageDecode

该接口用于解析RGB图像。
示例如下:

image_data bgr = new image_data();
cl.DeviceStreamImageDecode(frames[i], bgr);
IntPtr pt = bgr.buffer.getCPtr();
Bitmap bmp_color = new Bitmap(bgr.width, bgr.height, bgr.width * 3, PixelFormat.Format24bppRgb, pt);
pictureBox2.Image = (Image)(new Bitmap(bmp_color, new Size(640, 480))).Clone();

2.15 DeviceStreamIRRender

该接口用于解析ir图像。
示例如下:

image_data rightIR = new image_data();
cl.DeviceStreamIRRender(frames[i], rightIR);
IntPtr pt = rightIR.buffer.getCPtr();
Bitmap rightIR_BMP = new Bitmap(rightIR.width, rightIR.height, 3*rightIR.width, PixelFormat.Format24bppRgb, pt);
pictureBox2.Image = (Image)(new Bitmap(rightIR_BMP, new Size(640, 480))).Clone();

2.16 DeviceControlLaserPowerAutoControlEnable

该接口用于使能/失能 **TY_BOOL_LASER_AUTO_CTRL**属性,用于需要分析ir散斑图时,点亮激光器。
示例如下:

cl.DeviceControlLaserPowerAutoControlEnable(handle, false);

2.17 DeviceControlLaserPowerConfig

该接口用于调整激光器亮度。
示例如下:

cl.DeviceControlLaserPowerConfig(handle, 80);

2.18 DeviceColorStreamIspEnable

该接口用于打开/关闭软件isp。
示例如下:

cl.DeviceColorStreamIspEnable(handle, true);

2.19 DeviceStreamMapDepthImageToColorCoordinate

该接口用于将深度图坐标映射到彩色图,可参考fetch_registration_cs*。
示例如下:
SDK3.6.51此接口有变化,若SDK版本低于3.6.51,以下代码不可用。

cl.DeviceStreamMapDepthImageToColorCoordinate(depth_calib,depth,scale_unit,color_calib,undsitortion_color.width,undsitortion_color.height,registration_depth);

2.20 DeviceStreamMapRGBImageToDepthCoordinate

该接口用于将彩色图坐标映射到深度图。
示例如下:

cl.DeviceStreamMapRGBImageToDepthCoordinate(depth_calib,depth,scale_unit,color_calib, undsitortion_color, registration_color);

SDK3.6.66新增接口。

2.21 DeviceStreamDoUndistortion

该接口用于对图像做畸变校正,可参考fetch_registration_cs。
示例如下:

cl.DeviceStreamDoUndistortion(color_calib, color, undsitortion_color);

2.22 DeviceControlTriggerModeEnable

`该接口用于设置相机的工作模式。·
示例如下:

cl.DeviceControlTriggerModeEnable(handle, 1);

0代表 TY_TRIGGER_MODE_OFF,
1代表 TY_TRIGGER_MODE_SLAVE。

2.23 DeviceControlTriggerModeSendTriggerSignal

该接口用于给相机发送软触发命令,类似于C++中TYSendSoftTrigger。
示例如下:

cl.DeviceControlTriggerModeSendTriggerSignal(handle);

2.24DeviceStreamMapDepthImageToPoint3D

该接口用于将深度图转换成点云数据,可参fetch_point3d_cs。
示例如下:

cl.DeviceStreamMapDepthImageToPoint3D(image, depth_calib_data, f_depth_scale, p3d_list);

2.25 IPv4StringToInt

该接口可以将字符串转换成整型,应用于相机的ip设置。

但是因为没有TYForceDeviceIP接口,所以只把参数写入了相机,不会立刻更新,需要重启相机才可以生效。

示例如下:

int ip = cl.IPv4StringToInt("0.0.0.0");
DevParam param = cl.DevParamFromInt(ip);
cl.DeviceSetParameter(handle, TY_COMPONENT_DEVICE, TY_INT_PERSISTENT_IP, param);
DevParam read_param = cl.DeviceGetParameter(handle, TY_COMPONENT_DEVICE, TY_INT_PERSISTENT_IP);
int read_param_m = read_param.toInt();
Console.WriteLine($"{read_param_m}");

int netmask = cl.IPv4StringToInt("0.0.0.0");
DevParam param1 = cl.DevParamFromInt(netmask);
cl.DeviceSetParameter(handle, TY_COMPONENT_DEVICE, TY_INT_PERSISTENT_SUBMASK, param1);
DevParam read_param1 = cl.DeviceGetParameter(handle, TY_COMPONENT_DEVICE, TY_INT_PERSISTENT_SUBMASK);
int read_param_m1 = read_param1.toInt();
Console.WriteLine($"{read_param_m1}");

int gateway = cl.IPv4StringToInt("0.0.0.0");
DevParam param2 = cl.DevParamFromInt(gateway);
cl.DeviceSetParameter(handle, TY_COMPONENT_DEVICE, TY_INT_PERSISTENT_GATEWAY, param2);
DevParam read_param2 = cl.DeviceGetParameter(handle, TY_COMPONENT_DEVICE, TY_INT_PERSISTENT_GATEWAY);
int read_param_m2 = read_param2.toInt();
Console.WriteLine($"{read_param_m2}");

2.26 DevParamFromInt

该接口用于定义Int类型的变量,变量数据类型:int。
示例如下:

DevParam param =  cl.DevParamFromInt(4096);

2.27 DevParamFromEnum

该接口用于定义Enum类型的变量,变量数据类型:uint。
示例如下:

DevParam param =  cl.DevParamFromEnum(TY_DEPTH_QUALITY_BASIC);

2.28 DevParamFromBool

该接口用于定义Bool型变量,用于设置Bool类型的feature。
示例如下:

DevParam param =  cl.DevParamFromBool(true);

2.29 DevParamFromFloat

该接口用于定义Float型变量,用于设置Float类型的feature。
示例如下:

DevParam param = cl.DevParamFromFloat(2.2f);

2.30 DeviceSetParameter

该接口用于设置相机参数,可以设置Int、Enum、Bool、Float、Array型参数。

2.31 DeviceGetParameter

该接口用于读取相机参数,可以读取Int、Enum、Bool、Float、Array型参数。
DeviceSetParameterDeviceGetParameter的示例代码如下:

2.31.1 Int型

DevParam param = cl.DevParamFromInt(1088);
cl.DeviceSetParameter(handle, TY_COMPONENT_RGB_CAM, TY_INT_EXPOSURE_TIME, param);
DevParam read_param = cl.DeviceGetParameter(handle, TY_COMPONENT_RGB_CAM, TY_INT_EXPOSURE_TIME);
int m_read_param = read_param.toInt();
Console.WriteLine($"current value {m_read_param}");
int min = read_param.mMin();
int max = read_param.mMax();
int inc = read_param.mInc();
Console.WriteLine($"min :{min},max:{max},inc:{inc}");

2.31.2 Enum型

DevParam param = cl.DevParamFromEnum(TY_TIME_SYNC_TYPE_HOST);
cl.DeviceSetParameter(handle, TY_COMPONENT_DEVICE, TY_ENUM_TIME_SYNC_TYPE, param);
DevParam read_param = cl.DeviceGetParameter(handle, TY_COMPONENT_DEVICE, TY_ENUM_TIME_SYNC_TYPE);
uint m_read_param = read_param.toEnum();
Console.WriteLine($"current value {m_read_param}");
EnumEntryVector m_read_param2 = read_param.eList();
for (int i = 0; i < m_read_param2.Count(); i++){
         Console.WriteLine($"{ m_read_param2[i].value}");
}

2.31.3 Bool型

DevParam param = cl.DevParamFromBool(false);
cl.DeviceSetParameter(handle, TY_COMPONENT_RGB_CAM, TY_BOOL_AUTO_EXPOSURE, param);
DevParam status = cl.DeviceGetParameter(handle, TY_COMPONENT_RGB_CAM, TY_BOOL_AUTO_EXPOSURE);
bool m_status = status.toBool();
Console.WriteLine($"current value {m_status}");

2.31.4 Float型

DevParam param = cl.DevParamFromFloat(0.0125f);
cl.DeviceSetParameter(handle, TY_COMPONENT_DEPTH_CAM, TY_FLOAT_SCALE_UNIT, param);
DevParam read_param = cl.DeviceGetParameter(handle, TY_COMPONENT_DEPTH_CAM, TY_FLOAT_SCALE_UNIT);
float m_read_param = read_param.toFloat();
Console.WriteLine($"current value {m_read_param}");
float min = read_param.fMin();
float max = read_param.fMax();
float inc = read_param.fInc();
Console.WriteLine($"min :{min},max:{max},inc:{inc}");

2.31.5 Array型

ByteArrayVector array = new ByteArrayVector { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 14, 0, 0, 0 };
 DevParam arr = cl.DevParamFromByteArray(array);
 cl.DeviceSetParameter(handle, TY_COMPONENT_IR_CAM_LEFT, TY_BYTEARRAY_HDR_PARAMETER,arr);
  DevParam hdr_arry = cl.DeviceGetParameter(handle, TY_COMPONENT_IR_CAM_LEFT, TY_BYTEARRAY_HDR_PARAMETER);
   ByteArrayVector hdr_arry_1 = hdr_arry.toByteArray();
    for (int i = 0; i < hdr_arry_1.Count(); i++)
     {
      Console.Write($",{hdr_arry_1[i]}");
       }

2.31.6 Struct(roi)型

PercipioAecROI roi = new PercipioAecROI(0, 0, 640, 480);
DevParam param = cl.DevParamFromPercipioAecROI(roi);
 cl.DeviceSetParameter(handle, TY_COMPONENT_RGB_CAM, TY_STRUCT_AEC_ROI, param);
 DevParam readParam = cl.DeviceGetParameter(handle, TY_COMPONENT_RGB_CAM, TY_STRUCT_AEC_ROI);
ArrayVector mReadParam = readParam.toArray();
Console.WriteLine("aec roi: " + string.Join(",", mReadParam));

2.32 获取网络相机信息接口get_netinfo

该接口可用于获取打开的网络相机的设备信息,如ip、mac、netmask、gateway。
ip的获取示例如下:

handle = cl.Open(dev_list[select].id);
Console.WriteLine("ip {0}", dev_list[select].get_netinfo().ip());

2.33 DeviceLoadDefaultParameters

该接口用于加载相机的配置文件(custom_block.bin文件中保存的相机参数json文件)。

int err = cl.DeviceLoadDefaultParameters(handle);
            if (err != TY_STATUS_OK)
                Console.WriteLine(string.Format("Load default parameters fail: {0}!", err));
            else
                Console.WriteLine(string.Format("Load default parameters successful!"));

支持加载的参数类型有Int、Float、Enum、Bool、和BYTEARRAY。

2.34 DeviceWriteDefaultParametersFromJSFile

该接口用于将本地json文件中保存的参数内容写入相机custom_block.bin文件。

string filePath = @"C:\Users\G\Desktop\1.json";
cl.DeviceWriteDefaultParametersFromJSFile(handle, filePath);

2.35 DeviceClearDefaultParameters

用于清除相机内存中的内容。

cl.DeviceClearDefaultParameters(handle);

2.36 DeviceHasStream

该接口用于判断相机是否具有特定的数据流,返回值为bool型。
示例:判断相机是否具有color数据流。

bool has_stream = false;
has_stream = cl.DeviceHasStream(handle, PERCIPIO_STREAM_IR_RIGHT);
Console.WriteLine($"has right ir  {has_stream}");

2.37 DeviceReadRectifiedRotationData

该接口用于读取V相机的IR rotation。
示例:读取IR rotation数据

PercipioRectifyRotaData LEFTIR_rot_data = cl.DeviceReadRectifiedRotationData(handle, PERCIPIO_STREAM_IR_LEFT);
CalibDataVector LEFTIR_r_data = LEFTIR_rot_data.Data();
Console.WriteLine(string.Format(":IR_rot_data"));
dump_calib_data(LEFTIR_r_data, 3, 3);

2.38 DeviceReadRectifiedIntrData

该接口用于读取V相机的IR rectified intrinsic。

PercipioRectifyIntrData LEFTIR_int_data = cl.DeviceReadRectifiedIntrData(handle, PERCIPIO_STREAM_IR_LEFT);
CalibDataVector LEFTIR_i_data = LEFTIR_int_data.Data();
Console.WriteLine(string.Format(":IR_ntrinsic _data"));
dump_calib_data(LEFTIR_i_data, 3, 3);

相关文章:

  • 薛定谔的指针
  • Spring Cloud Gateway中Route Predicate Factories(路由断言工厂)的详细介绍
  • 华为OD机试 - 寻找连续区间 - 滑动窗口(Java 2024 E卷 100分)
  • Python入门(7):Python序列结构-字典
  • Docker容器网络相关设置
  • 【系统移植】 (二)交叉开发环境搭建
  • 【蓝桥杯真题精讲】第 15 届 Python A 组(省赛)
  • dounable to get image ‘nginx:latest‘: error during connect
  • 基于kubernetes构建jenkins+gitlab持续集成
  • Pycharm中Django框架使用{% load static %}模板,HTML报错
  • Postman —— postman实现参数化
  • nmslib 是一个 超快、适用于高维向量的最近邻搜索库,基于 HNSW 算法,被广泛用于 语义搜索、推荐系统、人脸识别等任务
  • 美国队长 [4部合集][2008~2025] 4K 下载
  • 如何部署私有 AI 大模型?(本地 GPU vs 云计算 vs 端侧 AI)
  • Debian系统_主板四个网口1个配置为WAN,3个配置为LAN
  • Nessus 扫描Web服务
  • TypeScript vs. JavaScript:技术对比与核心差异解析
  • 【AI论文】探索基于人类反馈的强化学习中的数据扩展趋势与影响
  • 软考教材重点内容 信息安全工程师 第21章 网络设备安全
  • virsh 的工作原理
  • 国宝归来!子弹库帛书二、三卷抵达北京
  • 世界高血压日|专家:高血压患者控制血压同时应注重心率管理
  • 长三角体育节回归“上海时间”,首次发布赛事旅游推荐线路
  • 马上评|训斥打骂女儿致死,无暴力应是“管教”底线
  • 商务部召开全国离境退税工作推进会:提高退税商店覆盖面,扩大入境消费
  • 董军同德国国防部长举行会谈