在某鱼花了90RMB,买了个Astra Pro奥比中光深度相机,性价比还是比较高的。通过封装官方的SDK,导出为dll给C#调用,效果如下

///////////AstraCamera.cs////////////
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Drawing;
using OpenCvSharp;
using OpenCvSharp.Extensions;
public class AstraCamera : IDisposable
{
// DLL导入
[DllImport("ColorReaderEventCPP.dll", CallingConvention = CallingConvention.StdCall)]
private static extern void StartCamera();
[DllImport("ColorReaderEventCPP.dll", CallingConvention = CallingConvention.StdCall)]
private static extern void StopCamera();
[DllImport("ColorReaderEventCPP.dll", CallingConvention = CallingConvention.StdCall)]
private static extern bool GetLatestFrames(
IntPtr rawDepthData, int rawDepthSize,
IntPtr depthData, int depthSize,
IntPtr colorData, int colorSize);
[DllImport("ColorReaderEventCPP.dll", CallingConvention = CallingConvention.StdCall)]
private static extern void GetFrameInfo(
out int rawDepthWidth, out int rawDepthHeight, out int rawDepthType,
out int depthWidth, out int depthHeight, out int depthType,
out int colorWidth, out int colorHeight, out int colorType);
// 图像属性
public int RawDepthWidth;
public int RawDepthHeight;
public MatType RawDepthType { get; private set; }
public int DepthWidth;
public int DepthHeight;
public MatType DepthType { get; private set; }
public int ColorWidth;
public int ColorHeight;
public MatType ColorType { get; private set; }
// 非托管内存缓冲区
private IntPtr _rawDepthBuffer;
private IntPtr _depthBuffer;
private IntPtr _colorBuffer;
private int _rawDepthBufferSize;
private int _depthBufferSize;
private int _colorBufferSize;
// 当前帧
public Mat RawDepthFrame { get; private set; } // 原始深度图 (16位)
public Mat DepthFrame { get; private set; } // 伪彩色深度图
public Mat ColorFrame { get; private set; } // 彩色图
// 更新事件
public event Action FramesUpdated;
// 后台线程
private Thread _updateThread;
private bool _isRunning;
public AstraCamera()
{
// 获取帧信息
GetFrameInfo(out RawDepthWidth, out RawDepthHeight, out int rawDepthType,
out DepthWidth, out DepthHeight, out int depthType,
out ColorWidth, out ColorHeight, out int colorType);
// 转换为MatType
RawDepthType = (MatType)rawDepthType;
DepthType = (MatType)depthType;
ColorType = (MatType)colorType;
// 计算缓冲区大小
_rawDepthBufferSize = RawDepthWidth * RawDepthHeight * sizeof(u

最低0.47元/天 解锁文章
228

被折叠的 条评论
为什么被折叠?



