我有Orbbec相机。
我使用C#。
我有他们SDK的C#包装器。
我有深度流,可以从该流中获取图像。但是,如何将像素值转换为距离(以mms为单位)?
我已经看过了,我已经给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数据到距离?}
谢谢
发布于 2019-10-27 06:35:17
我使用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_);
}因此,在此演示中,您实际上可以看到深入展示的值,并且使用此示例代码可以对它们进行有利于我们的操作。希望这能有所帮助。
https://stackoverflow.com/questions/54791606
复制相似问题