Example #1
0
        private CSImgT LoadImage()
        {
            // This is just a demo
            MessageBox.Show("这里仅以代码形式演示如何加载 ICON(dat|xml) 类型的图像数据。");
            CSImgT img = new CSImgT();

            string         strConfigPath = string.Empty;
            OpenFileDialog ofd           = new OpenFileDialog();

            ofd.Title            = "Please select the path / 请选择加载路径";
            ofd.InitialDirectory = Application.StartupPath;
            ofd.Filter           = "xml|*.xml";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                strConfigPath = ofd.FileName;
            }
            else
            {
                return(img);
            }

            if (false == img.loadFromIconFile(strConfigPath))
            {
                MessageBox.Show("加载失败!! \n\n\nLoad Image failed!!");
            }

            return(img);
        }
Example #2
0
        static void test_CS_CPP_Graber_thread_process_img(bool isPrint, CSImgT imgT)
        {
            for (DataNames i = 0; i < DataNames.SCA2_CAL; ++i)
            {
                unit_test_print(isPrint, imgT.DN2Str(i));
            }
            // --- test CSR3 ImgT data array
            byte[] senData = imgT.getDataByte(DataNames.SEN);

            // --- test CSImgT data info getting
            int cols = imgT.get_cols(DataNames.SEN);
            int rows = imgT.get_rows(DataNames.SEN);

            int    S_cols          = imgT.getS_cols();
            int    S_rows          = imgT.getS_rows();
            int    S_OffsetX       = imgT.getS_OffsetX();
            int    S_OffsetY       = imgT.getS_OffsetY();
            int    R_cols          = imgT.getR_cols();
            int    R_rows          = imgT.getR_rows();
            int    R_AoiOffsetX    = imgT.getR_AoiOffsetX();
            int    R_AoiOffsetY    = imgT.getR_AoiOffsetY();
            int    R_AoiHeight     = imgT.getR_AoiHeight();
            int    R_AoiWidth      = imgT.getR_AoiWidth();
            bool   R_RangeAxis     = imgT.getR_RangeAxis();
            int    C_cols          = imgT.getC_cols();
            int    C_rows          = imgT.getC_rows();
            double C_offsetX       = imgT.getC_offsetX();
            double C_offsetY       = imgT.getC_offsetY();
            double C_scaleX        = imgT.getC_scaleX();
            double C_scaleY        = imgT.getC_scaleY();
            double C_lower_bound_x = imgT.getC_lower_bound_x();
            double C_upper_bound_x = imgT.getC_upper_bound_x();
            double C_lower_bound_r = imgT.getC_lower_bound_r();
            double C_upper_bound_r = imgT.getC_upper_bound_r();

            /// test CS ImgT data info getting
            int  id    = imgT.get_ID();
            bool isE   = imgT.isEmpty();
            bool hasS  = imgT.has(DataNames.SEN);
            bool hasR  = imgT.has(DataNames.RAN);
            bool hasCI = imgT.has_ChunkInfo();

            bool saveSenOk = imgT.SaveToIconFile("D:\\sen", DataNames.SEN);
            bool saveRanOk = imgT.SaveToIconFile("D:\\ran", DataNames.RAN);
            bool saveRacOk = imgT.SaveToIconFile("D:\\rac", DataNames.RAN_CAL);

            unit_test_print(true, "Get Image, id = {0}", id);
        }
Example #3
0
        private void btnLoadBuffer_Click(object sender, EventArgs e)
        {
            CSImgT img = LoadImage();

            if (!img.isEmpty())
            {
                var dnList = img.getAvalibleDataNames();
                foreach (var dn in dnList)
                {
                    Form   f   = new Form();
                    Bitmap src = BuiltGrayBitmap(img.getDataByte(dn), img.get_cols(dn), img.get_rows(dn));

                    if (dn == DataNames.SEN)
                    {
                        f.Text = "激光线图像 | Sensor Image";
                        src    = BuiltGrayBitmap(img.getDataByte(dn), img.get_cols(dn), img.get_rows(dn));
                    }
                    else if (dn == DataNames.RAN)
                    {
                        f.Text = "高度图像 | Range Image";
                        src    = BuiltGrayBitmap(img.getDataWord(dn), img.get_cols(dn), img.get_rows(dn));
                    }
                    else if (dn == DataNames.RAN_CAL)
                    {
                        f.Text = "标定后的高度图像 | Calibrated Range Image";
                        src    = BuiltGrayBitmap(img.getDataFloat(dn), img.get_cols(dn), img.get_rows(dn));
                    }
                    else if (dn == DataNames.REF)
                    {
                        f.Text = "激光强度图像 | Reflectance Image";
                        src    = BuiltGrayBitmap(img.getDataByte(dn), img.get_cols(dn), img.get_rows(dn));
                    }
                    else if (dn == DataNames.REF_CAL)
                    {
                        f.Text = "标定后的激光强度图像 | Calibrated Reflectance Image";
                        src    = BuiltGrayBitmap(img.getDataByte(dn), img.get_cols(dn), img.get_rows(dn));
                    }

                    IntPtr pp      = new IntPtr();
                    Size   imgSize = new Size(src.Width / 3, src.Height / 3);
                    f.BackgroundImage = src.GetThumbnailImage(imgSize.Width, imgSize.Height, null, pp);
                    f.Size            = new Size(imgSize.Width, imgSize.Height + 30);
                    f.MaximumSize     = new Size(imgSize.Width, imgSize.Height + 30);
                    f.Show();
                }
            }
        }
Example #4
0
        private void GrabImageTimer(object sender, System.Timers.ElapsedEventArgs e)
        {
            // 响应停止请求
            if (m_reqStop == 0)
            {
                m_reqStop       = 1;
                myTimer.Enabled = false;
            }

            if (R3(m_ip).getStatus() == CAM_STATUS.CAM_IS_STARTED && R3(m_ip).isGrabbed())
            {
                CSImgT imgTable = new CSImgT();
                if (R3(m_ip).getImageData(imgTable) == CAM_STATUS.All_OK)
                {
                    Bitmap imgGray;

                    // 读取图片 convert image to show
                    var mode = GetGrabMode();
                    if (!imgTable.has(mode))
                    {
                        return;
                    }

                    switch (mode)
                    {
                    case DataNames.SEN:
                        imgGray = BuiltGrayBitmap(
                            imgTable.getDataByte(mode),
                            imgTable.getS_cols(),
                            imgTable.getS_rows()
                            );
                        break;

                    case DataNames.REF:
                    case DataNames.SCA:
                    case DataNames.REF_CAL:
                    case DataNames.SCA_CAL:
                    case DataNames.REF2:
                    case DataNames.SCA2:
                    case DataNames.REF2_CAL:
                    case DataNames.SCA2_CAL:
                        imgGray = BuiltGrayBitmap(
                            imgTable.getDataByte(mode),
                            imgTable.getR_cols(),
                            imgTable.getR_rows()
                            );
                        break;

                    case DataNames.RAN:
                    case DataNames.RAN2:
                        imgGray = BuiltGrayBitmap(
                            imgTable.getDataWord(mode),
                            imgTable.getR_cols(),
                            imgTable.getR_rows()
                            );
                        break;

                    case DataNames.RAN_CAL:
                    case DataNames.RAN2_CAL:
                        imgGray = BuiltGrayBitmap(
                            imgTable.getDataFloat(mode),
                            imgTable.getR_cols(),
                            imgTable.getR_rows()
                            );
                        break;

                    default:
                        imgTable.Dispose();
                        return;
                    }

                    // 显示图片 Show Image
                    // Code below will cost a lot of memory.
                    // This is a side effect of C# gc.
#if true
                    System.Drawing.Image imgShow = System.Drawing.Image.FromHbitmap(imgGray.GetHbitmap());
                    pictureBox1.BackgroundImage = imgShow.GetThumbnailImage(pictureBox1.Size.Width, pictureBox1.Size.Height, null, IntPtr.Zero);
                    imgShow.Dispose();
                    imgGray.Dispose();
                    imgShow = null;
                    imgGray = null;
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
#endif

                    lock (m_imgLocker)
                    {
                        m_lastImg._deepCopy(imgTable);
                    }

                    // 响应停止请求
                    if (m_reqStop == 0)
                    {
                        m_reqStop       = 1;
                        myTimer.Enabled = false;
                    }

                    // show ID
                    wFlog(imgTable.get_ID().ToString());
                }
                imgTable.Dispose();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Example #5
0
        static bool test_CS_CPP_ShowImage(bool isPrintToScream = true, int nImg = 5)
        {
            bool enable_CPP_Grab_thread = true;

            // --- test CSR3S. (Please note: "CS" = C_Sharp, "R3S" = Ranger3_Shared_runtime_environment, So "CSR3S" = class of C_Sharp_Ranger3_Shared_runtime_environment.)
            String    logPath    = "D:\\log.txt";
            String    ctiPath    = "";
            bool      isPrintLog = isPrintToScream;
            bool      isWriteLog = true;
            GenICam3D r3s        = new GenICam3D(logPath, ctiPath, isPrintLog, isWriteLog);

            String[] IPs     = r3s.getConDevListIP();
            String[] Nas     = r3s.getConDevList();
            var      scanRes = r3s.scanDevice();

            // --- test CSR3. (Please note: "CS" = C_Sharp, "R3" = Ranger3, So "CSR3" = class of C_Sharp_Ranger3.)
            String  mac = "0006770c69e1";
            Ranger3 r3  = new Ranger3(mac, false);

            /// CSR3 r3 = new CSR3(IPs[0], true);

            if (r3.isReady() != CAM_STATUS.All_OK)
            {
                unit_test_print(isPrintToScream, "Camera is not ready!");
                return(false);
            }

            /// If program might last time, camera status will be incorrect. re-conencting to make it ready!
            /// Debug tips.
            r3.connectCamera(false);
            r3.disconnectCamera();

            var camStatus = r3.connectCamera(enable_CPP_Grab_thread);

            if (camStatus != CAM_STATUS.All_OK)
            {
                unit_test_print(isPrintToScream, "Camera connecting failed!");
                return(false);
            }

            /// test CS getting paramters info
            if (r3.updateParamtersInfo() == false)
            {
                return(false);
            }

            String[] CategoryList = r3.paramCategoryList();
            String[] FullNameList = r3.paramFullNameList();
            int      fnId         = 0;

            unit_test_print(isPrintToScream, "");
            unit_test_print(isPrintToScream, "--------------");
            foreach (String cate in CategoryList)
            {
                unit_test_print(isPrintToScream, "|");
                unit_test_print(isPrintToScream, "----  Cate: {0}", cate);
                String[] categries = r3.paramFullNameOfCategory(cate);
                foreach (String fn in categries)
                {
                    unit_test_print(isPrintToScream, "    |"); unit_test_print(isPrintToScream, "    --- FullName: {0}", fn);
                    unit_test_print(isPrintToScream, "        |"); unit_test_print(isPrintToScream, "        --- CurrentValue: {0}", r3.paramCurrentValue(fn));
                    unit_test_print(isPrintToScream, "        |"); unit_test_print(isPrintToScream, "        --- Optional values:");
                    String[] opt = r3.paramOptionalValues(fn, ref fnId);
                    foreach (String sub in opt)
                    {
                        unit_test_print(isPrintToScream, "               |");
                        unit_test_print(isPrintToScream, "               ---- {0}", sub);
                    }
                }
            }


            // --- test CSR3 setting paramters info
            ///r3.setParameterValue("DeviceScanType", "Linescan3D");    /// 3D Range image
            r3.setParameterValue("DeviceScanType", "Areascan");         /// 2D Sensor image

            camStatus = r3.startCamera();
            if (camStatus != CAM_STATUS.All_OK)
            {
                unit_test_print(isPrintToScream, "Camera starting failed!");
                return(false);
            }

            // --- test CSR3 acquisition
            Thread.Sleep(1000);

            int i = 0;

            while (true)
            {
                if (r3.isGrabbed())
                {
                    // --- test CS ImgT
                    CSImgT imgT = new CSImgT();
                    camStatus = r3.getImageData(imgT);
                    if (camStatus != CAM_STATUS.All_OK)
                    {
                        unit_test_print(isPrintToScream, "Camera get data failed!");
                        return(false);
                    }

                    //读取图片
                    byte[] senImage = imgT.getDataByte(DataNames.SEN);
                    var    img2     = BuiltGrayBitmap(senImage, 2560, 832);

                    //显示图片
                    System.Drawing.Image imgXXXX = System.Drawing.Image.FromHbitmap(img2.GetHbitmap());

                    ++i;
                }
                else
                {
                    Thread.Sleep(50);
                }

                if (i == nImg)
                {
                    break;
                }
            }

            camStatus = r3.stopCamera();
            if (camStatus != CAM_STATUS.All_OK)
            {
                unit_test_print(isPrintToScream, "Camera stopping failed!");
                return(false);
            }

            camStatus = r3.disconnectCamera();
            if (camStatus != CAM_STATUS.All_OK)
            {
                unit_test_print(isPrintToScream, "Camera disconnecting failed!");
                return(false);
            }

            // --- delete variable.
            r3s.Dispose();


            return(true);
        }
Example #6
0
        /////////////////////////////////////////////////////////////////////////////////////


        static bool test_CS_basic_functions(bool isPrintToScream = true)
        {
            bool enable_CPP_Grab_thread = false;

            // --- test CSR3S. (Please note: "CS" = C_Sharp, "R3S" = Ranger3_Shared_runtime_environment, So "CSR3S" = class of C_Sharp_Ranger3_Shared_runtime_environment.)
            String    logPath    = "D:\\log.txt";
            String    ctiPath    = "";
            bool      isPrintLog = isPrintToScream;
            bool      isWriteLog = true;
            GenICam3D r3s        = new GenICam3D(logPath, ctiPath, isPrintLog, isWriteLog);

            String[] IPs     = r3s.getConDevListIP();
            String[] Nas     = r3s.getConDevList();
            var      scanRes = r3s.scanDevice();

            // --- test CSR3. (Please note: "CS" = C_Sharp, "R3" = Ranger3, So "CSR3" = class of C_Sharp_Ranger3.)
            String  mac = "0006770c69e1";
            Ranger3 r3  = new Ranger3(mac, false);

            /// CSR3 r3 = new CSR3(IPs[0], true);

            if (r3.isReady() != CAM_STATUS.All_OK)
            {
                if (isPrintToScream)
                {
                    unit_test_print(isPrintToScream, "Camera is not ready!");
                }
                return(false);
            }

            var camStatus = r3.connectCamera(enable_CPP_Grab_thread);

            if (camStatus != CAM_STATUS.All_OK)
            {
                if (isPrintToScream)
                {
                    unit_test_print(isPrintToScream, "Camera connecting failed!");
                }
                return(false);
            }

            /// test CS getting paramters info
            if (r3.updateParamtersInfo() == false)
            {
                return(false);
            }

            String[] CategoryList = r3.paramCategoryList();
            String[] FullNameList = r3.paramFullNameList();
            int      fnId         = 0;

            unit_test_print(isPrintToScream, "");
            unit_test_print(isPrintToScream, "--------------");
            foreach (String cate in CategoryList)
            {
                unit_test_print(isPrintToScream, "|");
                unit_test_print(isPrintToScream, "----  Cate: {0}", cate);
                String[] categries = r3.paramFullNameOfCategory(cate);
                foreach (String fn in categries)
                {
                    unit_test_print(isPrintToScream, "    |");  unit_test_print(isPrintToScream, "    --- FullName: {0}", fn);
                    unit_test_print(isPrintToScream, "        |");  unit_test_print(isPrintToScream, "        --- CurrentValue: {0}", r3.paramCurrentValue(fn));
                    unit_test_print(isPrintToScream, "        |");  unit_test_print(isPrintToScream, "        --- Optional values:");
                    String[] opt = r3.paramOptionalValues(fn, ref fnId);
                    foreach (String sub in opt)
                    {
                        unit_test_print(isPrintToScream, "               |");
                        unit_test_print(isPrintToScream, "               ---- {0}", sub);
                    }
                }
            }


            // --- test CSR3 setting paramters info
            ///r3.setParameterValue("DeviceScanType", "Linescan3D");    /// 3D Range image
            r3.setParameterValue("DeviceScanType", "Areascan");         /// 2D Sensor image



            camStatus = r3.startCamera();
            if (camStatus != CAM_STATUS.All_OK)
            {
                unit_test_print(isPrintToScream, "Camera starting failed!");
                return(false);
            }

            // --- test CSR3 acquisition
            Thread.Sleep(1000);

            // --- test CS ImgT
            CSImgT imgT = new CSImgT();

            camStatus = r3.getImageData(imgT);

            for (DataNames i = 0; i < DataNames.SCA2_CAL; ++i)
            {
                unit_test_print(isPrintToScream, imgT.DN2Str(i));
            }
            // --- test CSR3 ImgT data array
            byte[] senData = imgT.getDataByte(DataNames.SEN);

            // --- test CSImgT data info getting
            int    S_cols          = imgT.getS_cols();
            int    S_rows          = imgT.getS_rows();
            int    S_OffsetX       = imgT.getS_OffsetX();
            int    S_OffsetY       = imgT.getS_OffsetY();
            int    R_cols          = imgT.getR_cols();
            int    R_rows          = imgT.getR_rows();
            int    R_AoiOffsetX    = imgT.getR_AoiOffsetX();
            int    R_AoiOffsetY    = imgT.getR_AoiOffsetY();
            int    R_AoiHeight     = imgT.getR_AoiHeight();
            int    R_AoiWidth      = imgT.getR_AoiWidth();
            bool   R_RangeAxis     = imgT.getR_RangeAxis();
            int    C_cols          = imgT.getC_cols();
            int    C_rows          = imgT.getC_rows();
            double C_offsetX       = imgT.getC_offsetX();
            double C_offsetY       = imgT.getC_offsetY();
            double C_scaleX        = imgT.getC_scaleX();
            double C_scaleY        = imgT.getC_scaleY();
            double C_lower_bound_x = imgT.getC_lower_bound_x();
            double C_upper_bound_x = imgT.getC_upper_bound_x();
            double C_lower_bound_r = imgT.getC_lower_bound_r();
            double C_upper_bound_r = imgT.getC_upper_bound_r();

            /// test CS ImgT data info getting
            int  id    = imgT.get_ID();
            bool isE   = imgT.isEmpty();
            bool hasS  = imgT.has(DataNames.SEN);
            bool hasR  = imgT.has(DataNames.RAN);
            bool hasCI = imgT.has_ChunkInfo();

            bool saveSenOk = imgT.SaveToIconFile("D:\\sen", DataNames.SEN);
            bool saveRanOk = imgT.SaveToIconFile("D:\\ran", DataNames.RAN);
            bool saveRacOk = imgT.SaveToIconFile("D:\\rac", DataNames.RAN_CAL);

            camStatus = r3.stopCamera();
            if (camStatus != CAM_STATUS.All_OK)
            {
                unit_test_print(isPrintToScream, "Camera stopping failed!");
                return(false);
            }

            camStatus = r3.disconnectCamera();
            if (camStatus != CAM_STATUS.All_OK)
            {
                unit_test_print(isPrintToScream, "Camera disconnecting failed!");
                return(false);
            }
            return(true);
        }
Example #7
0
        static bool test_CS_CPP_Graber_thread(bool isPrintToScream = true, int nImg = 5)
        {
            bool enable_CPP_Grab_thread = true;

            // --- test CSR3S. (Please note: "CS" = C_Sharp, "R3S" = Ranger3_Shared_runtime_environment, So "CSR3S" = class of C_Sharp_Ranger3_Shared_runtime_environment.)
            String    logPath    = "D:\\log.txt";
            String    ctiPath    = "";
            bool      isPrintLog = isPrintToScream;
            bool      isWriteLog = true;
            GenICam3D r3s        = new GenICam3D(logPath, ctiPath, isPrintLog, isWriteLog);

            String[] IPs     = r3s.getConDevListIP();
            String[] Nas     = r3s.getConDevList();
            var      scanRes = r3s.scanDevice();

            // --- test CSR3. (Please note: "CS" = C_Sharp, "R3" = Ranger3, So "CSR3" = class of C_Sharp_Ranger3.)
            ///String mac = "0006770c69e1";
            ///Ranger3 r3 = new Ranger3(mac, false);
            Ranger3 r3 = new Ranger3(IPs[0], true);

            if (r3.isReady() != CAM_STATUS.All_OK)
            {
                unit_test_print(isPrintToScream, "Camera is not ready!");
                return(false);
            }

            /// If program might last time, camera status will be incorrect. re-conencting to make it ready!
            ///Debug tips.
            r3.connectCamera(false);
            r3.disconnectCamera();

            var camStatus = r3.connectCamera(enable_CPP_Grab_thread);

            if (camStatus != CAM_STATUS.All_OK)
            {
                unit_test_print(isPrintToScream, "Camera connecting failed!");
                return(false);
            }

            /// test CS getting paramters info
            if (r3.updateParamtersInfo() == false)
            {
                return(false);
            }

            String[] CategoryList = r3.paramCategoryList();
            String[] FullNameList = r3.paramFullNameList();
            int      fnId         = 0;

            unit_test_print(isPrintToScream, "");
            unit_test_print(isPrintToScream, "--------------");
            foreach (String cate in CategoryList)
            {
                unit_test_print(isPrintToScream, "|");
                unit_test_print(isPrintToScream, "----  Cate: {0}", cate);
                String[] categries = r3.paramFullNameOfCategory(cate);
                foreach (String fn in categries)
                {
                    unit_test_print(isPrintToScream, "    |");  unit_test_print(isPrintToScream, "    --- FullName: {0}", fn);
                    unit_test_print(isPrintToScream, "        |");  unit_test_print(isPrintToScream, "        --- CurrentValue: {0}", r3.paramCurrentValue(fn));
                    unit_test_print(isPrintToScream, "        |");  unit_test_print(isPrintToScream, "        --- Optional values:");
                    String[] opt = r3.paramOptionalValues(fn, ref fnId);
                    foreach (String sub in opt)
                    {
                        unit_test_print(isPrintToScream, "               |");
                        unit_test_print(isPrintToScream, "               ---- {0}", sub);
                    }
                }
            }


            // --- test CSR3 setting paramters info
            ///r3.setParameterValue("DeviceScanType", "Linescan3D");    /// 3D Range image
            r3.setParameterValue("DeviceScanType", "Areascan");         /// 2D Sensor image

            // --- Memory using check: X Mb before starting
            camStatus = r3.startCamera();
            if (camStatus != CAM_STATUS.All_OK)
            {
                unit_test_print(isPrintToScream, "Camera starting failed!");
                return(false);
            }

            // --- test CSR3 acquisition
            Thread.Sleep(1000);

            int i = 0;

#if true
            while (true)
            {
                if (r3.isGrabbed())
                {
                    // --- test CS ImgT
                    CSImgT imgT = new CSImgT();
                    camStatus = r3.getImageData(imgT);
                    if (camStatus != CAM_STATUS.All_OK)
                    {
                        unit_test_print(isPrintToScream, "Camera get data failed!");
                        return(false);
                    }

                    test_CS_CPP_Graber_thread_process_img(isPrintToScream, imgT);

                    // --- Important to list these code here and collect memory allocating to imgT.
                    imgT.Dispose();
                    GC.Collect();
                    GC.WaitForFullGCComplete();
                    ++i;
                }
                else
                {
                    Thread.Sleep(50);
                }

                if (i == nImg)
                {
                    break;
                }
            }
#else
            while (true)
            {
                Thread.Sleep(50);
                ++i;
                Console.WriteLine("i = {0}", i);
                if (i == nImg)
                {
                    break;
                }
            }
#endif

            // --- Memory using check: around X Mb after stopping.
            camStatus = r3.stopCamera();
            if (camStatus != CAM_STATUS.All_OK)
            {
                unit_test_print(isPrintToScream, "Camera stopping failed!");
                return(false);
            }

            camStatus = r3.disconnectCamera();
            if (camStatus != CAM_STATUS.All_OK)
            {
                unit_test_print(isPrintToScream, "Camera disconnecting failed!");
                return(false);
            }

            // --- delete variable.
            r3s.Dispose();


            return(true);
        }