0

我有一个 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

在此处输入图像描述

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);
            }
        }
    }
4

1 回答 1

0

我当前的解决方案是通过递增指针来循环缓冲区并将字节保存到新数组(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 循环更好/更快的方法。那篇文章将不胜感激。

于 2021-09-23T18:45:07.657 回答