Пример #1
0
        /// <summary>
        /// LED 燈色檢查
        /// </summary>
        /// <param name="SendMessage"></param>
        /// <param name="MainResultArray"></param>
        /// <param name="SendString"></param>
        public static void LED_Check(ref Dictionary <string, object> SendMessage, ref Dictionary <string, object> MainResultArray, ref string SendString)
        {
            string   str     = Application.StartupPath + @"\IDSData\LedData";
            DateTime timeNow = DateTime.Now;

            if (!Directory.Exists(str))
            {
                Directory.CreateDirectory(str);
            }

            FuncClass.IdsStatus();
            SendMessage.Add("SavePath", dll_PublicFuntion.Folder.ToolPath + "IDSNowImage.png");
            try { SendString = dll_PublicFuntion.Other.DictionaryToXml(SendMessage); } catch { }
            FuncClass.IDS_Check(SendMessage, ref MainResultArray, false);

            if (!File.Exists((string)SendMessage["SavePath"]))
            {
                MainResultArray[Parameters.Status] = "Fail";
                MainResultArray[Parameters.Remark] = "IDS connect error.";
            }

            if ((string)MainResultArray[Parameters.Status] == "Pass")
            {
                Dictionary <string, object> FDic = new Dictionary <string, object>();
                try { FDic = dll_PublicFuntion.Other.XmlToDictionary(SendMessage[Parameters.Parameter].ToString()); } catch { }

                try
                {
                    // 創一個取樣大小的bitmap
                    Bitmap newRec     = new Bitmap((int.Parse((string)FDic["ImgWidth"])), int.Parse((string)FDic["ImgHeight"]));
                    Image  FullScreen = dll_PublicFuntion.Other.LoadImage((string)SendMessage["SavePath"]);

                    Graphics grPhoto = Graphics.FromImage(newRec);

                    Rectangle resultRec = new Rectangle();
                    resultRec.X      = Convert.ToInt32((string)FDic["startX"]);
                    resultRec.Y      = Convert.ToInt32((string)FDic["startY"]);
                    resultRec.Width  = Convert.ToInt32((string)FDic["ImgWidth"]);
                    resultRec.Height = Convert.ToInt32((string)FDic["ImgHeight"]);
                    grPhoto.DrawImage(FullScreen, 0, 0, resultRec, GraphicsUnit.Pixel);

                    grPhoto = Graphics.FromImage(FullScreen);
                    grPhoto.DrawRectangle(new Pen(System.Drawing.Color.Red, 3), resultRec);
                    newRec.Save(string.Format(FuncClass.Check_path($@"IDSData\LedData\{(string)FDic["DataFile"]}") + "{0}.png", $"{timeNow:HH-mm-ss}", System.Drawing.Imaging.ImageFormat.Png));
                    Thread.Sleep(1000);
                    MainResultArray["DataFile"] = (string)FDic["DataFile"];

                    if (newRec != null)
                    {
                        MainResultArray["IDSImagePortion"] = newRec;
                        string fileplace = str + $@"\{(string)FDic["DataFile"]}\{timeNow:HH-mm-ss}.png";

                        Image             GetBitmap  = Image.FromFile(fileplace);
                        Image <Bgr, byte> inputImage = new Image <Bgr, byte>(fileplace);

                        string returnColor = FuncClass.getcolor(inputImage);
                        MainResultArray[Parameters.Remark] = returnColor;
                    }

                    // Delete NowImage in case of wrong time
                    FuncClass.FileDelete(dll_PublicFuntion.Folder.ToolPath + "IDSNowImage.png");
                }
                catch (Exception)
                {
                    // Delete NowImage in case of wrong time
                    FuncClass.FileDelete(dll_PublicFuntion.Folder.ToolPath + "IDSNowImage.png");

                    MainResultArray[Parameters.Status] = "Fail";
                    MainResultArray[Parameters.Remark] = "Image catch fail.";
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 解析度
        /// </summary>
        /// <param name="SendMessage"></param>
        /// <param name="MainResultArray"></param>
        /// <param name="SendString"></param>
        public static void Resolution_Check(ref Dictionary <string, object> SendMessage, ref Dictionary <string, object> MainResultArray, ref string SendString)
        {
            // 檢查IDS是否啟動
            FuncClass.IdsStatus();

            SendMessage.Add("SavePath", dll_PublicFuntion.Folder.ToolPath + "IDSNowImage.png");
            try { SendString = dll_PublicFuntion.Other.DictionaryToXml(SendMessage); } catch { }
            FuncClass.IDS_Check(SendMessage, ref MainResultArray, false);
            Thread.Sleep(200);

            if (!File.Exists((string)SendMessage["SavePath"]))
            {
                MainResultArray[Parameters.Status] = "Fail";
                MainResultArray[Parameters.Remark] = "IDS connect error.";
            }
            if ((string)MainResultArray[Parameters.Status] == "Pass")
            {
                Dictionary <string, object> FDic = new Dictionary <string, object>();
                try { FDic = dll_PublicFuntion.Other.XmlToDictionary(SendMessage[Parameters.Parameter].ToString()); } catch { }

                try
                {
                    Bitmap   newRec  = new Bitmap((int.Parse((string)FDic["ImgWidth"])), int.Parse((string)FDic["ImgHeight"]));
                    Image    NowImg  = dll_PublicFuntion.Other.LoadImage((string)SendMessage["SavePath"]);
                    Graphics grPhoto = Graphics.FromImage(newRec);

                    grPhoto.SmoothingMode      = SmoothingMode.AntiAlias;
                    grPhoto.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                    grPhoto.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                    grPhoto.CompositingQuality = CompositingQuality.HighQuality;

                    Rectangle rectangleHAHA = new Rectangle();
                    rectangleHAHA.X      = Convert.ToInt32((string)FDic["startX"]);
                    rectangleHAHA.Y      = Convert.ToInt32((string)FDic["startY"]);
                    rectangleHAHA.Width  = Convert.ToInt32((string)FDic["ImgWidth"]);
                    rectangleHAHA.Height = Convert.ToInt32((string)FDic["ImgHeight"]);

                    grPhoto.DrawImage(NowImg, 0, 0, rectangleHAHA, GraphicsUnit.Pixel);

                    grPhoto = Graphics.FromImage(NowImg);
                    grPhoto.DrawRectangle(new Pen(System.Drawing.Color.Red, 3), rectangleHAHA);
                    string F1 = string.Format(FuncClass.Check_path($@"IDSData\{(string)FDic["DataFile"]}") + @"{0}.png", "FullScreen");
                    string F2 = string.Format(FuncClass.Check_path($@"IDSData\{(string)FDic["DataFile"]}") + @"{0}.png", "OcrRegion");

                    NowImg.Save(F1, System.Drawing.Imaging.ImageFormat.Png);
                    newRec.Save(F2, System.Drawing.Imaging.ImageFormat.Png);
                    Thread.Sleep(1000);
                    dll_GoogleOCR.GoogleOCR googleOCR = new dll_GoogleOCR.GoogleOCR();
                    MainResultArray["DataFile"] = (string)FDic["DataFile"];

                    if (NowImg != null)
                    {
                        MainResultArray["IDSImageFull"] = NowImg;
                    }
                    if (newRec != null)
                    {
                        MainResultArray["IDSImagePortion"] = newRec;
                    }

                    string OCRresult = googleOCR.UploadFileToTxt(Application.StartupPath + $@"\IDSData\{(string)FDic["DataFile"]}\" + "OcrRegion.png", null, true);
                    string OriOCR    = OCRresult.Replace("_", " ").Trim();

                    // Delete NowImage in case of wrong time
                    FuncClass.FileDelete(dll_PublicFuntion.Folder.ToolPath + "IDSNowImage.png");

                    // OSD display value
                    OCRresult = FuncClass.RexResolution(OCRresult.Replace("_", " ").Trim());

                    // Receive
                    string receMsg = "";
                    Dictionary <string, object> receivedData = new Dictionary <string, object>();

                    // Send to server
                    main.Resolution_ConncetNet(SendString, ref receMsg);
                    receivedData = dll_PublicFuntion.Other.XmlToDictionary(receMsg);

                    // Dut resolution
                    string OriDut        = (string)receivedData["Remark"];
                    string dutResolution = FuncClass.RexResolution(((string)receivedData["Remark"]).Trim());
                    if (OriDut != "")
                    {
                        if (!OCRresult.Equals(dutResolution))
                        {
                            MainResultArray[Parameters.Status] = "Fail";
                            MainResultArray[Parameters.Remark] = $"OSD : {OriOCR} ; Windows : {(string)receivedData["Remark"]}";
                        }
                    }
                    else
                    {
                        MainResultArray[Parameters.Status] = "Fail";
                        MainResultArray[Parameters.Remark] = "No monitor has been detective.";
                    }

                    MainResultArray[Parameters.Remark] = $"OSD : {OriOCR} ; Windows : {OriDut}";
                }
                catch (Exception)
                {
                    MainResultArray[Parameters.Status] = "Fail";
                    MainResultArray[Parameters.Remark] = "Data received error.";
                }
            }
        }