如何使用 Pleora eBUS SDK c# 或 python 从 Photon Focus 相机获取“像素”数据值?

How to get the "pixel" data values from a Photon Focus camera using the Pleora eBUS SDK c# or python?

提问人:Cary H 提问时间:9/23/2021 最后编辑:Cary H 更新时间:9/24/2021 访问量:345

问:

我有一个 3D Photon Focus 相机 (MV1-D2048x1088-3D06-760-G2-8),我在 Windows 10 计算机上将 C# 与 Pleora eBUS SDK 版本 5.1.1 一起使用。相机设置为在LineFinder模式下扫描激光线,DataFormat3D = 2并返回数据(缓冲区有效负载= 2 x 2048 = 4096字节)。有效载荷似乎是正确的。我想保存这些数据,但我遇到了困难。如何将缓冲区放入数组(或某些结构)中以将其保存到文件流中? 我的代码正在使用 .来自 Pleora eBUS SDK 的 DataPointer 参数,但我不明白它在做什么。我在这里包含的手册 - MAN075_PhotonFocus

enter image description here

private unsafe static void ThreadProc(object aParameters)
    {
        object[] lParameters = (object[])aParameters;
        MainForm lThis = (MainForm)lParameters[0];

        for (;;)
        {
            if (lThis.mIsStopping)
            {
                // Signaled to terminate thread, return.
                return;
            }

            PvBuffer lBuffer = null;
            PvResult lOperationResult = new PvResult(PvResultCode.OK);                
            // Retrieve next buffer from acquisition pipeline
            PvResult lResult = lThis.mStream.RetrieveBuffer(ref lBuffer, ref lOperationResult, 100);
            if (lResult.IsOK)
            {
                // Operation result of buffer is OK, display.
                if (lOperationResult.IsOK)
                {
                    //lThis.displayControl.Display(lBuffer);
                    uint bSize = lBuffer.GetPayloadSize();
                    PvImage image1 = lBuffer.Image;
                    uint height1 = image1.Height;
                    uint width1 = image1.Width;
                    uint offx1 = image1.OffsetX;
                    uint offy1 = image1.OffsetY;                        
                    PvPixelType imgpixtype = image1.PixelType;                                               
                    image1.Alloc(width1, (uint)2, imgpixtype);
                    byte *data_pnt = image1.DataPointer ;
                    byte[] MSB_array = new byte[(int)width1];
                    int buff_size = 2 * (int)width1;
                    byte[] pix_array = new byte[buff_size];                       
                    
                    ulong tStamp = lBuffer.Timestamp;
                    string msgOut = (bSize.ToString() + " TimeStamp " + tStamp.ToString() + " width " + width1.ToString());
                    Console.WriteLine(msgOut);
                    for (int i = 0; i < width1; i++)
                    {
                        data_pnt += 0;
                        Console.Write((uint)*data_pnt);
                        MSB_array[i] = *data_pnt;
                        data_pnt += 1;
                    }
                    data_pnt += 1;
                    Console.WriteLine(height1.ToString());
                    for (int i = 0; i < width1; i++)
                    {
                        ushort msb1 = MSB_array[i];
                        ushort last_4 = (ushort)(*data_pnt & 0x0F);
                        int integer1 = (msb1 << 4)+(ushort)(*data_pnt>>4);
                        double dec_part = (float)last_4 / (float)16;
                        double val1 = (float)integer1 + dec_part;
                        Console.WriteLine(val1.ToString());
                        data_pnt += 1;
                    }
                    Console.WriteLine(height1.ToString());
                }
                else
                {
                    uint bSize = lBuffer.GetPayloadSize();
                    ulong tStamp = lBuffer.Timestamp;
                    string msgOut = (bSize.ToString() + " BAD RESULT TimeStamp " + tStamp.ToString());
                    Console.WriteLine(msgOut);
                }

                // We have an image - do some processing (...) and VERY IMPORTANT,
                // re-queue the buffer in the stream object.
                lThis.mStream.QueueBuffer(lBuffer);
            }
        }
    }
C# 3D 扫描 PLEORA-SDK

评论

1赞 Jeroen van Langen 9/23/2021
它正在将数据复制到 ,因此您可以使用 将像素数据另存为文件。Bitmap img_bitmap1img_bitmap1
0赞 Jeroen van Langen 9/23/2021
仅用于在控制台中显示某些值data_pnt
1赞 Jeroen van Langen 9/23/2021
您可以使用 将格式从 8 位转换为其他格式。使用所需的 PvPixelType 创建第二个 PvBuffer。PvBufferConverterconvertBuffer.Image.Alloc(lBuffer.Image.Width, lBuffer.Image.Height, PvPixelType.BGR8);
0赞 Cary H 9/23/2021
谢谢你@JeroenvanLangen。我需要知道正在发送的数据。数据由相机编码,每 2 个字节包含“高度 Z 数据”,而不是实际图像。前 12 位包含整数数据,后 4 位包含分数数据。我需要读取字节。我认为 PixelType 很好。由于某种原因,我无法正确阅读它们。
0赞 Jeroen van Langen 9/23/2021
我不认为图像是交错存储的。它是平面存储的,所以首先是所有高度数据,然后是亮度,然后是数据层页面/块。

答:

0赞 Cary H 9/24/2021 #1

我目前的解决方案是通过递增指针来遍历缓冲区,并将字节保存到一个新数组 (MSB_array) 中。这些数据的打包方式(见问题中附上的图像)我必须读取下一行并将其位移,并将其添加到MSB_array中的字节中才能得到一个

    for (int i = 0; i < width1; i++)
        {
            data_pnt += 0;
            Console.Write((uint)*data_pnt);
            MSB_array[i] = *data_pnt;
            data_pnt += 1;
        }
        data_pnt += 1;
        Console.WriteLine(height1.ToString());
        for (int i = 0; i < width1; i++)
        {
            ushort msb1 = MSB_array[i];
            ushort last_4 = (ushort)(*data_pnt & 0x0F);
            int integer1 = (msb1 << 4)+(ushort)(*data_pnt>>4);
            double dec_part = (float)last_4 / (float)16;
            double val1 = (float)integer1 + dec_part;
            Console.WriteLine(val1.ToString());
            data_pnt += 1;
        }

我现在只是把它写到控制台上,但数据是正确的。可能有比使用指针的 for 循环更好/更快的方法。该职位将不胜感激。

评论

0赞 Cary H 9/25/2021
我将发布完成的方法。现在一切似乎都正常了。