Пример #1
0
 /// <summary>
 /// 图片均衡操作,将传入图片自动转换,imgWidth:设定图片宽度,imgHeight图片设定高度
 /// 图片(forexample:a.bmp)另存为同文件夹下面的_a.bmp
 /// </summary>
 /// <param name="ImagePath"></param>
 public void QualizerImage(string ImagePath, int imgWidth, int imgHeight)
 {
     try
     {
         if ((ImagePath.Length == 0) || (!File.Exists(ImagePath)))
         {
             return;
         }
         EImageBW8 EBW8ImageOrig = new EImageBW8(); // EImageBW8 instance
         EImageBW8 EBW8ImageDest = new EImageBW8(); // EImageBW8 instance
         EBW8ImageOrig.SetSize(imgWidth, imgHeight);
         // Make image black
         EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), EBW8ImageOrig);
         EBW8ImageOrig.Load(ImagePath);
         EBW8ImageDest.SetSize(imgWidth, imgHeight);
         // Make image black
         EasyImage.Oper(EArithmeticLogicOperation.Copy, new EBW8(0), EBW8ImageDest);
         EBW8ImageDest.SetSize(EBW8ImageOrig);
         EasyImage.Equalize(EBW8ImageOrig, EBW8ImageDest);
         EBW8ImageOrig.Dispose();
         //EBW8ImageDest.Save(ImagePath);
         EBW8ImageDest.Save(ImageSaveAsPath(ImagePath));
     }
     catch
     {
         throw;
     }
 }
        /// <summary>
        /// 从图片中获得DecodeString
        /// </summary>
        /// <param name="imagePath"></param>
        /// <returns></returns>
        public bool GetDecodeStrbyPath(string imagePath, int DeviceID)
        {
            try
            {
                if ((imagePath.Length == 0) || (!File.Exists(imagePath)))
                {
                    return(false);
                }
                EMatrixCodeReader EMatrixCodeReader1 = new EMatrixCodeReader(); // EMatrixCodeReader instance
                EMatrixCodeReader1.TimeOut = 3000000;

                EMatrixCode EMatrixCodeReader1Result = null; // EMatrixCode
                EImageBW8   EBW8Image1 = new EImageBW8();    // EImageBW8 instance
                EBW8Image1.Load(imagePath);
                EMatrixCodeReader1Result = EMatrixCodeReader1.Read(EBW8Image1);
                //GlobalVar.gl_str_decode[DeviceID] = EMatrixCodeReader1Result.DecodedString;
                return(true);
            }
            catch
            {
                return(false);

                throw;
            }
        }
Пример #3
0
        private void btnGray_Click(object sender, EventArgs e)
        {
            //使用者選取Bitmap檔案
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                EBW8Image1.Load(openFileDialog1.FileName); //直接載入

                //顯示影像於Picturebox
                ShowImage(EBW8Image1, pbImage);
            }
        }
Пример #4
0
 public void LoadPatterns(
     string pattern1_FilePath,
     string pattern2_FilePath,
     string pattern1_ImageFilePath,
     string pattern2_ImageFilePath)
 {
     EMatcher1_.Load(pattern1_FilePath);
     EMatcher2_.Load(pattern2_FilePath);
     if (Pattern1 == null)
     {
         Pattern1 = new EImageBW8();
     }
     if (Pattern2 == null)
     {
         Pattern2 = new EImageBW8();
     }
     Pattern1.Load(pattern1_ImageFilePath);
     Pattern2.Load(pattern2_ImageFilePath);
     isParametersSet = true;
     isPatternReady  = true;
 }
Пример #5
0
 /// <summary>
 /// 从图片中获得DecodeString
 /// </summary>
 /// <param name="imagePath"></param>
 /// <returns></returns>
 public string GetDecodeStrbyPath(string imagePath)
 {
     try
     {
         //return "1234567890"; //fortest
         if ((imagePath.Length == 0) || (!File.Exists(imagePath)))
         {
             return("");
         }
         EMatrixCodeReader EMatrixCodeReader1       = new EMatrixCodeReader(); // EMatrixCodeReader instance
         EMatrixCode       EMatrixCodeReader1Result = null;                    // EMatrixCode
         EImageBW8         EBW8Image1 = new EImageBW8();                       // EImageBW8 instance
         EBW8Image1.Load(imagePath);
         EMatrixCodeReader1.TimeOut = GlobalVar.gl_decode_timeout;
         //EMatrixCodeReader1Result = EMatrixCodeReader1.Read(EBW8Image1);
         ////Global.GlobalVar.gl_str_decode[DeviceID] = EMatrixCodeReader1Result.DecodedString;
         //return EMatrixCodeReader1Result.DecodedString;
         return(GetDecodeStrbyEImageBW8(EBW8Image1)); //ltt
     }
     catch
     {
         return("");
     }
 }
Пример #6
0
        public override bool Run(bool isTaskRun = false)
        {
            OutputImg = new EImageBW8();
            switch (config.SelectMode)
            {
            case 0:
                if (ParentTask.SourceImg != null)
                {
                    OutputImg.SetSize(ParentTask.SourceImg);
                    EasyImage.Copy(ParentTask.SourceImg, OutputImg);
                }
                else
                {
                    OutputImg = null;
                }

                if (isTaskRun)
                {
                    ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Imgs.Count));
                }
                break;

            case 1:
                if (!File.Exists(config.ImgPath))
                {
                    return(false);
                }

                OutputImg.Load(config.ImgPath);
                if (isTaskRun)
                {
                    ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Imgs.Count));
                }
                break;

            case 2:
                if (!Directory.Exists(config.FolderPath))
                {
                    return(false);
                }
                DirectoryInfo dir = new DirectoryInfo(config.FolderPath);
                FileInfo[]    fil = dir.GetFiles("*.bmp", SearchOption.TopDirectoryOnly);
                if (fil.Length == 0)
                {
                    return(false);
                }
                if (selectImg >= fil.Length)
                {
                    selectImg = 0;
                }
                OutputImg.Load(fil[selectImg++].FullName);
                if (isTaskRun)
                {
                    ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Imgs.Count));
                }
                break;

            case 3:
                if (config.SelectCCD > 0)
                {
                    int select = config.SelectCCD - 1;
                    if (ParentTask.Cameras[select].IsConnect)
                    {
                        ImgAtt att = ParentTask.Cameras[select].Grab();
                        OutputImg = new EImageBW8();
                        OutputImg.SetImagePtr(att.ImgWidth, att.ImgHeight, att.ImgPointer);

                        if (isTaskRun)
                        {
                            ParentTask.Imgs.Add(new ImgDictionary(Config, OutputImg, ParentTask.Imgs.Count));
                        }
                    }
                    else
                    {
                        OutputImg = null;
                        return(false);
                    }
                }
                else
                {
                    OutputImg = null;
                    return(false);
                }

                break;

            default:
                return(false);
            }
            return(true);
        }
Пример #7
0
        private static void ProcessingCallback(MC.SIGNALINFO signalInfo)
        {
            isImageReady = false;

            UInt32 currentChannel = (UInt32)signalInfo.Context;

            currentSurface = signalInfo.SignalInfo;

            // + GrablinkSnapshotTrigger Sample Program

            try
            {
                // Update the image with the acquired image buffer data
                Int32  width, height, bufferPitch;
                IntPtr bufferAddress;
                MC.GetParam(currentChannel, "ImageSizeX", out width);
                MC.GetParam(currentChannel, "ImageSizeY", out height);
                MC.GetParam(currentChannel, "BufferPitch", out bufferPitch);
                MC.GetParam(currentSurface, "SurfaceAddr", out bufferAddress);

                try
                {
                    imageMutex.WaitOne();

                    image  = new System.Drawing.Bitmap(width, height, bufferPitch, PixelFormat.Format8bppIndexed, bufferAddress);
                    imgpal = image.Palette;

                    // Build bitmap palette Y8
                    for (uint i = 0; i < 256; i++)
                    {
                        imgpal.Entries[i] = Color.FromArgb(
                            (byte)0xFF,
                            (byte)i,
                            (byte)i,
                            (byte)i);
                    }

                    image.Palette = imgpal;

                    string path_directory = @"D:\Waftech\BDMVision\Log\Temp\";
                    System.IO.Directory.CreateDirectory(path_directory);
                    string fullPath = path_directory + "test.jpg";

                    image.Save(fullPath);
                    eImage = new EImageBW8();
                    eImage.SetSize(image.Width, image.Height);
                    eImage.Load(fullPath);
                }
                finally
                {
                    imageMutex.ReleaseMutex();
                }

                isImageReady = true;

                // Retrieve the frame rate
                double frameRate_Hz;
                MC.GetParam(channel, "PerSecond_Fr", out frameRate_Hz);

                // Retrieve the channel state
                string channelState;
                MC.GetParam(channel, "ChannelState", out channelState);

                // Log frame rate and channel state
                VisionLogger.Log(WaftechLibraries.Log.LogType.Log, "E2VCameraHelper", string.Format("Frame Rate: {0:f2}, Channel State: {1}", frameRate_Hz, channelState));
            }
            catch (Euresys.MultiCamException ex)
            {
                VisionLogger.Log(WaftechLibraries.Log.LogType.Exception, "E2VCameraHelper", ex);
                VisionNotifier.AddNotification("MultiCam Exception: " + ex.Message);
                errorMessage = "MultiCam Exception: " + ex.Message;
            }
            catch (System.Exception ex)
            {
                VisionLogger.Log(WaftechLibraries.Log.LogType.Exception, "E2VCameraHelper", ex);
                VisionNotifier.AddNotification("System Exception: " + ex.Message);
                errorMessage = "System Exception: " + ex.Message;
            }
        }