Jump to content

AVT Firewrap.net Camera zooms in even though it wasn't coded

deathsiroj

For my internship I have to create photo's with a prosillica camera, I have been looking at different api's to be able to work with the camera. Now that i found one that works, and I write the code that a previous intern wrote("guessing" he says). i get images but they are all really zoomed in. While in the official Firegrab program the pictures look fine and aren't zoomed in at all. You can look at the images [here][1]. The code i wrote to connect to the camera was as followed: 

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

When i connect to the camera, I also tell it to start recording instantly. The frames i get when the camera turns on are processed in OnFrameReady, which I used the following code for:

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

So in this function i get the frame and put it in a byte[], then i call the function SaveImageFromByteArray(); where i put the byte[] in a list. So i can access all my pictures later on to save them. The code for the SaveImageFromByteArray is as followed:

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

After im done recoding all of my frames, I click save, stops the camera and then i call the following functions to save it to a bitmap file:

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

The save function called in the function above is written as followed:

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

I think the problem of the zooming happens when we connect to the camera and we execute this line of code:

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

But the problem is that there is no documentation to be found about Firewrap.net or their api. Even when we try to edit the 16 to like 15, the camera won't even startup

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×