Example #1
0
        static void DestroysObjects(SapAcquisition acq, SapAcqDevice camera, SapBuffer buf, SapTransfer xfer, SapView view)
        {
            if (xfer != null)
            {
                xfer.Destroy();
                xfer.Dispose();
            }

            if (camera != null)
            {
                camera.Destroy();
                camera.Dispose();
            }

            if (acq != null)
            {
                acq.Destroy();
                acq.Dispose();
            }

            if (buf != null)
            {
                buf.Destroy();
                buf.Dispose();
            }

            if (view != null)
            {
                view.Destroy();
                view.Dispose();
            }

            //Console.WriteLine("\nPress any key to terminate\n");
            //Console.ReadKey(true);
        }
Example #2
0
 private void DisposeObjects()
 {
     if (m_Xfer != null)
     {
         m_Xfer.Dispose(); m_Xfer = null;
     }
     if (m_Buffers != null)
     {
         m_Buffers.Dispose(); m_Buffers = null;
     }
     if (m_AcqDevice != null)
     {
         m_AcqDevice.Dispose(); m_AcqDevice = null;
     }
 }
Example #3
0
 private void DisposeObjects()
 {
     if (m_Xfer != null)
     {
         m_Xfer.Dispose(); m_Xfer = null;
     }
     if (m_Buffers != null)
     {
         m_Buffers.Dispose(); m_Buffers = null;
     }
     if (m_Acquisition != null)
     {
         m_Acquisition.Dispose(); m_Acquisition = null;
     }
 }
Example #4
0
 /// <summary>
 /// 清空 采集、传输、缓存对象
 /// </summary>
 public void SeparaInterface_DisposeObjects()
 {
     if (m_Xfer != null)
     {
         m_Xfer.Dispose(); m_Xfer = null;
     }
     if (m_Buffers != null)
     {
         m_Buffers.Dispose(); m_Buffers = null;
     }
     if (m_Acquisition != null)
     {
         m_Acquisition.Dispose(); m_Acquisition = null;
     }
 }
Example #5
0
        static bool IsMonoBuffer(SapBuffer pBuffers)
        {
            SapFormat format = pBuffers.Format;

            if (format == SapFormat.Uint8 || format == SapFormat.Int8 || format == SapFormat.Int16 || format == SapFormat.Uint16 ||
                format == SapFormat.Int24 || format == SapFormat.Uint24 || format == SapFormat.Int32 || format == SapFormat.Uint32 ||
                format == SapFormat.Int64 || format == SapFormat.Uint64)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #6
0
 static SapData SetDataValue(SapBuffer pBuffers, UInt32 pPrmIndex)
 {
     if (IsMonoBuffer(pBuffers))
     {
         SapDataMono mono = new SapDataMono(128);
         return(mono);
     }
     else
     {
         SapDataRGB rgb = new SapDataRGB();
         //SapDataRGB rgb(m_pInfoList->GetValueAt(*pPrmIndex), m_pInfoList->GetValueAt(*pPrmIndex+1), m_pInfoList->GetValueAt(*pPrmIndex+2));
         pPrmIndex = pPrmIndex + 3;
         return(rgb);
     }
 }
        private void cvProcess(SapBuffer buffer)//修改
        {
            unsafe
            {
                IntPtr dataBufAddress;

                buffer.GetAddress(out dataBufAddress);

                //IntPtr imgdata = new IntPtr(img.data);
                if (2 == videoMode)
                {
                    mChipDetection.ProcessImage(dataBufAddress, (UInt32)buffer.Width, (UInt32)buffer.Height);
                }
                //img.data
            }
        }
Example #8
0
        private void DisposeObjects()
        {
            if (m_Xfer != null)
            {
                m_Xfer.Dispose(); m_Xfer = null;
            }
//             if (m_View != null)
//             { m_View.Dispose(); m_View = null; m_ImageBox.View = null; }
            if (m_Buffers != null)
            {
                m_Buffers.Dispose(); m_Buffers = null;
            }
            if (m_Acquisition != null)
            {
                m_Acquisition.Dispose(); m_Acquisition = null;
            }
        }
        private void btnTest_Click(object sender, EventArgs e)
        {
            //************整个的处理******************//
            string    picpath   = "E:\\pic\\7.jpg";
            SapBuffer picbuffer = null;

            picbuffer = new SapBuffer(picpath, SapBuffer.MemoryType.Default);
            picbuffer.Create();
            picbuffer.Load(picpath, -1);

            IntPtr BufAddress;

            picbuffer.GetAddress(out BufAddress);
            mChipDetection.ProcessImage(BufAddress, (uint)picbuffer.Width, (uint)picbuffer.Height);

            lblwordx.Text = mChipDetection.realworldx.ToString();
            lblwordy.Text = mChipDetection.realworldy.ToString();
        }
        public static byte[] ReadPicDatas(SapBuffer Buffers, int index)
        {
            long len  = Buffers.Height * Buffers.Width * Buffers.BytesPerPixel;
            long len1 = len / Buffers.BytesPerPixel;

            byte[] pRx1  = new byte[len];
            IntPtr pBuf1 = Marshal.UnsafeAddrOfPinnedArrayElement(pRx1, 0);

            if (index < 0)
            {
                Buffers.Read(0, (int)len1, pBuf1);
            }
            else
            {
                Buffers.Read(index, 0, (int)len1, pBuf1);
            }
            return(pRx1);
        }
Example #11
0
        public bool CreateNewObjects(SapLocation location, string fileName, bool Restore)
        {
            if (Online)
            {
                if (!Restore)
                {
                    Location = location;
                }

                if (!SapManager.IsResourceAvailable(location, SapManager.ResourceType.Acq))
                {
                    Debug.WriteLine(fileName + "available");
                    return(false);
                }

                Acquisition = new SapAcquisition(Location, fileName);
                if (SapBuffer.IsBufferTypeSupported(Location, SapBuffer.MemoryType.ScatterGather))
                {
                    Buffers = new SapBufferWithTrash(4, Acquisition, SapBuffer.MemoryType.ScatterGather);
                }
                else
                {
                    Buffers = new SapBufferWithTrash(4, Acquisition, SapBuffer.MemoryType.ScatterGatherPhysical);
                }
                Xfer   = new SapAcqToBuf(Acquisition, Buffers);
                m_View = new SapView(Buffers);

                Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
                Xfer.XferNotify        += xfer_XferNotify;
                Xfer.XferNotifyContext  = this;
            }
            else
            {
                Buffers = new SapBuffer();
            }

            if (!CreateObjects())
            {
                DisposeObjects();
                return(false);
            }

            return(true);
        }
Example #12
0
        void Run()
        {
            string    result;
            SapBuffer buffer = null;

            while (true)
            {
                result = server.Receive();
                while (result != "")
                {
                    //Console.WriteLine(result);
                    System.IO.File.AppendAllText(_save_dir + "MCU_data.txt", result + "\n");

                    result = server.Receive();
                }
                Thread.Sleep(2000);
            }
            server.Close();
        }
Example #13
0
 /// <summary>
 /// 释放句柄
 /// </summary>
 private void DisposeObjects()
 {
     if (m_Xfer != null)
     {
         m_Xfer.Dispose(); m_Xfer = null;
     }
     if (m_View != null)
     {
         m_View.Dispose(); m_View = null; m_ImageBox.View = null;
     }
     if (m_Buffers != null)
     {
         m_Buffers.Dispose(); m_Buffers = null;
     }
     if (m_AcqDevice != null)
     {
         m_AcqDevice.Dispose(); m_AcqDevice = null;
     }
 }
Example #14
0
        public bool CreateNewObjects(SapLocation ServerLocation, string ConfigFile)
        {
            m_Acquisition = new SapAcquisition(m_ServerLocation, ConfigFile);
            if (SapBuffer.IsBufferTypeSupported(m_ServerLocation, SapBuffer.MemoryType.ScatterGather))
            {
                m_Buffers = new SapBufferWithTrash(2, m_Acquisition, SapBuffer.MemoryType.ScatterGather);
            }
            else
            {
                m_Buffers = new SapBufferWithTrash(2, m_Acquisition, SapBuffer.MemoryType.ScatterGatherPhysical);
            }
            m_Xfer = new SapAcqToBuf(m_Acquisition, m_Buffers);


            //event for view
            m_Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
            m_Xfer.XferNotify        += new SapXferNotifyHandler(xfer_XferNotify);

            return(true);
        }
Example #15
0
 public Boolean Create()
 {
     try
     {
         Params      = new MyAcquisitionParams();
         Location    = new SapLocation(Params.ServerName, Params.ResourceIndex);
         Device      = new SapAcqDevice(Location, Params.ConfigFileName);
         Buffers     = new SapBufferWithTrash(DefaultBuffer, Device, SapBuffer.MemoryType.ScatterGather);
         Acquisition = new SapAcquisition(Location, Params.ConfigFileName);
         Transfer    = new SapAcqToBuf(Acquisition, Buffers);
     }
     catch (SapException CreateException)
     {
         throw new Exception("CreateCamera failed!", CreateException);
     }
     finally
     {
         Console.WriteLine("Camera Created!");
     }
     return(true);
 }
Example #16
0
        private void Initialize_ViewFormat_Combo()
        {
            SapBuffer buffer = m_pView.Buffer;

            if (buffer.MultiFormat)
            {
                int         numPages    = buffer.NumPages;
                SapFormat[] pageFormats = buffer.PageFormats;
                for (int i = 0; i < numPages; i++)
                {
                    comboBox1_ViewFormat.Items.Add(pageFormats[i] + " (page " + i + ")");
                }
                int currentPage = buffer.Page;
                comboBox1_ViewFormat.SelectedIndex = currentPage;
                comboBox1_ViewFormat.Enabled       = true;
            }
            else
            {
                comboBox1_ViewFormat.Enabled = false;
            }
        }
Example #17
0
        protected override bool?CreateCamObj()
        {
            ServerLocation = new SapLocation(ServerName, ResourceIndex);
            Acquisition    = new SapAcquisition(ServerLocation, ConfigFile);

            if (SapBuffer.IsBufferTypeSupported(ServerLocation, SapBuffer.MemoryType.ScatterGather))
            {
                Buffers = new SapBufferWithTrash(2, Acquisition, SapBuffer.MemoryType.ScatterGather);
            }
            else
            {
                Buffers = new SapBufferWithTrash(2, Acquisition, SapBuffer.MemoryType.ScatterGatherPhysical);
            }

            Acquisition.Create();

            Xfer = new SapAcqToBuf(Acquisition, Buffers);
            Xfer.Pairs [0].EventType = SapXferPair.XferEventType.EndOfFrame;

            View = new SapView(Buffers);
            return(true);
        }
Example #18
0
        bool CreateDeviceMana(IConnection connectModule)
        {
            try
            {
                DalsaMemObj.ServerLocation = new SapLocation(connectModule.ServerName, connectModule.ResourceIndex);
                DalsaMemObj.Acquisition    = new SapAcquisition(DalsaMemObj.ServerLocation, connectModule.ConfigFile);

                if (SapBuffer.IsBufferTypeSupported(DalsaMemObj.ServerLocation, SapBuffer.MemoryType.ScatterGather))
                {
                    DalsaMemObj.Buffers = new SapBufferWithTrash(2, DalsaMemObj.Acquisition, SapBuffer.MemoryType.ScatterGather);
                }
                else
                {
                    DalsaMemObj.Buffers = new SapBufferWithTrash(2, DalsaMemObj.Acquisition, SapBuffer.MemoryType.ScatterGatherPhysical);
                }

                var objSetting = new ObjectSetting();
                objSetting.AcqusitionSetting(DalsaMemObj.Acquisition);

                DalsaMemObj.Xfer = new SapAcqToBuf(DalsaMemObj.Acquisition, DalsaMemObj.Buffers);
                DalsaMemObj.Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;

                DalsaMemObj.View = new SapView(DalsaMemObj.Buffers);

                DalsaMemObj.Xfer.XferNotify       += new SapXferNotifyHandler(GrabDoneEventMethod);
                DalsaMemObj.Xfer.XferNotifyContext = DalsaMemObj.View;

                var creatobject = new CreatesObjects();
                creatobject.CreatEndSqObject(DalsaMemObj.Buffers, DalsaMemObj.Xfer, DalsaMemObj.View);
                return(true);
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(false);
            }
        }
Example #19
0
        /// <summary>
        /// 初始化设备
        /// </summary>
        /// <param name="acConfigDlg"></param>
        /// <param name="Restore"></param>
        /// <returns></returns>
        public bool CreateNewObjects(AcqConfigDlg acConfigDlg, bool Restore)
        {
            if (!Restore)
            {
                m_ServerLocation = acConfigDlg.ServerLocation;
                m_ConfigFileName = acConfigDlg.ConfigFile;
            }
            m_AcqDevice = new SapAcqDevice(m_ServerLocation, m_ConfigFileName);
            if (SapBuffer.IsBufferTypeSupported(m_ServerLocation, SapBuffer.MemoryType.ScatterGather))
            {
                m_Buffers = new SapBufferWithTrash(2, m_AcqDevice, SapBuffer.MemoryType.ScatterGather);
            }
            else
            {
                m_Buffers = new SapBufferWithTrash(2, m_AcqDevice, SapBuffer.MemoryType.ScatterGatherPhysical);
            }
            m_Xfer          = new SapAcqDeviceToBuf(m_AcqDevice, m_Buffers);
            m_View          = new SapView(m_Buffers);
            m_ImageBox.View = m_View;

            m_Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
            m_Xfer.XferNotify        += new SapXferNotifyHandler(xfer_XferNotify);
            m_Xfer.XferNotifyContext  = this;
            StatusLabelInfo.Text      = "Online... Waiting grabbed images";

            if (!CreateObjects())
            {
                DisposeObjects();
                return(false);
            }

            // Resize ImagBox to take into account the size of created sapview
            m_ImageBox.OnSize();
            UpdateControls();
            return(true);
        }
Example #20
0
        static void Main(string[] args)
        {
            SapAcquisition Acq       = null;
            SapAcqDevice   AcqDevice = null;
            SapBuffer      Buffers   = null;
            SapTransfer    Xfer      = null;
            SapView        View      = null;

            //Console.WriteLine("Sapera Console Grab Example (C# version)\n");

            MyAcquisitionParams acqParams = new MyAcquisitionParams();

            // Call GetOptions to determine which acquisition device to use and which config
            // file (CCF) should be loaded to configure it.
            if (!GetOptions(args, acqParams))
            {
                Console.WriteLine("\nPress any key to terminate\n");
                Console.ReadKey(true);
                return;
            }

            SapLocation loc = new SapLocation(acqParams.ServerName, acqParams.ResourceIndex);

            if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.Acq) > 0)
            {
                Acq     = new SapAcquisition(loc, acqParams.ConfigFileName);
                Buffers = new SapBuffer(1, Acq, SapBuffer.MemoryType.ScatterGather);
                Xfer    = new SapAcqToBuf(Acq, Buffers);

                // Create acquisition object
                if (!Acq.Create())
                {
                    Console.WriteLine("Error during SapAcquisition creation!\n");
                    DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                    return;
                }
            }

            if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.AcqDevice) > 0)
            {
                AcqDevice = new SapAcqDevice(loc, acqParams.ConfigFileName);
                Buffers   = new SapBuffer(1, AcqDevice, SapBuffer.MemoryType.ScatterGather);
                Xfer      = new SapAcqDeviceToBuf(AcqDevice, Buffers);

                // Create acquisition object
                if (!AcqDevice.Create())
                {
                    Console.WriteLine("Error during SapAcqDevice creation!\n");
                    DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                    return;
                }
            }

            View = new SapView(Buffers);
            // End of frame event
            Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
            Xfer.XferNotify        += new SapXferNotifyHandler(xfer_XferNotify);
            Xfer.XferNotifyContext  = View;

            //Console.WriteLine("gggggwhat is new line");
            // Create buffer object
            if (!Buffers.Create())
            {
                Console.WriteLine("Error during SapBuffer creation!\n");
                DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                return;
            }

            // Create buffer object
            if (!Xfer.Create())
            {
                Console.WriteLine("Error during SapTransfer creation!\n");
                DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                return;
            }

            // Create buffer object
            if (!View.Create())
            {
                Console.WriteLine("Error during SapView creation!\n");
                DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                return;
            }

            // Grab as fast as possible, wait for a key to be pressed, if it's p,
            // write the file, otherwise if it's q exit the program. Designed to be run by and monitored
            // through a pipe

            Boolean stop_snap = false;
            int     curr_code = 0;
            string  new_cmd   = "";

            while (stop_snap == false)
            {
                Console.WriteLine("Press a key to trigger snap");
                new_cmd = Console.ReadLine();
                Xfer.Snap();

                Console.WriteLine("Press a key to trigger save");
                new_cmd = Console.ReadLine();
                View.Buffer.Save("test.raw", "-format raw");

                var dsb = new StringBuilder("frame: " + frame_count);
                Console.WriteLine(dsb);
                frame_count = frame_count + 1;


                Console.WriteLine("File saved, Press a key to repeat, q to quit:");
                new_cmd = Console.ReadLine();
                if (new_cmd == "q")
                {
                    stop_snap = true;
                }
                //if (curr_code == 113) { stop_snap = true; }
            }

            DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
            loc.Dispose();
        }
Example #21
0
 public void XferSetting(SapAcqToBuf xfer, SapAcquisition acquisition, SapBuffer buffers)
 {
     xfer = new SapAcqToBuf(acquisition, buffers);
     xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
 }
Example #22
0
        static public string GetLUTOptionsFromQuestions(SapBuffer pBuffers, SapLut pLut)
        {
            //////// Ask questions to user to select LUT mode ////////
            UInt32 prmIndex       = 1;
            string acqLutFileName = "";
            string chAcqLutName   = "";

            while (string.IsNullOrEmpty(chAcqLutName))
            {
                Console.WriteLine("\nSelect the LookUpTable mode you want to apply: \n");

                Console.WriteLine("a : Normal mode");
                Console.WriteLine("b : Arithmetic mode");
                Console.WriteLine("c : Binary mode");
                Console.WriteLine("d : Boolean mode");
                Console.WriteLine("e : Gamma mode");
                Console.WriteLine("f : Reverse mode");
                Console.WriteLine("g : Roll mode");
                Console.WriteLine("h : Shift mode");
                Console.WriteLine("i : Slope mode");
                Console.WriteLine("j : Threshold single mode");
                Console.WriteLine("k : Threshold double mode");

                ConsoleKeyInfo info = Console.ReadKey(true);
                char           key  = info.KeyChar;
                switch (key)
                {
                case 'a':
                {
                    pLut.Normal();
                    acqLutFileName = "Normal_Lut_Mode.lut";
                    chAcqLutName   = "Normal Lut";
                    break;
                }

                case 'b':
                {
                    int operationMode = 0;                //Linear plus offset with clip

                    /*
                     *      Others operations available
                     */
                    //int operation = 1;//Linear minus offset(absolute)
                    //int operation = 2;//Linear minus offset(with clip)
                    //int operation = 3;//Linear with lower clip
                    //int operation = 4;//Linear with upper clip
                    //int operation = 5;//Scale to maximum limit

                    SapData offSet;
                    offSet = SetDataValue(pBuffers, prmIndex);
                    pLut.Arithmetic((SapLut.ArithmeticOp)operationMode, offSet);
                    acqLutFileName = "Arithmetic_Lut_Mode.lut";
                    chAcqLutName   = "Arithmetic Lut";
                    break;
                }

                case 'c':
                {
                    SapData clipValue;
                    clipValue = SetDataValue(pBuffers, prmIndex);
                    pLut.BinaryPattern(0, clipValue);
                    acqLutFileName = "Binary_Lut_Mode.lut";
                    chAcqLutName   = "Binary Lut";
                    break;
                }

                case 'd':
                {
                    SapData booleanFunction;
                    booleanFunction = SetDataValue(pBuffers, prmIndex);
                    pLut.Boolean((SapLut.BooleanOp) 0, booleanFunction);

                    /*
                     *      Others operations available
                     */
                    // AND
                    //pLut->Boolean((SapLut::BooleanOp)1, booleanFunction);
                    // OR
                    //pLut->Boolean((SapLut::BooleanOp)2, booleanFunction);
                    // XOR
                    acqLutFileName = "Boolean_Lut_Mode.lut";
                    chAcqLutName   = "Boolean Lut";
                    break;
                }

                case 'e':
                {
                    int gammaFactor = (int)(2 * GAMMA_FACTOR);
                    pLut.Gamma((float)gammaFactor / GAMMA_FACTOR);
                    acqLutFileName = "Gamma_Lut_Mode.lut";
                    chAcqLutName   = "Gamma Lut";
                    break;
                }

                case 'f':
                {
                    pLut.Reverse();
                    acqLutFileName = "Reverse_Lut_Mode.lut";
                    chAcqLutName   = "Reverse Lut";
                    break;
                }

                case 'g':
                {
                    int numEntries = 128;
                    pLut.Roll(numEntries);
                    acqLutFileName = "Roll_Lut_Mode.lut";
                    chAcqLutName   = "Roll Lut";
                    break;
                }

                case 'h':
                {
                    int bitsToShift = 3;
                    pLut.Shift(bitsToShift);
                    acqLutFileName = "Shift_Lut_Mode.lut";
                    chAcqLutName   = "Shift Lut";
                    break;
                }

                case 'i':
                {
                    int     startIndex1 = 76;
                    int     endIndex1   = 179;
                    bool    clipOutSide = false;             //TRUE
                    SapData minValue;
                    SapData maxValue;
                    minValue = SetDataValue(pBuffers, prmIndex);
                    maxValue = SetDataValue(pBuffers, prmIndex);
                    pLut.Slope(startIndex1, endIndex1, minValue, maxValue, clipOutSide);
                    acqLutFileName = "Slope_With_Range_Lut_Mode.lut";
                    chAcqLutName   = "Slope With Range Lut";
                    break;
                }

                case 'j':
                {
                    SapData treshValue;
                    treshValue = SetDataValue(pBuffers, prmIndex);
                    pLut.Threshold(treshValue);
                    acqLutFileName = "Threshold_Single_Mode.lut";
                    chAcqLutName   = "Threshold Single Lut";
                    break;
                }

                case 'k':
                {
                    SapData treshValue1;
                    SapData treshValue2;
                    treshValue1 = SetDataValue(pBuffers, prmIndex);
                    treshValue2 = SetDataValue(pBuffers, prmIndex);
                    pLut.Threshold(treshValue1, treshValue2);
                    acqLutFileName = "Threshold_Double_Mode.lut";
                    chAcqLutName   = "Threshold Double Lut";
                    break;
                }

                default:
                {
                    Console.WriteLine("\nInvalid selection!\n");
                    break;
                }
                }
            }
            pLut.Save(acqLutFileName);                  // Save LUT to file (can be reloaded in the main demo)
            Console.WriteLine("\n");
            return(chAcqLutName);
        }
 public static byte[] ReadPicDatas(SapBuffer Buffers)
 {
     return(ReadPicDatas(Buffers, -1));
 }
Example #24
0
        static void Main(string[] args)
        {
            SapAcquisition Acq = null;
            SapAcqDevice AcqDevice = null;
            SapBuffer Buffers = null;
            SapTransfer Xfer = null;
            SapView View = null;

            //Console.WriteLine("Sapera Console Grab Example (C# version)\n");

            MyAcquisitionParams acqParams = new MyAcquisitionParams();

            // Call GetOptions to determine which acquisition device to use and which config
            // file (CCF) should be loaded to configure it.
            if (!GetOptions(args, acqParams))
            {
                Console.WriteLine("\nPress any key to terminate\n");
                Console.ReadKey(true);
                return;
            }

            SapLocation loc = new SapLocation(acqParams.ServerName, acqParams.ResourceIndex);

            if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.Acq) > 0)
            {
                Acq         = new SapAcquisition(loc, acqParams.ConfigFileName);
                Buffers     = new SapBuffer(1, Acq, SapBuffer.MemoryType.ScatterGather);
                Xfer = new SapAcqToBuf(Acq, Buffers);

               // Create acquisition object
                if (!Acq.Create())
                {
                    Console.WriteLine("Error during SapAcquisition creation!\n");
                    DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                    return;
                }
            }

            if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.AcqDevice) > 0)
            {
                AcqDevice   = new SapAcqDevice(loc, acqParams.ConfigFileName);
                Buffers = new SapBuffer(1, AcqDevice, SapBuffer.MemoryType.ScatterGather);
                Xfer = new SapAcqDeviceToBuf(AcqDevice, Buffers);

               // Create acquisition object
                if (!AcqDevice.Create())
                {
                    Console.WriteLine("Error during SapAcqDevice creation!\n");
                    DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                    return;
                }
            }

            View = new SapView(Buffers);
            // End of frame event
            Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
            Xfer.XferNotify += new SapXferNotifyHandler(xfer_XferNotify);
            Xfer.XferNotifyContext = View;

            //Console.WriteLine("gggggwhat is new line");
            // Create buffer object
            if (!Buffers.Create())
            {
                Console.WriteLine("Error during SapBuffer creation!\n");
                DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                return;
            }

            // Create buffer object
            if (!Xfer.Create())
            {
                Console.WriteLine("Error during SapTransfer creation!\n");
                DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                return;
            }

            // Create buffer object
            if (!View.Create())
            {
                Console.WriteLine("Error during SapView creation!\n");
                DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                return;
            }

            // Grab as fast as possible, wait for a key to be pressed, if it's p,
            // write the file, otherwise if it's q exit the program. Designed to be run by and monitored
            // through a pipe

            Boolean stop_snap = false;
            int curr_code = 0;
            string new_cmd = "";
            while (stop_snap == false)
            {
                Console.WriteLine("Press a key to trigger snap");
                new_cmd = Console.ReadLine();
                Xfer.Snap();

                Console.WriteLine("Press a key to trigger save");
                new_cmd = Console.ReadLine();
                View.Buffer.Save("test.raw", "-format raw");

                var dsb = new StringBuilder("frame: " + frame_count);
                Console.WriteLine(dsb);
                frame_count = frame_count + 1;

                Console.WriteLine("File saved, Press a key to repeat, q to quit:");
                new_cmd = Console.ReadLine();
                if (new_cmd == "q") { stop_snap = true; }
                //if (curr_code == 113) { stop_snap = true; }

            }

            DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
            loc.Dispose();
        }
Example #25
0
        static void Main(string[] args)
        {
            SapAcquisition Acq       = null;
            SapAcqDevice   AcqDevice = null;
            SapBuffer      Buffers   = null;
            SapTransfer    Xfer      = null;
            SapView        View      = null;

            Console.WriteLine("Sapera Console Grab Example (C# version)\n");

            MyAcquisitionParams acqParams = new MyAcquisitionParams();

            // Call GetOptions to determine which acquisition device to use and which config
            // file (CCF) should be loaded to configure it.
            if (!GetOptions(args, acqParams))
            {
                Console.WriteLine("\nPress any key to terminate\n");
                Console.ReadKey(true);
                return;
            }

            SapLocation loc = new SapLocation(acqParams.ServerName, acqParams.ResourceIndex);

            if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.Acq) > 0)
            {
                Acq     = new SapAcquisition(loc, acqParams.ConfigFileName);
                Buffers = new SapBufferWithTrash(2, Acq, SapBuffer.MemoryType.ScatterGather);
                Xfer    = new SapAcqToBuf(Acq, Buffers);

                // Create acquisition object
                if (!Acq.Create())
                {
                    Console.WriteLine("Error during SapAcquisition creation!\n");
                    DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                    return;
                }
                Acq.EnableEvent(SapAcquisition.AcqEventType.StartOfFrame);
            }

            else if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.AcqDevice) > 0)
            {
                AcqDevice = new SapAcqDevice(loc, acqParams.ConfigFileName);
                Buffers   = new SapBufferWithTrash(2, AcqDevice, SapBuffer.MemoryType.ScatterGather);
                Xfer      = new SapAcqDeviceToBuf(AcqDevice, Buffers);

                // Create acquisition object
                if (!AcqDevice.Create())
                {
                    Console.WriteLine("Error during SapAcqDevice creation!\n");
                    DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                    return;
                }
            }

            View = new SapView(Buffers);

            // End of frame event
            Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
            Xfer.XferNotify        += new SapXferNotifyHandler(xfer_XferNotify);
            Xfer.XferNotifyContext  = View;

            // Create buffer object
            if (!Buffers.Create())
            {
                Console.WriteLine("Error during SapBuffer creation!\n");
                DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                return;
            }

            // Create buffer object
            if (!Xfer.Create())
            {
                Console.WriteLine("Error during SapTransfer creation!\n");
                DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                return;
            }

            // Create buffer object
            if (!View.Create())
            {
                Console.WriteLine("Error during SapView creation!\n");
                DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
                return;
            }


            Xfer.Grab();
            Console.WriteLine("\n\nGrab started, press a key to freeze");
            Console.ReadKey(true);
            Xfer.Freeze();
            Xfer.Wait(1000);

            DestroysObjects(Acq, AcqDevice, Buffers, Xfer, View);
            loc.Dispose();
        }
Example #26
0
        static bool AutoWhiteBalanceOperations(SapAcqDevice Camera, SapBuffer Buffers, SapTransfer Transfer)
        {
            Console.WriteLine("\nCalibration in progress ...........\n\n");

            double coefBlueGain         = MAX_COEF + 1;
            double coefGreenGain        = MAX_COEF + 1;
            double coefRedGain          = MAX_COEF + 1;
            int    calibrationIteration = 0;

            // Create a new Bayer object
            SapBayer   Bayer       = new SapBayer(Buffers);
            SapFeature FeatureInfo = new SapFeature(Camera.Location);

            if (!FeatureInfo.Create())
            {
                DestroysFeaturesAndBayer(FeatureInfo, Bayer);
                return(false);
            }

            // Create Bayer object
            if (!Bayer.Create())
            {
                DestroysFeaturesAndBayer(FeatureInfo, Bayer);
                return(false);
            }

            // Initialize all Gain colors to 0
            Camera.SetFeatureValue("GainBlue", 0);
            Camera.SetFeatureValue("GainGreen", 0);
            Camera.SetFeatureValue("GainRed", 0);

            // Choose alignment used
            Bayer.Align = SapBayer.AlignMode.RGGB;

            // Definition of ROI used for calibration
            int fixSelectedRoiLeft = 0;
            int fixSelectedRoiTop  = 0;
            // Half buffer width
            int fixSelectedRoiWidth = Buffers.Width / 2;
            // Half buffer height
            int fixSelectedRoiHeight = Buffers.Height / 2;

            // Start loop for calibration until each coefficient is under 1.05
            while (coefBlueGain > MAX_COEF || coefGreenGain > MAX_COEF || coefRedGain > MAX_COEF)
            {
                if (!Transfer.Snap())
                {
                    Console.WriteLine("Unable to acquire an image");
                    return(false);
                }

                Thread.Sleep(500);
                // Call WhiteBalance function
                if (!Bayer.WhiteBalance(Buffers, fixSelectedRoiLeft, fixSelectedRoiTop, fixSelectedRoiWidth, fixSelectedRoiHeight))
                {
                    break;
                }

                // New coefficients values are reused.
                coefBlueGain  = Bayer.WBGain.Blue;
                coefGreenGain = Bayer.WBGain.Green;
                coefRedGain   = Bayer.WBGain.Red;

                if (coefRedGain > MAX_COEF)
                {
                    if (!ComputeGain("GainRed", Camera, FeatureInfo, coefRedGain))
                    {
                        break;
                    }
                }
                if (coefGreenGain > MAX_COEF)
                {
                    if (!ComputeGain("GainGreen", Camera, FeatureInfo, coefGreenGain))
                    {
                        break;
                    }
                }
                if (coefBlueGain > MAX_COEF)
                {
                    if (!ComputeGain("GainBlue", Camera, FeatureInfo, coefBlueGain))
                    {
                        break;
                    }
                }

                if (calibrationIteration >= MAX_CALIBRATION_ITERATION)
                {
                    Console.WriteLine("Iterations for calibration are at the maximum.\n");
                    break;
                }
                calibrationIteration++;
            }

            // Uncomment this part if you want to get new values after calibration.

            /*
             * int gainBlue=0, gainRed=0, gainGreen=0;
             * Camera.GetFeatureValue("GainBlue", out gainBlue);
             * Camera.GetFeatureValue("GainRed", out gainRed);
             * Camera.GetFeatureValue("GainGreen", out gainGreen);
             */

            DestroysFeaturesAndBayer(FeatureInfo, Bayer);
            Console.WriteLine("\nCalibration finished ...........\n\n");
            return(true);
        }
Example #27
0
        //static void Main(string[] args)
        public static void Done()
        {
            SapAcqDevice camera   = null;
            SapView      view     = null;
            SapTransfer  transfer = null;
            SapBuffer    buffer   = null;

            Console.WriteLine("Sapera Console GigE Cameras AutoWhiteBalance Example (C# version)\n");

            MyAcquisitionParams acqParams = new MyAcquisitionParams();

            /*if (!GetOptions(args, acqParams))
             * {
             *  Console.WriteLine("\nPress any key to terminate\n");
             *  Console.ReadKey();
             *  return;
             * }*/
            SapLocation location = new SapLocation(acqParams.ServerName, acqParams.ResourceIndex);


            camera   = new SapAcqDevice(location, acqParams.ConfigFileName);
            buffer   = new SapBufferWithTrash(2, camera, SapBuffer.MemoryType.ScatterGather);
            transfer = new SapAcqDeviceToBuf(camera, buffer);
            view     = new SapView(buffer);

            // End of frame event
            transfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
            transfer.XferNotify        += new SapXferNotifyHandler(Xfer_XferNotify);
            transfer.XferNotifyContext  = view;

            if (!camera.Create())
            {
                Console.WriteLine("Error during SapAcquisition creation!\n");
                DestroysObjects(camera, buffer, transfer, view);
                return;
            }

            // Monochrome models are not supported for White Balance Calibration.
            int  colorType   = 0;
            bool isAvailable = false;

            if (isAvailable = camera.IsFeatureAvailable("ColorType"))
            {
                if (camera.GetFeatureValue("ColorType", out colorType))
                {
                    if (colorType == 0)
                    {
                        Console.WriteLine("This camera model does not support Auto White Balance calibration.\n");
                        DestroysObjects(camera, buffer, transfer, view);
                        return;
                    }
                }
            }


            //activate feature only if camera has 3 separate gains

            Boolean bRedGain   = false;
            Boolean bGreenGain = false;
            Boolean bBlueGain  = false;

            bRedGain   = camera.IsFeatureAvailable("GainRed");
            bGreenGain = camera.IsFeatureAvailable("GainGreen");
            bBlueGain  = camera.IsFeatureAvailable("GainBlue");
            if (!bRedGain && !bGreenGain && !bBlueGain)
            {
                Console.WriteLine("This camera model does not support Auto White Balance calibration.\n");
                DestroysObjects(camera, buffer, transfer, view);
                return;
            }

            // Create buffer object
            if (!buffer.Create())
            {
                Console.WriteLine("Error during SapBuffer creation!\n");
                DestroysObjects(camera, buffer, transfer, view);
                return;
            }

            // Create transfer object
            if (!transfer.Create())
            {
                Console.WriteLine("Error during SapTransfer creation!\n");
                DestroysObjects(camera, buffer, transfer, view);
                return;
            }

            // Create view object
            if (!view.Create())
            {
                Console.WriteLine("Error during SapView creation!\n");
                DestroysObjects(camera, buffer, transfer, view);
                return;
            }

            Console.WriteLine("Press any key to start Grab. Press 'q' to quit.");
            ConsoleKeyInfo info = Console.ReadKey(true);
            char           key  = info.KeyChar;

            if (key != 0)
            {
                if (key == 'q')
                {
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }
            }

            // Start continous grab
            transfer.Grab();

            Console.WriteLine("Press any key to stop grab\n");
            Console.ReadKey();

            // Stop grab
            transfer.Freeze();
            transfer.Wait(5000);

            Console.WriteLine("Press any key to start Auto White Balance calibration. Press 'q' to quit.\n");
            info = Console.ReadKey(true);
            key  = info.KeyChar;
            if (key != 0)
            {
                if (key == 'q')
                {
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }
            }

            int oldPixelFormat = 0;

            isAvailable = false;
            if (isAvailable = camera.IsFeatureAvailable("PixelFormat"))
            {
                camera.GetFeatureValue("PixelFormat", out oldPixelFormat);
            }
            else
            {
                Console.WriteLine("This camera model does not support Auto White Balance calibration.\n");
                DestroysObjects(camera, buffer, transfer, view);
                return;
            }

            if (oldPixelFormat != GVSP_PIX_BAYRG8)
            {
                // Camera Pixel Format defined is not Raw Bayer.
                // We change the value

                DestroysObjects(null, buffer, transfer, view);

                camera.SetFeatureValue("PixelFormat", GVSP_PIX_BAYRG8);

                // Instantiation of new buffer object
                buffer = new SapBufferWithTrash(2, camera, SapBuffer.MemoryType.ScatterGather);
                // Instantiation of new view object
                view = new SapView(buffer);
                // Instantiation of new transfer object
                transfer = new SapAcqDeviceToBuf(camera, buffer);

                // End of frame event
                transfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
                transfer.XferNotify        += new SapXferNotifyHandler(Xfer_XferNotify);
                transfer.XferNotifyContext  = view;

                if (!camera.Create())
                {
                    Console.WriteLine("Error during SapAcquisition creation!\n");
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }

                // Create buffer object
                if (!buffer.Create())
                {
                    Console.WriteLine("Error during SapBuffer creation!\n");
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }

                // Create transfer object
                if (!transfer.Create())
                {
                    Console.WriteLine("Error during SapTransfer creation!\n");
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }

                // Create view object
                if (!view.Create())
                {
                    Console.WriteLine("Error during SapView creation!\n");
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }
            }


            if (!AutoWhiteBalanceOperations(camera, buffer, transfer))
            {
                Console.WriteLine("Auto WhiteBalamce has failed");
                DestroysObjects(camera, buffer, transfer, view);
                return;
            }

            if (oldPixelFormat != GVSP_PIX_BAYRG8)
            {
                // Camera Pixel Format was changed for Raw Bayer.
                // We set the original value.
                DestroysObjects(null, buffer, transfer, view);

                camera.SetFeatureValue("PixelFormat", oldPixelFormat);

                // Instantiation of new buffer object
                buffer = new SapBufferWithTrash(2, camera, SapBuffer.MemoryType.ScatterGather);
                // Instantiation of new view object
                view = new SapView(buffer);
                // Instantiation of new transfer object
                transfer = new SapAcqDeviceToBuf(camera, buffer);

                // End of frame event
                transfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
                transfer.XferNotify        += new SapXferNotifyHandler(Xfer_XferNotify);
                transfer.XferNotifyContext  = view;

                // Create buffer object
                if (!buffer.Create())
                {
                    Console.WriteLine("Error during SapBuffer creation!\n");
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }

                // Create transfer object
                if (!transfer.Create())
                {
                    Console.WriteLine("Error during SapTransfer creation!\n");
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }

                // Create view object
                if (!view.Create())
                {
                    Console.WriteLine("Error during SapView creation!\n");
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }
            }

            Console.WriteLine("Press any key to start Grab. Press 'q' to quit.\n");
            info = Console.ReadKey(true);
            key  = info.KeyChar;
            if (key != 0)
            {
                if (key == 'q')
                {
                    DestroysObjects(camera, buffer, transfer, view);
                    return;
                }
            }

            // Start continous grab
            transfer.Grab();

            Console.WriteLine("Press any key to stop grab\n");
            Console.ReadKey();

            // Stop grab
            transfer.Freeze();
            transfer.Wait(5000);

            DestroysObjects(camera, buffer, transfer, view);
            location.Dispose();
        }
Example #28
0
        void InitCam(int n)
        {
            while (true)
            {
                try
                {
                    DestroyObjects();
                    DisposeObjects();
                    if (m_online)
                    {
                        m_ServerLocation = new SapLocation("X64-CL_iPro_1", 0);
                        m_ConfigFileName = SystemParam.cmosInfo.ccfPath;//@"C:\Program Files\Teledyne DALSA\Sapera\CamFiles\User\w512x512.ccf";
                        // define on-line object
                        m_Acquisition = new SapAcquisition(m_ServerLocation, m_ConfigFileName);

                        m_Buffers = new SapBufferWithTrash(n, m_Acquisition, SapBuffer.MemoryType.ScatterGather);


                        m_Xfer = new SapAcqToBuf(m_Acquisition, m_Buffers);
                        //                 m_View = new SapView(m_Buffers);
                        //                 m_View.SetScalingMode(true);

                        //event for view
                        m_Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
                        m_Xfer.XferNotify        += new SapXferNotifyHandler(xfer_XferNotify);
                        m_Xfer.XferNotifyContext  = this;

                        // event for signal status
                        m_Acquisition.SignalNotify       += new SapSignalNotifyHandler(GetSignalStatus);
                        m_Acquisition.SignalNotifyContext = this;
                    }
                    else
                    {
                        m_Buffers = new SapBuffer(1, SystemParam.cmosInfo.RowPixels, SystemParam.cmosInfo.ColPixels, SapFormat.Mono16, SapBuffer.MemoryType.ScatterGather);
                        //                 m_View = new SapView(m_Buffers);
                        //                 m_View.SetScalingMode(true);
                        StatusLabelInfo.Text = "offline... Load images";
                    }

                    //m_ImageBox.View = m_View;
                    while (true)
                    {
                        try
                        {
                            if (!CreateObjects())
                            {
                                DisposeObjects();
                                WFNetLib.WFGlobal.WaitMS(20);
                                continue;
                            }
                            break;
                        }
                        catch
                        {
                            WFNetLib.WFGlobal.WaitMS(20);
                        }
                    }
                    SystemParam.cmosInfo.PixelDepth = m_Buffers.PixelDepth;
                    SystemParam.cmosInfo.ColPixels  = m_Buffers.Height;
                    SystemParam.cmosInfo.RowPixels  = m_Buffers.Width;
                    if (SystemParam.cmosInfo.bRGB != 0)
                    {
                        wfSapGUI.GetRGBPixelInfo(SystemParam.cmosInfo.RowPixels, SystemParam.cmosInfo.ColPixels, SystemParam.cmosInfo.RGB1, SystemParam.cmosInfo.RGB2, SystemParam.cmosInfo.RGB3, SystemParam.cmosInfo.RGB4);
                    }
                    SystemParam.Pixel4Pic = (int)SystemParam.cmosInfo.ColPixels * SystemParam.cmosInfo.RowPixels;
                    float WidthScalor  = (float)(splitContainer1.Panel2.Size.Width) / m_Buffers.Width;
                    float HeightScalor = (float)(splitContainer1.Panel2.Size.Height) / m_Buffers.Height;
                    //m_View.SetScalingMode(WidthScalor, HeightScalor);
                    //m_ImageBox.OnSize();
                    EnableSignalStatus();
                    SystemParam.ByteLen4Pic = SystemParam.Pixel4Pic * m_Buffers.BytesPerPixel;
                    m_Xfer.Freeze();
                    return;
                }
                catch
                {
                }
            }
        }
Example #29
0
        public override bool DoInit()
        {
            int DalsaCardCount = SapManager.GetServerCount(); //获取图像采集卡的数量

            for (int i = 0; i < DalsaCardCount; i++)
            {
                bool bAcq       = false;
                bool bAcqDevice = false;
                if (SapManager.GetResourceCount(i, SapManager.ResourceType.Acq) > 0)
                {
                    bAcq = true;                                                                     //卡的数量大于0
                }
                if (SapManager.GetResourceCount(i, SapManager.ResourceType.AcqDevice) > 0)
                {
                    bAcqDevice = true;                                                                    //相机数量大于0
                }
                if (bAcq)
                {
                    string ServerName = SapManager.GetServerName(i);
                    if (this.myCamPara.ServerName == ServerName)
                    {
                        bServerFound = true; //发现图像采集卡
                        string DeviceName = SapManager.GetResourceName(ServerName, SapManager.ResourceType.Acq, 0);
                        if (this.myCamPara.DeviceName != DeviceName)
                        {
                            Logger.PopError("采集卡上找到的相机名字和campara里的名字不同");
                            return(false);
                        }
                    }
                }
                else if (bAcqDevice) //没有采集卡,相机直接传给电脑
                {
                    CameraIsFound = true;
                    string serverName = SapManager.GetServerName(i);
                }
            }
            if (!bServerFound && !CameraIsFound)  //至少需要一张采集卡,或者相机装置
            {
                m_Buffers = new SapBuffer();
                return(false);
            }
            else
            {
                SapLocation location = new SapLocation(this.myCamPara.ServerName, 0);
                if (SapManager.GetResourceCount(this.myCamPara.ServerName, SapManager.ResourceType.Acq) > 0)
                {
                    m_Acquisition = new SapAcquisition(location, System.Windows.Forms.Application.StartupPath + "\\ccf\\" + this.myCamPara.CcfPath + ".ccf");
                    //m_AcqDevice = new SapAcqDevice(location, System.Windows.Forms.Application.StartupPath + "\\ccf\\" + this.myCamPara.CcfPath + ".ccf");
                    if (SapBuffer.IsBufferTypeSupported(location, SapBuffer.MemoryType.ScatterGather))
                    {
                        m_Buffers = new SapBuffer(m_RingBufCount, m_Acquisition, SapBuffer.MemoryType.ScatterGather); //buffer里有10段内存,用来循环存储从相机采集的图片
                    }
                    else
                    {
                        m_Buffers = new SapBufferWithTrash(m_RingBufCount, m_Acquisition, SapBuffer.MemoryType.ScatterGatherPhysical);
                    }
                    m_Xfer = new SapAcqToBuf(m_Acquisition, m_Buffers);
                    m_Xfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame;
                    m_Xfer.XferNotify        += new SapXferNotifyHandler(AcqCallback1);
                    m_Xfer.XferNotifyContext  = this;
                    // event for signal status
                    if (!SeparaInterface_CreateObjects())
                    {
                        Logger.PopError(" 创建 相关的采集、传输、缓存对象失败");
                        this.SeparaInterface_DisposeObjects();
                        return(false);
                    }
                    this.FrameImgHei = this.SeparaInterface_GetImageHeight();
                    this.FrameImgWid = this.SeparaInterface_GetImageWidth();
                    return(true);
                }
            }
            return(false);
        }
Example #30
0
        //
        // Step 2: Snap a bright image to calculate the gain coefficients
        //
        private void button_Acq_Bright_Click(object sender, EventArgs e)
        {
            int nbImagesUsed = m_pFlatField.CorrectionType == SapFlatField.ScanCorrectionType.Field ? int.Parse(textBox_Frame_Avg.Text) : 1;

            // Set maximum deviation from average pixel value for bright image
            m_pFlatField.DeviationMaxWhite = int.Parse(textBox_Max_Dev.Text);

            // Set number of lines to average and vertical offset
            m_pFlatField.NumLinesAverage = int.Parse(textBox_Line_Avg.Text);
            m_pFlatField.VerticalOffset  = int.Parse(textBox_Vert_Offset.Text);

            // Set wether to declare pixels with clipped coefficient as defective
            m_pFlatField.ClippedGainOffsetDefects = ClippedCoefsDefects_checkbox.Checked;

            if (m_pXfer != null && m_pXfer.Initialized)
            {
                m_pLocalBuffer = new SapBuffer(nbImagesUsed, m_pBuffer, SapBuffer.MemoryType.Default);
                m_pLocalBuffer.Create();

                // Acquire an image
                if (!Snap())
                {
                    LogMessage(LogTypes.Error, "Unable to acquire an image");
                    if (m_pLocalBuffer != null)
                    {
                        m_pLocalBuffer.Destroy();
                        m_pLocalBuffer.Dispose();
                        m_pLocalBuffer = null;
                    }
                    return;
                }
            }
            else
            {
                // Load an image
                m_pLocalBuffer = new SapBuffer(1, m_pBuffer, SapBuffer.MemoryType.Default);
                m_pLocalBuffer.Create();


                LoadSaveDlg dlg = new LoadSaveDlg(null, true, false);
                if (dlg.ShowDialog() != DialogResult.OK)
                {
                    if (m_pLocalBuffer != null)
                    {
                        m_pLocalBuffer.Destroy();
                        m_pLocalBuffer.Dispose();
                        m_pLocalBuffer = null;
                    }
                    return;
                }

                String path = dlg.PathName;

                // Create a temporary buffer in order to know the selected file's native format and pixel depth

                SapBuffer loadBuffer = new SapBuffer(path, SapBuffer.MemoryType.Default);
                loadBuffer.Create();

                if (loadBuffer.Format != m_pBuffer.Format || loadBuffer.PixelDepth != m_pBuffer.PixelDepth)
                {
                    LogMessage(LogTypes.Warning, "Image file has a different format than expected.  Pixel values may get shifted.");
                }

                if (loadBuffer.Width != m_pBuffer.Width || loadBuffer.Height != m_pBuffer.Height)
                {
                    LogMessage(LogTypes.Error, "Image file selected doesn't have same dimensions as buffer.");
                    if (m_pLocalBuffer != null)
                    {
                        m_pLocalBuffer.Destroy();
                        m_pLocalBuffer.Dispose();
                        m_pLocalBuffer = null;
                    }
                    return;
                }

                loadBuffer.Load(path, 1);
                m_pLocalBuffer.Copy(loadBuffer);

                String str;
                str = String.Format("Loaded bright image: '{0}'", path);
                LogMessage(LogTypes.Info, str);
            }

            BrightImage();
        }
Example #31
0
 public void CreatEndSqObject(SapBuffer buf, SapTransfer xfer, SapView view)
 {
     buf.Create();
     xfer.Create();
     //view.Create();
 }