Example #1
0
        static void Main(string[] args)
        {
            PrintBuildInfo();

            Program program = new Program();

            // Since this application saves images in the current folder
            // we must ensure that we have permission to write to this folder.
            // If we do not have permission, fail right away.
            FileStream fileStream;

            try
            {
                fileStream = new FileStream(@"test.txt", FileMode.Create);
                fileStream.Close();
                File.Delete("test.txt");
            }
            catch
            {
                Console.WriteLine("Failed to create file in current folder.  Please check permissions.\n");
                return;
            }

            ManagedBusManager busMgr = new ManagedBusManager();

            CameraInfo[] camInfos = ManagedBusManager.DiscoverGigECameras();
            Console.WriteLine("Number of cameras discovered: {0}", camInfos.Length);
            foreach (CameraInfo camInfo in camInfos)
            {
                PrintCameraInfo(camInfo);
            }

            uint numCameras = busMgr.GetNumOfCameras();

            Console.WriteLine("Number of cameras enumerated: {0}", numCameras);

            for (uint i = 0; i < numCameras; i++)
            {
                ManagedPGRGuid guid = busMgr.GetCameraFromIndex(i);
                if (busMgr.GetInterfaceTypeFromGuid(guid) != InterfaceType.GigE)
                {
                    continue;
                }

                try
                {
                    program.RunSingleCamera(guid);
                }
                catch (FC2Exception ex)
                {
                    Console.WriteLine(
                        String.Format(
                            "Error running camera {0}. Error: {1}",
                            i, ex.Message));
                }
            }

            Console.WriteLine("Done! Press any key to exit...");
            Console.ReadKey();
        }
Example #2
0
        static void Main(string[] args)
        {
            PrintBuildInfo();

            Program program = new Program();

            ManagedBusManager busMgr = new ManagedBusManager();
            uint numCameras          = busMgr.GetNumOfCameras();

            Console.WriteLine("Number of cameras detected: {0}", numCameras);

            // Finish if there are no cameras
            if (numCameras == 0)
            {
                Console.WriteLine("Not enough cameras!");
                Console.WriteLine("Press Enter to exit...");
                Console.ReadLine();
                return;
            }

            for (uint i = 0; i < numCameras; i++)
            {
                ManagedPGRGuid guid = busMgr.GetCameraFromIndex(i);

                program.RunSingleCamera(guid);
            }

            Console.WriteLine("Done! Press enter to exit...");
            Console.ReadLine();
        }
Example #3
0
        private void OpenCamera()
        {
            try
            {
                System.Diagnostics.Debug.WriteLine("OpenCamera:" + DateTime.Now.ToString("HH:mm:ss.fff"));
                ManagedBusManager busMgr = new ManagedBusManager();
                uint numCameras          = busMgr.GetNumOfCameras();
                if (numCameras == 0)
                {
                    System.Diagnostics.Debug.WriteLine("没有发现相机!");
                    return;
                }
                m_camera = new ManagedCamera();

                //m_processedImage = new ManagedImage();
                m_grabThreadExited = new AutoResetEvent(false);
                ManagedPGRGuid m_guid = busMgr.GetCameraFromIndex(0);

                // Connect to the first selected GUID
                m_camera.Connect(m_guid);

                // Set embedded timestamp to on
                EmbeddedImageInfo embeddedInfo = m_camera.GetEmbeddedImageInfo();
                embeddedInfo.timestamp.onOff = true;
                m_camera.SetEmbeddedImageInfo(embeddedInfo);

                m_camera.StartCapture();
                System.Diagnostics.Debug.WriteLine("OpenCamera:" + DateTime.Now.ToString("HH:mm:ss.fff"));
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
Example #4
0
        /// <summary>
        /// Attempt to connect to camera
        /// </summary>
        /// <returns>True if connection is successful</returns>
        public bool Initialize()
        {
            ManagedBusManager busMgr = new ManagedBusManager();

            try
            {
                ManagedPGRGuid guid = busMgr.GetCameraFromSerialNumber(this.serial);
                this.camera.Connect(guid);
                GigEImageSettings config = this.camera.GetGigEImageSettings();
                config.height  = this.PixelHeight;
                config.width   = this.PixelWidth;
                config.offsetX = (2448 - this.PixelWidth) / 2;
                config.offsetY = (2048 - this.PixelHeight) / 2;
                this.camera.SetGigEImageSettings(config);
            }
            catch (Exception ex)
            {
                // Connection unsuccessful
                Logger.Out(ex.ToString());
                this.Connected = false;
                return(false);
            }
            // Set embedded timestamp to on
            EmbeddedImageInfo embeddedInfo = this.camera.GetEmbeddedImageInfo();

            embeddedInfo.timestamp.onOff = true;
            this.camera.SetEmbeddedImageInfo(embeddedInfo);
            // Start live capture
            this.Connected = true;
            this.Start();
            return(true);
        }
Example #5
0
        public void ReconnectCamera(ManagedPGRGuid guid)
        {
            lock (this)
            {
                if (m_isConnected == true)
                {
                    try
                    {
                        if (m_camera.IsConnected())
                        {
                            m_camera.Disconnect();
                            m_camera.Connect(guid);
                        }
                        else
                        {
                            m_camera.Connect(guid);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }

                Debug.WriteLine("Reconnected to camera");
            }
        }
        // calibrator constructor#2
        public Flea3Calibrator(int horiz_corner_count, int vert_corner_count,
                               float rect_width, float rect_height, int frame_count, PictureBox displaybox)
        {
            DisplayBox = displaybox;
            // 1. creating the camera object
            Cam = new ManagedCamera();
            // 2. creating the bus manager in order to handle (potentially)
            // multiple cameras
            BusMgr = new ManagedBusManager();

            // 3. retrieving the List of all camera ids connected to the bus
            CamIDs = new List <ManagedPGRGuid>();
            int camCount = (int)BusMgr.GetNumOfCameras();

            for (int i = 0; i < camCount; i++)
            {
                ManagedPGRGuid guid = BusMgr.GetCameraFromIndex((uint)i);
                CamIDs.Add(guid);
            }


            FrameCount      = frame_count;
            ChessHorizCount = horiz_corner_count;
            ChessVertCount  = vert_corner_count;

            RectWidth  = rect_width;
            RectHeight = rect_height;

            // creatring the imageViewer to display the calibration frame sequence
            //imageViewer = new ImageViewer();


            state = ST_IDLE;
        }
        // calibrator deafult constructor
        public Flea3Calibrator(PictureBox displaybox)
        {
            DisplayBox = displaybox;
            // 1. creating the camera object
            Cam = new ManagedCamera();
            // 2. creating the bus manager in order to handle (potentially)
            // multiple cameras
            BusMgr = new ManagedBusManager();

            // 3. retrieving the List of all camera ids connected to the bus
            CamIDs = new List <ManagedPGRGuid>();
            int camCount = (int)BusMgr.GetNumOfCameras();

            for (int i = 0; i < camCount; i++)
            {
                ManagedPGRGuid guid = BusMgr.GetCameraFromIndex((uint)i);
                CamIDs.Add(guid);
            }


            FrameCount      = FRAME_COUNT;
            ChessHorizCount = CHESS_HORIZ_CORNER_COUNT;
            ChessVertCount  = CHESS_VERT_CORNER_COUNT;

            RectWidth  = RECT_WIDTH;
            RectHeight = RECT_HEIGHT;

            // creatring the imageViewer to display the calibration frame sequence
            //imageViewer = new ImageViewer();


            state = ST_IDLE;
        }
Example #8
0
 public NodeSurface()
 {
     m_xPos     = 0;
     m_yPos     = 0;
     m_guid     = new ManagedPGRGuid();
     m_deviceId = 0;
     m_surface  = new Bitmap(NodeWidth, NodeHeight);
 }
Example #9
0
        static void Main(string[] args)
        {
            PrintBuildInfo();
            Program    program = new Program();
            SerialPort pyboard = new SerialPort("COM5", 115200);

            pyboard.Open();
            pyboard.WriteLine("import rig_load\r");
            FileStream fileStream;
            //try
            //{
            //    fileStream = new FileStream(@"test.txt", FileMode.Create);
            //    fileStream.Close();
            //    File.Delete("test.txt");
            //}
            //catch
            //{
            //    Console.WriteLine("Failed to create file in current folder.  Please check permissions.\n");
            //    return;
            //}

// Here want to take the ID number of the experiment instead of the total number of frames. The number of frames will be set by the set experiment parameters established. Have user input from console.writeline "Please Enter Experiment ID". saveto will occur after the input of this line, and will be "D:/"+idstring+"cam0.AVI". etc. int frames, instead of being framestring, will just be a constant. calculate this tomorrow after you've established the exact paradigm.

            ManagedBusManager busMgr = new ManagedBusManager();
            uint numCameras          = busMgr.GetNumOfCameras();

            Console.WriteLine("Number of cameras detected: {0}", numCameras);

            // List<string> save_to = new List<string>{"D:/Movies/cam0.AVI","E:/Movies/cam1.AVI"};
            Console.WriteLine("Please Enter Experiment ID: ");
            string        idstring = Console.ReadLine();
            List <string> save_to  = new List <string> {
                "D:/Movies/" + idstring + "_cam0.AVI", "E:/Movies/" + idstring + "_cam1.AVI"
            };

            Console.WriteLine("Please Enter Number of Frames: ");
            string framestring = Console.ReadLine();
            int    frames      = Convert.ToInt32(framestring);

            if (numCameras == 1)
            {
                ManagedPGRGuid guid = busMgr.GetCameraFromIndex(0);
                program.RunSingleCamera(guid, "C:/Users/Deadpool/Desktop/flea3.AVI", frames);
            }
            else if (numCameras == 2)
            {
                ManagedPGRGuid camid1     = busMgr.GetCameraFromIndex(0);
                ManagedPGRGuid camid2     = busMgr.GetCameraFromIndex(1);
                Thread         camthread1 = new Thread(() => program.RunSingleCamera(camid1, save_to[0], frames));
                camthread1.Start();
// have to declare this way if your return is a void but you pass variables to the function
                Thread camthread2 = new Thread(() => program.RunSingleCamera(camid2, save_to[1], frames));
                camthread2.Start();
                pyboard.WriteLine("rig_load.full_experiment(True,True)\r");
//                pyboard.WriteLine("rig_load.full_experiment(True,True)\r");
//                pyboard.WriteLine("rig_load.light_test()\r");
            }
        }
Example #10
0
 private static bool IsGuidValid(ManagedPGRGuid guid)
 {
     if (guid.Equals(new ManagedPGRGuid()) == false)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #11
0
        private void OnDrawingAreaMouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                // In this case, we can not use e.X and e.Y for calculation
                // because e.X and e.Y are the value which is a related value (not abs value).
                // The picture box scroll position will be changed, and that will effect e.X and e.Y.
                // We must use absolute mouse position here, so I use Cursor.Position instead.
                int x = -m_imagePanel.AutoScrollPosition.X - (Cursor.Position.X - m_prevMousePosX);
                int y = -m_imagePanel.AutoScrollPosition.Y - (Cursor.Position.Y - m_prevMousePosY);
                m_imagePanel.AutoScrollPosition = new Point(x, y);
                m_prevMousePosX = Cursor.Position.X;
                m_prevMousePosY = Cursor.Position.Y;
                m_drawingArea.Refresh();
            }
            else
            {
                Cursor.Current = Cursors.Default;
            }

            ManagedPGRGuid mouseOverGuid    = new ManagedPGRGuid();
            bool           isMouseOverValid = IsSelectionValid(e, ref mouseOverGuid);

            if (!isMouseOverValid)
            {
                cameraInfoToolTip.Active = false;
                return;
            }

            Control ctlSender            = (Control)sender;
            string  currentTooltipString = cameraInfoToolTip.GetToolTip(ctlSender);
            string  newTooltipString     = string.Empty;

            try
            {
                newTooltipString = GenerateToolTipString(mouseOverGuid);
            }
            catch (FC2Exception ex)
            {
                cameraInfoToolTip.Active = false;
                ex.Dispose();
                return;
            }

            // Only set the tooltip string if the string has changed, this
            // prevents a nasty flicker problem that can occur as the
            // string is drawn repeatedly
            if (currentTooltipString != newTooltipString)
            {
                cameraInfoToolTip.SetToolTip(ctlSender, newTooltipString);
            }

            cameraInfoToolTip.Active = true;
        }
Example #12
0
        private void UpdatePhyRegisters()
        {
            ManagedPGRGuid nullGuid = new ManagedPGRGuid();

            if (m_selectedGuid.Equals(m_nodeDesc.Guid))
            {
                return;
            }

            ResetRegisterPane();

            if (m_selectedGuid.Equals(nullGuid))
            {
                m_nodeDesc.Guid = nullGuid;
                return;
            }

            Field vendorID;

            if (GetVendorID(m_selectedGuid, out vendorID) == false)
            {
                m_nodeDesc.Guid = nullGuid;
                ResetRegisterPane();
                return;
            }

            try
            {
                m_nodeTreeView.BeginUpdate();
                TreeNode currentTreeNode = m_nodeTreeView.Nodes.Add(string.Format("{0} Chipset", vendorID.Name));

                // add base register heading
                TreeNode tempNode = currentTreeNode.Nodes.Add("Base Registers");
                tempNode.Tag = "B#0"; // B#0 is id for this new node
                uint numPorts = GetNumberOfPorts(m_selectedGuid);

                // add port headings
                for (uint i = 0; i < numPorts; i++)
                {
                    tempNode     = currentTreeNode.Nodes.Add(string.Format("Port {0}", i));
                    tempNode.Tag = string.Format("P#{0}", i); // this is id for this new node
                }

                m_nodeTreeView.ExpandAll();
                m_nodeTreeView.EndUpdate();
            }
            catch (ArgumentException ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
                return;
            }
        }
Example #13
0
        private bool GetPGRGuidFromRowIndex(int rowIndex, out ManagedPGRGuid guid)
        {
            uint cameraSerialNumber = 0;

            if (m_cameraDataGridView.Rows[rowIndex].Cells[0].Value == null)
            {
                Debug.WriteLine("Unable to get camera information. Nothing in row: " + rowIndex);
                guid = new ManagedPGRGuid();
                return(false);
            }

            try
            {
                cameraSerialNumber = Convert.ToUInt32(m_cameraDataGridView.Rows[rowIndex].Cells[0].Value);
            }
            catch (ArgumentException ex)
            {
                Debug.WriteLine("Invalid serial number.");
                Debug.WriteLine(ex.Message);
                guid = new ManagedPGRGuid();
                return(false);
            }
            catch (FormatException ex)
            {
                Debug.WriteLine("Invalid format for serial number.");
                Debug.WriteLine(ex.Message);
                guid = new ManagedPGRGuid();
                return(false);
            }
            catch (OverflowException ex)
            {
                Debug.WriteLine("The serial number is too long.");
                Debug.WriteLine(ex.Message);
                guid = new ManagedPGRGuid();
                return(false);
            }

            try
            {
                guid = m_busMgr.GetCameraFromSerialNumber(cameraSerialNumber);
            }
            catch (FC2Exception ex)
            {
                Debug.WriteLine("The camera with serial number not found.");
                Debug.WriteLine(ex.Message);
                guid = new ManagedPGRGuid();
                ex.Dispose();
                return(false);
            }

            return(true);
        }
Example #14
0
        private void InitializePage()
        {
            m_busMgr      = new ManagedBusManager();
            m_imageWidth  = m_drawingArea.Width;
            m_imageHeight = m_drawingArea.Height;
            ResetNodeInformation();
            OnRefreshTopology();
            SetColors();

            if (m_camInfo != null)
            {
                m_currCameraGuid = m_busMgr.GetCameraFromSerialNumber(m_camInfo.serialNumber);
            }
        }
Example #15
0
        public bool Connect()
        {
            bool flag = false;
            CameraSelectionDialog camSlnDlg = new CameraSelectionDialog();

            camSlnDlg.Show();
            camSlnDlg.Hide();

            //if (camSlnDlg.ShowModal())
            {
                try {
                    ManagedPGRGuid[] selectedGuids = camSlnDlg.GetSelectedCameraGuids();
                    ManagedPGRGuid   guidToUse     = selectedGuids[0];

                    ManagedBusManager busMgr = new ManagedBusManager();
                    m_camera = new ManagedCamera();

                    // Connect to the first selected GUID
                    m_camera.Connect(guidToUse);
                    m_camCtlDlg.Connect(m_camera);

                    CameraInfo camInfo = m_camera.GetCameraInfo();
                    camInfo.vendorName = "MicroTest";
                    camInfo.modelName  = "v1";
                    // UpdateFormCaption(camInfo);

                    // Set embedded timestamp to on
                    EmbeddedImageInfo embeddedInfo = m_camera.GetEmbeddedImageInfo();
                    embeddedInfo.timestamp.onOff = true;
                    //embeddedInfo.exposure.onOff = true;
                    embeddedInfo.shutter.onOff = true;
                    //tbox_uptime.Text = embeddedInfo.timestamp.ToString();
                    m_camera.SetEmbeddedImageInfo(embeddedInfo);
                    flag = true;
                }
                catch (IndexOutOfRangeException e) {
                    m_camCtlDlg.Disconnect();

                    if (m_camera != null)
                    {
                        m_camera.Disconnect();
                    }
                    flag = false;
                    throw e;
                }
            }

            return(flag);
        }
Example #16
0
        static void Main(string[] args)
        {
            PrintBuildInfo();

            Program program = new Program();

            // Since this application saves images in the current folder
            // we must ensure that we have permission to write to this folder.
            // If we do not have permission, fail right away.
            FileStream fileStream;

            try
            {
                fileStream = new FileStream(@"test.txt", FileMode.Create);
                fileStream.Close();
                File.Delete("test.txt");
            }
            catch
            {
                Console.WriteLine("Failed to create file in current folder. Please check permissions.");
                Console.WriteLine("Press Enter to exit...");
                Console.ReadLine();
                return;
            }

            ManagedBusManager busMgr = new ManagedBusManager();
            uint numCameras          = busMgr.GetNumOfCameras();

            Console.WriteLine("Number of cameras detected: {0}", numCameras);

            // Finish if there are no cameras
            if (numCameras == 0)
            {
                Console.WriteLine("Not enough cameras!");
                Console.WriteLine("Press Enter to exit...");
                Console.ReadLine();
                return;
            }

            for (uint i = 0; i < numCameras; i++)
            {
                ManagedPGRGuid guid = busMgr.GetCameraFromIndex(i);

                program.RunCamera(guid);
            }

            Console.WriteLine("Done! Press enter to exit...");
            Console.ReadLine();
        }
Example #17
0
        public ManagedPGRGuid[] GetCurrentSelectedGuids()
        {
            DataGridViewSelectedRowCollection rows = m_cameraDataGridView.SelectedRows;

            ManagedPGRGuid[] result = new ManagedPGRGuid[rows.Count];
            result.Initialize();
            for (int i = 0; i < result.Length; i++)
            {
                if (GetPGRGuidFromRowIndex(rows[i].Index, out result[i]) == false)
                {
                    Debug.WriteLine("Detected invalid Guid. At row index: " + rows[i].Index);
                }
            }

            return(result);
        }
Example #18
0
        private string GenerateToolTipString(ManagedPGRGuid guid)
        {
            if (guid.Equals(m_lastTooltipGuid))
            {
                return(m_tooltipString);
            }

            m_lastTooltipGuid = guid;

            if (guid.Equals(m_currCameraGuid))
            {
                StringBuilder tooltipStr = new StringBuilder();
                tooltipStr.AppendFormat("Camera: {0} {1} ({2})", m_camInfo.vendorName, m_camInfo.modelName, m_camInfo.serialNumber).AppendLine();
                tooltipStr.AppendFormat("Sensor: {0}", m_camInfo.sensorInfo).AppendLine();
                tooltipStr.AppendFormat("Firmware: {0} Built: {1}", m_camInfo.firmwareVersion, m_camInfo.firmwareBuildTime).AppendLine();
                tooltipStr.AppendFormat("Driver: {0}", m_camInfo.driverName).AppendLine();

                m_tooltipString = tooltipStr.ToString();
                return(m_tooltipString);
            }

            ManagedCameraBase tempCamera = null;

            if (m_busMgr.GetInterfaceTypeFromGuid(guid) == InterfaceType.GigE)
            {
                tempCamera = new ManagedGigECamera();
            }
            else
            {
                tempCamera = new ManagedCamera();
            }

            using (tempCamera)
            {
                tempCamera.Connect(guid);
                CameraInfo camInfo = tempCamera.GetCameraInfo();

                StringBuilder tooltipStr = new StringBuilder();
                tooltipStr.AppendFormat("Camera: {0} {1} ({2})", camInfo.vendorName, camInfo.modelName, camInfo.serialNumber).AppendLine();
                tooltipStr.AppendFormat("Sensor: {0}", camInfo.sensorInfo).AppendLine();
                tooltipStr.AppendFormat("Firmware: {0} Built: {1}", camInfo.firmwareVersion, camInfo.firmwareBuildTime).AppendLine();
                tooltipStr.AppendFormat("Driver: {0}", camInfo.driverName).AppendLine();

                m_tooltipString = tooltipStr.ToString();
                return(m_tooltipString);
            }
        }
Example #19
0
        static void Main()
        {
            ManagedBusManager busMgr = new ManagedBusManager();

            // Pop up the camera selection dialog
            FlyCapture2Managed.Gui.CameraSelectionDialog camSlnDlg = new FlyCapture2Managed.Gui.CameraSelectionDialog();
            if (camSlnDlg.ShowModal() == false)
            {
                MessageBox.Show("No cameras selected.", "Flycapture2", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            ManagedPGRGuid[] selectedGuids = camSlnDlg.GetSelectedCameraGuids();

            // Only start the first selected camera
            ManagedPGRGuid    guid = selectedGuids[0];
            InterfaceType     ifType;
            ManagedCameraBase camera;

            try
            {
                ifType = busMgr.GetInterfaceTypeFromGuid(guid);//unable to handle this error
            }
            catch (FC2Exception ex)
            {
                string error = string.Format("Failed to get interface for camera. {0}", ex.Message);
                Console.WriteLine(error);
                MessageBox.Show(error, "Flycapture 2", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (ifType == InterfaceType.GigE)
            {
                camera = new ManagedGigECamera();
            }
            else
            {
                camera = new ManagedCamera();
            }
            camera.Connect(guid);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            CameraControlMainFrame mainWindow = new CameraControlMainFrame();

            mainWindow.Connect(camera);
            mainWindow.ShowWindow();
        }
Example #20
0
        public bool CamConnection(uint[] serialList)
        {
            NumCameras = serialList.Length;
            ManagedBusManager busMgr = new ManagedBusManager();

            mCameras = new ManagedGigECamera[NumCameras];

            for (uint i = 0; i < NumCameras; i++)
            {
                if (serialList[i] == 0)
                {
                    continue;
                }

                mCameras[i] = new ManagedGigECamera();

                try
                {
                    ManagedPGRGuid guid = busMgr.GetCameraFromSerialNumber(serialList[i]);

                    // Connect to a camera
                    mCameras[i].Connect(guid);

                    // Turn trigger mode off
                    TriggerMode trigMode = new TriggerMode();
                    trigMode.onOff = false;
                    mCameras[i].SetTriggerMode(trigMode);

                    // Turn Timestamp on
                    EmbeddedImageInfo imageInfo = new EmbeddedImageInfo();
                    imageInfo.timestamp.onOff = true;
                    mCameras[i].SetEmbeddedImageInfo(imageInfo);

                    //IsConnected[i] = true;

                    GV.IsCameraConnected = true;
                }
                catch (Exception ex)
                {
                    //IsConnected[i] = false;

                    GV.IsCameraConnected = false;
                    return(false);
                }
            }
            return(true);
        }
Example #21
0
        public void Update(ManagedTopologyNode node, bool selected)
        {
            Debug.Assert(node != null, "node paramter is null");
            if (node == null)
            {
                return;
            }

            // Store the PGRGuid so we can handle device information on clicks
            m_guid     = node.GetGuid();
            m_deviceId = node.GetDeviceId();

            // Create a context for the surface
            Graphics surfaceGraphics = Graphics.FromImage(m_surface);

            surfaceGraphics.Clear(Color.White);

            Pen pen;

            if (selected == true)
            {
                pen = new Pen(Color.Red, 3);
            }
            else
            {
                pen = new Pen(Color.Black, 1);
            }

            using (pen)
            {
                int width  = m_surface.Width;
                int height = m_surface.Height;

                Rectangle surfaceRectangle = new Rectangle(
                    0 + RoundedRectangleMargin,
                    0 + RoundedRectangleMargin,
                    width - (2 * RoundedRectangleMargin),
                    height - (2 * RoundedRectangleMargin));

                const int Radius = 20;
                DrawRoundedRectangle(surfaceGraphics, surfaceRectangle, Radius, pen, GetNodeColor(node.GetNodeType()));

                DrawTextToGraphics(GetNodeText(node), surfaceGraphics, width, height);

                DrawPorts(node, surfaceGraphics);
            }
        }
Example #22
0
        void RunSingleCamera(ManagedPGRGuid guid)
        {
            const int k_numImages = 10;

            ManagedCamera cam = new ManagedCamera();

            // Connect to a camera
            cam.Connect(guid);

            // Get the camera information
            CameraInfo camInfo = cam.GetCameraInfo();

            PrintCameraInfo(camInfo);

            // Get embedded image info from camera
            EmbeddedImageInfo embeddedInfo = cam.GetEmbeddedImageInfo();

            // Enable timestamp collection
            if (embeddedInfo.timestamp.available == true)
            {
                embeddedInfo.timestamp.onOff = true;
            }

            // Set embedded image info to camera
            cam.SetEmbeddedImageInfo(embeddedInfo);

            // Start capturing images
            cam.StartCapture(OnImageGrabbed);

            CameraProperty frameRateProp = cam.GetProperty(PropertyType.FrameRate);

            while (imageCnt < 10)
            {
                int millisecondsToSleep = (int)(1000 / frameRateProp.absValue);
                Thread.Sleep(millisecondsToSleep);
            }

            // Stop capturing images
            cam.StopCapture();

            // Disconnect the camera
            cam.Disconnect();

            // Reset counter for next iteration
            imageCnt = 0;
        }
Example #23
0
        private uint GetNumberOfPorts(ManagedPGRGuid guid)
        {
            uint regVal;

            try
            {
                regVal = m_busMgr.ReadPhyRegister(
                    guid,
                    k_basePage,
                    0,
                    k_baseRegisterInfo[k_totalPortsField].Address);
            }
            catch (FC2Exception ex)
            {
                return(0);
            }

            return(GetField(k_baseRegisterInfo[k_totalPortsField], regVal));
        }
Example #24
0
        /// <summary>
        ///Initialize a point Grey Camera, it take the first that it detect if their is more than one.
        ///Give the default setting.
        /// </summary>
        /// <exception cref="NoCameraDetectedException">Thrown if no camera is detected.</exception>
        public PtGreyCamera()
        {
            using ManagedBusManager busMgr = new ManagedBusManager();
            setting = new PtGreyCameraSetting();
            uint numCameras = busMgr.GetNumOfCameras();

            if (numCameras == 0)
            {
                throw new NoCameraDetectedException {
                          Source = "PointGrey"
                };
            }

            ManagedPGRGuid guid = busMgr.GetCameraFromIndex(0); //If there is more than 1 camera, we take the first one

            cam = new ManagedCamera();
            cam.Connect(guid);
            SetProp();
        }
Example #25
0
        static void Main(string[] args)
        {
            PrintBuildInfo();

            Program program = new Program();

            ManagedBusManager busMgr = new ManagedBusManager();
            uint numCameras          = busMgr.GetNumOfCameras();

            Console.WriteLine("Number of cameras detected: {0}", numCameras);

            for (uint i = 0; i < numCameras; i++)
            {
                ManagedPGRGuid guid = busMgr.GetCameraFromIndex(i);

                program.RunSingleCamera(guid);
            }

            Console.WriteLine("Done! Press any key to exit...");
            Console.ReadKey();
        }
Example #26
0
        /// <summary>
        ///Initialize a point Grey Camera, it take the first that it detect if their is more than one.
        ///Utilize the given settings to initialize the camera.
        /// </summary>
        /// <exception cref="NoCameraDetectedException">Thrown if no camera is detected.</exception>
        /// <param name="setting">Setting used for the camera</param>
        public PtGreyCamera(PtGreyCameraSetting setting)
        {
            using ManagedBusManager busMgr = new ManagedBusManager();
            this.setting = setting;
            uint numCameras = busMgr.GetNumOfCameras();

            Console.WriteLine(numCameras);
            // Finish if there are no cameras
            if (numCameras == 0)
            {
                throw new NoCameraDetectedException();
            }

            ManagedPGRGuid guid = busMgr.GetCameraFromIndex(0); //If there is more than 1 camera, we take the first one

            cam = new ManagedCamera();

            cam.Connect(guid);

            SetProp();
        }
Example #27
0
        private bool GetVendorID(ManagedPGRGuid guid, out Field vendorID)
        {
            vendorID = new Field("Node", 0);

            uint regVal    = 0;
            uint vendorVal = 0;

            // read vendor id registers
            for (uint i = 10; i <= 12; i++)
            {
                try
                {
                    regVal = m_busMgr.ReadPhyRegister(guid, k_vendorPage, 0, i);
                }
                catch (FC2Exception ex)
                {
                    ex.Dispose();
                    return(false);
                }

                vendorVal = (vendorVal << 8) | regVal;
            }

            vendorID.ID = vendorVal;

            uint count;

            for (count = 0; count < k_vendorList.Length; count++)
            {
                if (vendorVal == k_vendorList[count].ID)
                {
                    vendorID.Name = k_vendorList[count].Name;
                    break;
                }
            }

            return(true);
        }
        // A timer used to sample the IMU during the intervals betweem frame captures
        //private System.Timers.Timer IMUSamplingTimer;


        public Flea3Recorder(GPSReceiver gpsReceiver, IMUCommsDevice imu)
        {
            int i;

            IMUcomms = imu;



            // 1. creating the camera object
            Cam = new ManagedCamera();
            // 2. creating the bus manager in order to handle (potentially)
            // multiple cameras
            BusMgr = new ManagedBusManager();

            // 3. retrieving the List of all camera ids connected to the bus
            CamIDs = new List <ManagedPGRGuid>();
            int camCount = (int)BusMgr.GetNumOfCameras();

            for (i = 0; i < camCount; i++)
            {
                ManagedPGRGuid guid = BusMgr.GetCameraFromIndex((uint)i);
                CamIDs.Add(guid);
            }

            // 4. assigning values to properties
            GpsReceiver = gpsReceiver;

            // 5. init flags
            RecordingThreadActive = false;

            RecordToFile = false;

            OutOfRecordingThread = OutOfDumpingThread = true;

            // 6. Creating the Frame data queue
            FrameQueue = new ManagedImageRollingBuffer(MAX_FRAMEQUEUE_LEN);
        }
Example #29
0
        /// <summary>
        /// 连接相机
        /// </summary>
        /// <param name="SerialNumber"></param>
        /// <returns></returns>
        bool ConnectCamera(string SerialNumber)
        {
            try
            {
#if (SDK)
                ManagedBusManager busMgr = new ManagedBusManager();
                //相机索引号
                uint           intSerialNumber = uint.Parse(SerialNumber);
                ManagedPGRGuid guid            = busMgr.GetCameraFromSerialNumber(intSerialNumber);
                InterfaceType  Type            = busMgr.GetInterfaceTypeFromGuid(guid);

                if (Type == InterfaceType.GigE)
                {
                    g_ManagedCameraBase = new ManagedGigECamera();
                    g_ManagedCameraBase.Connect(guid);

                    SetGigEPacketResend();//设置丢帧重传
                }
                else
                {
                    g_ManagedCameraBase = new ManagedCamera();
                    g_ManagedCameraBase.Connect(guid);
                }

                if (g_BaseParCamera.BlUsingTrigger)
                {
                    SetSoftTrriger(true);//设置触发
                }
#endif
                return(true);
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
                return(false);
            }
        }
Example #30
0
        private void UpdateNodeInformation(ManagedPGRGuid guidToUse)
        {
            // Fix for Bug 22724
            if (guidToUse.Equals(m_currCameraGuid))
            {
                UpdateNodeModelInformation(m_camInfo);
                UpdateNodeProductIDInformation();
                UpdateNodeVoltageInformation(m_camera);
                UpdateNodeCurrentInformation(m_camera, m_camInfo);
                UpdatePhyRegisters();
            }
            else
            {
                using (ManagedCamera camera = new ManagedCamera())
                {
                    CameraInfo camInfo;

                    try
                    {
                        camera.Connect(guidToUse);
                        camInfo = camera.GetCameraInfo();
                    }
                    catch (FC2Exception ex)
                    {
                        UpdatePhyRegisters();
                        ex.Dispose();
                        return;
                    }

                    UpdateNodeModelInformation(camInfo);
                    UpdateNodeProductIDInformation();
                    UpdateNodeVoltageInformation(camera);
                    UpdateNodeCurrentInformation(camera, camInfo);
                    UpdatePhyRegisters();
                }
            }
        }
        public void startCalibration(int vidmode, ManagedPGRGuid camGuid)
        {
            int i, j;

            VidMode = vidmode;

            // Starting the camera
            // 1. connect to the camera
            Cam.Connect(camGuid);

            // 2. setting up the video mode
            if (VidMode == 0)
            {
                Cam.SetVideoModeAndFrameRate(VideoMode.VideoMode1600x1200Yuv422, FrameRate.FrameRate30);

            }
            else if (VidMode == 1)
            {
                Cam.SetVideoModeAndFrameRate(VideoMode.VideoMode1600x1200Rgb, FrameRate.FrameRate15);

            }
            else if (VidMode == 2)
            {
                Format7ImageSettings fset = new Format7ImageSettings();
                fset.height = 540;
                fset.width = 960;
                fset.offsetX = 40;
                fset.offsetY = 118;
                fset.mode = Mode.Mode4;

                fset.pixelFormat = PixelFormat.PixelFormatRgb8;

                Cam.SetFormat7Configuration(fset, 40.0f); // this equivalent to 24 fps

            }

            // creating the thread
            CalibrationThread = new Thread(MainLoop);

            // zeroing the index of frame counter
            FrameCounter = 0;

            // creating the point detected storage array
            Points  = new PointF[FrameCount][];
            ObjectPoints = new MCvPoint3D32f[FrameCount][];

            // showing the image viewer
            //imageViewer.Show();

            // clearing flag
            CalibrationDone = false;

            for (i=0; i<FrameCount; i++) {
                ObjectPoints[i] = new MCvPoint3D32f[ChessHorizCount * ChessVertCount];
                for (j=0; j<ChessVertCount * ChessHorizCount; j++) {
                    ObjectPoints[i][j].x = (float)(RectWidth * ( j % ChessHorizCount ));
                    ObjectPoints[i][j].y = (float)(RectHeight * ( j / ChessHorizCount));
                    ObjectPoints[i][j].z = 0;
                }
            }

            // starting the camera capture
            Cam.StartCapture();

            state = ST_CALIBRATING;

            CalibrationThread.Start();
        }
Example #32
0
        void RunSingleCamera(ManagedPGRGuid guid)
        {
            const int k_numImages = 10;

            ManagedGigECamera cam = new ManagedGigECamera();

            // Connect to a camera
            cam.Connect(guid);

            // Get the camera information
            CameraInfo camInfo = cam.GetCameraInfo();
            PrintCameraInfo(camInfo);

            uint numStreamChannels = cam.GetNumStreamChannels();
            for (uint i=0; i < numStreamChannels; i++)
            {
                PrintStreamChannelInfo(cam.GetGigEStreamChannelInfo(i));
            }

            GigEImageSettingsInfo imageSettingsInfo = cam.GetGigEImageSettingsInfo();

            GigEImageSettings imageSettings = new GigEImageSettings();
            imageSettings.offsetX = 0;
            imageSettings.offsetY = 0;
            imageSettings.height = imageSettingsInfo.maxHeight;
            imageSettings.width = imageSettingsInfo.maxWidth;
            imageSettings.pixelFormat = PixelFormat.PixelFormatMono8;

            cam.SetGigEImageSettings(imageSettings);

            // Get embedded image info from camera
            EmbeddedImageInfo embeddedInfo = cam.GetEmbeddedImageInfo();

            // Enable timestamp collection
            if (embeddedInfo.timestamp.available == true)
            {
                embeddedInfo.timestamp.onOff = true;
            }

            // Set embedded image info to camera
            cam.SetEmbeddedImageInfo(embeddedInfo);

            // Start capturing images
            cam.StartCapture();

            ManagedImage rawImage = new ManagedImage();
            for (int imageCnt = 0; imageCnt < k_numImages; imageCnt++)
            {
                // Retrieve an image
                cam.RetrieveBuffer(rawImage);

                // Get the timestamp
                TimeStamp timeStamp = rawImage.timeStamp;

                Console.WriteLine(
                   "Grabbed image {0} - {1} {2} {3}",
                   imageCnt,
                   timeStamp.cycleSeconds,
                   timeStamp.cycleCount,
                   timeStamp.cycleOffset);

                // Create a converted image
                ManagedImage convertedImage = new ManagedImage();

                // Convert the raw image
                rawImage.Convert(PixelFormat.PixelFormatBgr, convertedImage);

                // Create a unique filename
                string filename = String.Format(
                   "GigEGrabEx_CSharp-{0}-{1}.bmp",
                   camInfo.serialNumber,
                   imageCnt);

                // Get the Bitmap object. Bitmaps are only valid if the
                // pixel format of the ManagedImage is RGB or RGBU.
                System.Drawing.Bitmap bitmap = convertedImage.bitmap;

                // Save the image
                bitmap.Save(filename);
            }

            // Stop capturing images
            cam.StopCapture();

            // Disconnect the camera
            cam.Disconnect();
        }
        // start capturing
        public void startCapture(ManagedPGRGuid camGuid, int vidMode,System.Windows.Forms.PictureBox displayPicture, 
                                 String fileName,Boolean record2file)
        {
            int i;

            Flag_GravityFound_Y = false; // garvity is not known

            // CLEARING THE FRAME QUEUE NO MATTER WHAT...
            FrameQueue.clear();

            RecordToFile = record2file;

            // creating the GPS data list
            GpsCaptureData = new List<GPSDataInstance>();
            // creating the IMU data List
            IMUCapturedata = new List<IMUDataInstance>();

            // resetting frame index
            FrameIndex = 0;

            // 1. connect to the camera
            Cam.Connect(camGuid);

            int fps_i = 0;
            if (vidMode == 0)
            {
                Cam.SetVideoModeAndFrameRate(VideoMode.VideoMode1600x1200Yuv422, FrameRate.FrameRate30);
                fps_i = 30;
            }
            else if (vidMode == 1) {
                Cam.SetVideoModeAndFrameRate(VideoMode.VideoMode1600x1200Rgb, FrameRate.FrameRate15);
                fps_i = 15;
                }
            else if (vidMode == 2)
            {
                Format7ImageSettings fset = new Format7ImageSettings();
                fset.height = 540;
                fset.width = 960;
                fset.offsetX = 40;
                fset.offsetY = 118;
                fset.mode = Mode.Mode4;

                fset.pixelFormat = PixelFormat.PixelFormatRgb8;

                Cam.SetFormat7Configuration(fset, 40.0f); // this equivalent to 24 fps

                fps_i = 24;
            }

            if (RecordToFile)
            {
                // 3. Creating the avi recorder object
                AviRecorder = new ManagedAVIRecorder();

                MJPGOption option = new MJPGOption();

                float fps = (float)fps_i;

                option.frameRate = fps;
                option.quality = 100;  // 100 for superb quality
                AviRecorder.AVIOpen(fileName, option);
            }

            // 4. setting the frame buffering option
            // leave it for now...

            // 5. start the capturing
            Cam.StartCapture();

            // MUST discard the first few frames!
            ManagedImage rawImage = new ManagedImage();
            for (i = 0; i < 10;  i++)
            {
                Cam.RetrieveBuffer(rawImage);
            }

            // 6. set the display bitmap
            DisplayPicture = displayPicture;

            // 7. starting sampling, recording and dumping threads

            // IMU sampling thread
            IMUSamplingTimer = new PrecisionTimer(.0075, this.IMUSamplingEvent); // sampling frequency at 150 Hz

            RecordingThreadActive = true;
            OutOfRecordingThread = true;

            IMUSamplingTimer.start();
            RecordingThread = new Thread(this.mainLoop);
            //RecordingThread.Priority = ThreadPriority.Highest;
            RecordingThread.Start();

            // creating the thread for the dumping
            DumpingThread = new System.Threading.Thread(this.dumpingLoop);

            while (OutOfRecordingThread); // must wait until the recording thread enters the loop, otherwise the dumping will never start!

            DumpingThread.Start();
        }
Example #34
0
        void RunSingleCamera(ManagedPGRGuid guid)
        {
            const int k_numImages = 10;

            ManagedCamera cam = new ManagedCamera();

            // Connect to a camera
            cam.Connect(guid);

            // Get the camera information
            CameraInfo camInfo = cam.GetCameraInfo();

            PrintCameraInfo(camInfo);

            // Get embedded image info from camera
            EmbeddedImageInfo embeddedInfo = cam.GetEmbeddedImageInfo();

            // Enable timestamp collection
            if (embeddedInfo.timestamp.available == true)
            {
                embeddedInfo.timestamp.onOff = true;
            }

            // Set embedded image info to camera
            cam.SetEmbeddedImageInfo(embeddedInfo);

            // Start capturing images
            cam.StartCapture(OnImageGrabbed);

            CameraProperty frameRateProp = cam.GetProperty(PropertyType.FrameRate);

            while (imageCnt < 10)
            {
                int millisecondsToSleep = (int)(1000 / frameRateProp.absValue);
                Thread.Sleep(millisecondsToSleep);
            }

            // Stop capturing images
            cam.StopCapture();

            // Disconnect the camera
            cam.Disconnect();
        }