Exemplo n.º 1
0
        public static bool DoDepthFromFocus(IntPtr[] imgPtr, int imgCount, int width, int height, string imgSaveFolder, string imgSaveName)
        {
            bool ret = false;

            try
            {
                if (imgPtr == null || imgCount < 1)
                {
                    return(false);
                }

                HImage ho_Image = new HImage();
                ho_Image.GenImageInterleaved(imgPtr[0], "bgr", width, height, 0, "byte", width, height, 0, 0, -1, 0);
                for (int i = 1; i < imgCount; i++)
                {
                    HImage temp = new HImage();
                    temp.GenImageInterleaved(imgPtr[i], "bgr", width, height, 0, "byte", width, height, 0, 0, -1, 0);
                    ho_Image = ho_Image.ConcatObj(temp);
                }

                ret = DepthFromFocusProc(ho_Image, imgSaveFolder, imgSaveName);
                ho_Image.Dispose();
            }
            catch (HalconException hex)
            {
                Trace.WriteLine(hex.GetErrorMessage(), "HALCON error");
            }
            return(ret);
        }
Exemplo n.º 2
0
        public void GetImage2()
        {
            Image_1?.Dispose();
            Image_1 = Framegrabber1.GrabImage(); //拍照
            Image_2?.Dispose();
            Image_2 = Framegrabber2.GrabImage(); //拍照
            Image_3?.Dispose();
            Image_3 = Framegrabber3.GrabImage(); //拍照

            Image2?.Dispose();
            Image2 = Image_1.ConcatObj(Image_2).ConcatObj(Image_3).TileImages(3, "horizontal");
            GlobalVar.hWndCtrl.addIconicVar(Image2);
            GlobalVar.hWndCtrl.repaint();
        }
Exemplo n.º 3
0
        public void GetImage1()
        {
            //cam1ProcedureCall.Execute();
            Image_1?.Dispose();
            Image_1 = Framegrabber1.GrabImage(); //拍照
            Image_2?.Dispose();
            Image_2 = Framegrabber2.GrabImage(); //拍照
            Image_3?.Dispose();
            Image_3 = Framegrabber3.GrabImage(); //拍照

            Image1?.Dispose();
            Image1 = Image_1.ConcatObj(Image_2).ConcatObj(Image_3).TileImages(3, "horizontal");

            GlobalVar.hWndCtrl.addIconicVar(Image1);
            GlobalVar.hWndCtrl.repaint();
        }
Exemplo n.º 4
0
        public void ProcessImage()
        {
            Result_etch    = new bool[6];
            Result_blue    = new bool[6];
            Result_barcode = new bool[6];
            try
            {
                if (Image1 != null && Image2 != null)
                {
                    TiledImage?.Dispose();
                    TiledImage = Image1.ConcatObj(Image2).TileImages(1, "vertical");

                    GlobalVar.hWndCtrl.addIconicVar(TiledImage);
                    GlobalVar.hWndCtrl.repaint();
                    cam1ProcedureCall2.SetInputIconicParamObject("Image", TiledImage);//传入图像
                    cam1ProcedureCall2.Execute();
                    HRegion Rectangle10 = cam1ProcedureCall2.GetOutputIconicParamRegion("Rectangle10");
                    HRegion Rectangle11 = cam1ProcedureCall2.GetOutputIconicParamRegion("Rectangle11");
                    window1.SetColor("red");
                    window1.DispRegion(Rectangle10);
                    window1.SetColor("red");
                    window1.DispRegion(Rectangle11);
                    HTuple result_etch = cam1ProcedureCall2.GetOutputCtrlParamTuple("Result_etch");
                    HTuple result_blue = cam1ProcedureCall2.GetOutputCtrlParamTuple("Result_blue");
                    //HTuple result_barcode = cam1ProcedureCall2.GetOutputCtrlParamTuple("Result_barcode");
                    result_barcode = cam1ProcedureCall2.GetOutputCtrlParamTuple("Result_barcode");
                    GlobalVar.AddMessage("蚀刻:");
                    foreach (long item in result_etch.LArr)
                    {
                        if (item == 0)
                        {
                            GlobalVar.AddMessage(item.ToString() + "OK");
                        }
                        else
                        {
                            GlobalVar.AddMessage(item.ToString() + "NG");
                        }
                    }
                    GlobalVar.AddMessage("条码:");

                    try
                    {
                        int index = 0;
                        foreach (string item in result_barcode.SArr)
                        {
                            if (item != "error")
                            {
                                Result_barcode[index] = false;
                            }
                            else
                            {
                                Result_barcode[index] = true;
                            }
                            index++;
                        }
                    }

                    catch (Exception ex)
                    {
                        GlobalVar.AddMessage(ex.Message);
                    }


                    UploadBarcode();
                    try
                    {
                        foreach (string item in result_barcode.SArr)
                        {
                            System.Threading.Thread.Sleep(1000);
                            GlobalVar.AddMessage(item);
                            //SaveCSVfileBarcode(item);
                        }
                    }
                    catch { }
                    GlobalVar.AddMessage("蓝膜:");
                    foreach (long item in result_blue.LArr)
                    {
                        if (item == 1)
                        {
                            GlobalVar.AddMessage(item.ToString() + "NG");
                        }
                        else
                        {
                            GlobalVar.AddMessage(item.ToString() + "OK");
                        }
                    }
                    GlobalVar.AddMessage("图像处理完成");
                    for (int i = 0; i < result_etch.LArr.Length; i++)// i < Result_etch.Length && i < result_etch.LArr.Length && i < result_blue.LArr.Length; i++)
                    {
                        Result_etch[i] = result_etch[i];
                        //Result_blue[i] = result_blue[i];
                    }
                }
                else
                {
                    GlobalVar.AddMessage("无图像");
                }
            }
            catch (Exception ex)
            {
                GlobalVar.AddMessage(ex.Message);
            }
            //GC.Collect();
        }