AVT Firewrap.net 相机放大,即使它没有编码



在我的实习中,我必须使用Prosillica相机创建照片,我一直在研究其他API,以便能够使用相机。现在我找到了一个有效的工作,并且写了一个以前的实习生写的代码(他说"猜测"(。我得到了图像,但它们都非常放大。虽然在官方壁炉程序中,图片看起来还不错,根本没有放大。您可以在这里查看图像。我写的要连接到相机的代码如下:

Ctrl = FireWrap_CtrlCenter.GetInstance();
            Ctrl.OnFrameReady += OnFrameReady;
            Result = Ctrl.FGInitModule();
            if (Result == enFireWrapResult.E_NOERROR)
            {
                Result = InfoContainer.FGGetNodeList();
                var NodeCnt = InfoContainer.Size();
                InfoContainer.GetAt(NodeInfo, 0);
                Result = Cam.Connect(NodeInfo.Guid);
                cCamera.Items.Add(Cam.DeviceAll);
                if (Result == enFireWrapResult.E_NOERROR)
                {
                    Cam.m_Guid = NodeInfo.Guid;
                }
                if (Result == enFireWrapResult.E_NOERROR)
                {
                    Result = Cam.SetParameter(enFGParameter.E_IMAGEFORMAT,
                        (((uint)enFGResolution.E_RES_SCALABLE << 16) |
                        ((uint)enColorMode.E_CCOLORMODE_Y8 << 8) |
                        0));
                }
                if (Result == enFireWrapResult.E_NOERROR)
                    Result = Cam.OpenCapture();
                // Print device settings
                Result = Cam.GetParameter(enFGParameter.E_XSIZE, ref XSize);
                Result = Cam.GetParameter(enFGParameter.E_YSIZE, ref YSize);
                width = XSize;
                height = YSize;
                // Start camera
                if (Result == enFireWrapResult.E_NOERROR)
                {
                    Result = Cam.StartDevice();
                }
            }

连接到相机时,我还告诉它立即开始录制。当相机打开时,我在Onframeready处理时得到的帧,我使用以下代码:

Debug.WriteLine("OnFrameReady is called");
            FGEventArgs args = (FGEventArgs)__p2;
            FGFrame Frame;
            Guid.High = args.High;
            Guid.Low = args.Low;
            if (Guid.Low == Cam.m_Guid.Low)
            {
                Result = Cam.GetFrame(Frame, 0);
                // Process frame, skip FrameStart notification
                if (Result == enFireWrapResult.E_NOERROR & Frame.Length > 0)
                {
                    byte[] data = new byte[Frame.Length];
                    // Access to frame data
                    if (Frame.CloneData(data))
                    {
                        //DisplayImage(data.Clone());
                        SaveImageFromByteArray(data);
                        // Here you can start your image processsing logic on data
                        string debug = String.Format("[{6}] Frame #{0} length:{1}byte [ {2} {3} {4} {5} ... ]",
                            Frame.Id, Frame.Length, data[0], data[1], data[2], data[3], Cam.m_Guid.Low);
                        Debug.WriteLine(debug);
                    }
                    // Return frame to module as fast as posible after this the Frame is not valid 
                    Result = Cam.PutFrame(Frame);
                }
            }

因此,在此函数中,我得到框架并将其放入字节[],然后调用函数saveImageFromByTearRay((;我将字节[]放在列表中。这样我稍后可以访问所有图片以保存它们。saveimageFromByTearray的代码如下:

 public void SaveImageFromByteArray(byte[] byteArray)
        {
            try
            {
                //bytearray size determined
                byte[] data = new byte[width * height * 4];
                int o = 0;
                //bytearray size filled
                for (int io = 0; io < width * height; io++)
                {
                    byte value = byteArray[io];
                    data[o++] = value;
                    data[o++] = value;
                    data[o++] = value;
                    data[o++] = 0;
                }
                bytearrayList.Add(data);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

im完成了所有帧的重新编码后,我单击"保存",停止相机,然后调用以下功能以将其保存到位图文件:

public void SaveData()
        {
            try
            {
                foreach (byte[] data1 in bytearrayList)
                {
                    byte[] data = Save(data1);
                    lock (this)
                    {
                        unsafe
                        {
                            fixed (byte* ptr = data)
                            {
                                try
                                {
                                    using (image = new Bitmap((int) width, (int) height, (int) width * 4,
                                        System.Drawing.Imaging.PixelFormat.Format32bppPArgb, new IntPtr(ptr)))
                                    {
                                        image.Save(path + nextpicture + ".bmp", ImageFormat.Bmp);
                                        Debug.WriteLine("Image saved at " + path + nextpicture + ".bmp");
                                        nextpicture++;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Debug.Write(ex.ToString());
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());
            }
        }

上面函数中调用的保存函数如下:

private byte[] Save(byte[] data1)
        {
            //bytearray size determined
            byte[] data = new byte[width * height * 4];
            int o = 0;
            //bytearray size filled
            for (int io = 0; io < width * height; io++)
            {
                byte value = data1[io];
                data[o++] = value;
                data[o++] = value;
                data[o++] = value;
                data[o++] = 0;
            }
            return data;
        }

我认为缩放的问题发生在我们连接到相机并执行此代码时发生:

 if (Result == enFireWrapResult.E_NOERROR)
            {
                Result = Cam.SetParameter(enFGParameter.E_IMAGEFORMAT,
                    (((uint)enFGResolution.E_RES_SCALABLE << 16) |
                    ((uint)enColorMode.E_CCOLORMODE_Y8 << 8)| 
                    0));
            }

但问题在于,找不到有关FireWrap.net或其API的文档。即使我们尝试编辑16个喜欢15,相机甚至也不会启动

找到了问题!像素水平伸展到4个像素,那是因为我们做了两次:

byte[] data = new byte[width * height * 4];
            int o = 0;
            //bytearray size filled
            for (int io = 0; io < width * height; io++)
            {
                byte value = byteArray[io];
                data[o++] = value;
                data[o++] = value;
                data[o++] = value;
                data[o++] = 0;
            }

最新更新