orbbec - 将像素值转换为距离
问题描述
我得到了 Orbbec 相机。
我使用 C#。
我有他们的 SDK 的 C# 包装器。
我有深度流,可以从该流中获取图像。但是,如何将像素值转换为距离(以毫米为单位)?
我环顾四周,即谷歌搜索,并给 Orbbec 人发了电子邮件。
到目前为止我的代码:
private void HandleDepthFrame(
Astra.ReaderFrame frame )
{
var depthFrame = frame.GetFrame<Astra.DepthFrame>();
if ( depthBuffer.Update( depthFrame ) )
{
BitmapSource image = depthBuffer.ImageSource;
dispatcher.BeginInvoke(DispatcherPriority.DataBind, new Action(() => getBitmap(image)));
if ( frameRateCalculator.RegisterFrame() )
RaisePropertyChanged( nameof(FramesPerSecond) );
}
}
private void getBitmap(BitmapSource source)
{
Bitmap bmp = new Bitmap(source.PixelWidth, source.PixelHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
BitmapData data = bmp.LockBits(new System.Drawing.Rectangle(System.Drawing.Point.Empty, bmp.Size), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
source.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
bmp.UnlockBits(data);
Image<Gray, int16> imageCV = new Image<Gray, int16>(bmp);
??如何读取 mat 数据并将其转换为距离?}
谢谢
解决方案
我为 astra 使用了 C++ 设置,我能够通过在指南中提供的演示中使用一些代码来实现这一点。这段代码在这里:
int main(int argc, char** argv)
{
while (window.isOpen())
{
astra_update();
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::MouseMoved:
{
auto coordinateMapper = depthStream.coordinateMapper();
listener.update_mouse_position(window, coordinateMapper);
}break;
}
}
}
}
void update_mouse_position(sf::RenderWindow& window,
const astra::CoordinateMapper& coordinateMapper)
{
const sf::Vector2i position = sf::Mouse::getPosition(window);
const sf::Vector2u windowSize = window.getSize();
float mouseNormX = position.x / float(windowSize.x);
float mouseNormY = position.y / float(windowSize.y);
mouseX_ = depthWidth_ * mouseNormX;
mouseY_ = depthHeight_ * mouseNormY;
if (mouseX_ >= depthWidth_ ||
mouseY_ >= depthHeight_ ||
mouseX_ < 0 ||
mouseY_ < 0) { return; }
const size_t index = (depthWidth_ * mouseY_ + mouseX_);
const short z = depthData_[index];
coordinateMapper.convert_depth_to_world(float(mouseX_),
float(mouseY_),
float(z),
mouseWorldX_,
mouseWorldY_,
mouseWorldZ_);
}
因此,在此演示中,您实际上可以看到显示的深度值,并且使用此示例代码可以根据我们的喜好操纵它们。希望这可以帮助。
推荐阅读
- java - 使用 ArrayList 和扫描仪从文本文件中打印特定数字
- gwt - 在运行时更新网格中的 GWT(GXT) Buttoncell
- python - 如何使用线性插值对 numpy 数组进行插值
- c# - asp.net core 2.1 跨域策略。添加为 CORS 时,只有单个 url 有效
- python - 如何避免在 heapq 中使用 _siftup 或 _siftdown
- objective-c - 如果有两个条件,如何结合jsbundle和代码推送?
- node.js - 如何从 MERN 堆栈 Web 应用程序项目中的 API 获取数据?
- spring - 在springboot中以分页形式返回ldap条目
- wordpress - 自定义 WordPress 查询排序功能
- c++ - Clang-tidy 不正确的舍入