Ejemplo n.º 1
0
        public void Test_GetLabelText()
        {
            var config = new LabelConfig();
            var msg    = config.GetLabelText("captionfail");

            Assert.AreEqual("失败", msg);
        }
Ejemplo n.º 2
0
        public static void SetConfigForLable(LabelConfig labelConfig, Label label)
        {
            label.ForeColor = GetColor(labelConfig.Color);


            if (labelConfig.Bold)
            {
                if (!labelConfig.Italic)
                {
                    label.Font = new System.Drawing.Font(labelConfig.Font.Trim(), labelConfig.Size, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                }
                else
                {
                    label.Font = new System.Drawing.Font(labelConfig.Font.Trim(), labelConfig.Size, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                }
            }
            else
            {
                if (!labelConfig.Italic)
                {
                    label.Font = new System.Drawing.Font(labelConfig.Font.Trim(), labelConfig.Size, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                }
                else
                {
                    label.Font = new System.Drawing.Font(labelConfig.Font.Trim(), labelConfig.Size, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                }
            }
        }
Ejemplo n.º 3
0
        public void Test_GetErrorMessage()
        {
            var config = new LabelConfig();
            var msg    = config.GetErrorMessage(-3);

            Assert.AreEqual("链接错误", msg);
        }
Ejemplo n.º 4
0
        private bool GetPnConfig(string pn)
        {
            bool   result   = false;
            string labelMsg = "";

            _labelConfig = _romConvert.GetLabelConfig(pn, ref result, ref labelMsg);
            if (result)
            {
                AddStatus("标签配置下载成功");
                if (_labelConfig.TwoSn)
                {
                    txtSNExtend.Visible = true;
                    AddStatus("该料号有两个sn,请注意");
                }
                var template = _labelConfig.TempeleteBytes.Rotate();

                string templateFile = "template\\" + pn + ".txt";
                Extension.Write2DArray(template, templateFile);
                AddStatus("下载料号模板文件成功,路径:" + templateFile);
                btnTest.Enabled = true;
                txtSN.Focus();
            }
            else
            {
                AddStatus("标签配置下载失败");
            }

            return(result);
        }
Ejemplo n.º 5
0
        public void ExportFontData(List <FontData> fontDatas, List <ImageDecorator> decorators)
        {
            LabelConfig labelConfig = null;

            if (_twoLetters.Equals("1"))
            {
                labelConfig = new TwoLetterConfig();
            }
            else
            {
                labelConfig = new SingleLetterConfig(BigString);
            }

            foreach (var fontdata in fontDatas)
            {
                var imagePath = Path.Combine(dir.ToString(), fontdata.FontName);
                Directory.CreateDirectory(imagePath);
                labelConfig.LabelDatas.ForEach(ld =>
                {
                    SaveOneImage(ld.Label, ld.LabelAsFolderName, fontdata, imagePath, decorators);
                });
            }
        }
        /// <summary>
        /// normalize size of images, put all images and its identity into two byte files as for MNIST
        /// one file with image data
        /// second file with image label data
        ///
        /// shuffle will make sure that the imagedata are organized in random order, so machine learning training don't need to shuffle it
        /// </summary>
        public static void GenerateByteFile(string fontDataDirDest, int size, LabelConfig labelConfig)
        {
            var imageData  = ConfigurationManager.AppSettings["ImageData"];
            var imageLabel = ConfigurationManager.AppSettings["ImageLabel"];

            File.Delete(imageData);
            File.Delete(imageLabel);


            Dictionary <string, List <ImageData> > alldata = new Dictionary <string, List <ImageData> >();



            foreach (var folder in Directory.GetDirectories(fontDataDirDest))
            {
                var folderName        = folder.Split('\\');
                var ld                = labelConfig.LabelDatas.Single(x => x.LabelAsFolderName.Equals(folderName[folderName.Length - 1]));
                var imageDatasPerChar = new List <ImageData>();

                foreach (var file in Directory.GetFiles(folder))
                {
                    imageDatasPerChar.Add(new ImageData {
                        Path = file, Label = ld.Label, LabelAsInt = ld.LabelAsInt
                    });
                }
                //shuffle each dataset for each char
                imageDatasPerChar.Shuffle();
                alldata[ld.Label] = imageDatasPerChar;
            }

            //split 50% of all char data as training data and 50% as test data, both test / train collection holds a equal distribution for all chars
            var testDatas  = new List <ImageData>();
            var trainDatas = new List <ImageData>();

            foreach (KeyValuePair <string, List <ImageData> > entry in alldata)
            {
                var data   = entry.Value.OrderBy(x => x.Label).ToList();
                var count  = data.Count;
                var offset = count / 2;
                var trainD = data.Take(offset).ToList();
                trainDatas.AddRange(trainD);
                var testD = data.Skip(offset).Take(count - offset).ToList();
                testDatas.AddRange(testD);
            }
            //merge test and train dataset
            var imageDatas = new List <ImageData>();

            trainDatas.Shuffle();
            testDatas.Shuffle();

            imageDatas.AddRange(trainDatas);
            imageDatas.AddRange(testDatas);

            //write data to file
            var labelWriter     = new BinaryWriter(new FileStream(imageLabel, FileMode.CreateNew));
            var imageDataWriter = new BinaryWriter(new FileStream(imageData, FileMode.CreateNew));
            var total           = Directory.GetDirectories(fontDataDirDest).Sum(folder => Directory.GetFiles(folder).Count());

            WriteDataToFile(imageDatas, labelWriter, imageDataWriter, total, size);

            //data integrity check

            var labels = imageDatas.Select(x => x.LabelAsInt).ToList();

            VerifyLabelByteFile(imageLabel, labels);
            VerifyImageDataByteFile(imageData, imageDatas.Count(), size);
        }
Ejemplo n.º 7
0
 public Label(LabelConfig config) { throw new Exception(); }
Ejemplo n.º 8
0
        public static bool QueryPn(string pn, ref LabelConfig labelConfig, ref string msg)
        {
            bool   ret        = false;
            string queryPnSql = "Select PN,Valid,SWR_Check,SWR_Deadline,SN_Type," +
                                "CreateDate,Description,PE_Valid,DateCode8Format,CustomerName," +
                                "MapFile,Label_length FROM EEPROMManagement WHERE PN = ?";

            OleDbParameter[] b = new OleDbParameter[1];
            b[0] = new OleDbParameter("0", pn);
            DataTable dt = DbHelperOleDb.Query(queryPnSql, DB_MesDataCenterConnectionString, b).Tables[0];

            if (dt.Rows.Count == 0)
            {
                msg = "该PN对应的文件还未上传,请联系电子工程师上传文件,联系电话13620065253";
                return(false);
            }
            string valid       = Object2Str(dt.Rows[0]["Valid"]);
            string swrCheck    = Object2Str(dt.Rows[0]["SWR_Check"]);
            string peValid     = Object2Str(dt.Rows[0]["PE_Valid"]);
            string swrDeadline = Object2Str(dt.Rows[0]["SWR_Deadline"]);

            if (valid.ToUpper() != "TRUE")
            {
                if (swrCheck.ToUpper() != "TRUE")
                {
                    if (peValid.ToUpper() == "TRUE")
                    {
                        msg = "该PN对应的文件还未经过QC的确认,请联系QC确认,QC联系电话13425162206";
                    }
                    else
                    {
                        msg = "该PN对应的文件既没有确认,也没有发行SWR!请先联系对应PE工程师确认,然后联系QC确认,QC联系电话:13425162206";
                    }

                    return(false);
                }

                if (!CheckTimeInRange(swrDeadline))
                {
                    msg = "该PN对应的文件SWR时间已过期!有效日期段为:";
                    return(false);
                }
            }


            string snType      = (string)dt.Rows[0]["SN_Type"];
            string description = (string)dt.Rows[0]["Description"];
            int    labelLength = Object2Int(dt.Rows[0]["Label_length"]);

            byte[]   mapFile  = (byte[])dt.Rows[0]["MapFile"];
            byte[][] romBytes = GetRomBytes(mapFile, snType, description);

            string queryLabelSql =
                "SELECT labelType, yearStart, yearEnd, monthStart, monthEnd, " +
                "weekStart, weekEnd, DayStart, DayEnd, snStart, " +
                "snEnd, description, snFormat, cableType, preStaData, " +
                "significant, noErrorRetest, twobar  FROM labelconfig WHERE labelType =?";

            b[0] = new OleDbParameter("0", snType);
            DataTable dt1 = DbHelperOleDb.Query(queryLabelSql, DB_HTPSDBConnectionString, b).Tables[0];

            if (dt1.Rows.Count == 0)
            {
                msg = "未能找到对应label类型:" + snType;
                return(false);
            }
            labelConfig.Customer            = Object2Str(dt.Rows[0]["CustomerName"]);
            labelConfig.Description         = Object2Str(dt1.Rows[0]["description"]);
            labelConfig.YearStart           = Object2Int(dt1.Rows[0]["yearStart"]);
            labelConfig.YearEnd             = Object2Int(dt1.Rows[0]["yearEnd"]);
            labelConfig.MonthStart          = Object2Int(dt1.Rows[0]["monthStart"]);
            labelConfig.MonthEnd            = Object2Int(dt1.Rows[0]["monthEnd"]);
            labelConfig.WeekStart           = Object2Int(dt1.Rows[0]["weekStart"]);
            labelConfig.WeekEnd             = Object2Int(dt1.Rows[0]["weekEnd"]);
            labelConfig.DayStart            = Object2Int(dt1.Rows[0]["DayStart"]);
            labelConfig.DayEnd              = Object2Int(dt1.Rows[0]["DayEnd"]);
            labelConfig.SnStart             = Object2Int(dt1.Rows[0]["snStart"]);
            labelConfig.SnEnd               = Object2Int(dt1.Rows[0]["snEnd"]);
            labelConfig.SnFormat            = Object2Str(dt1.Rows[0]["snFormat"]);
            labelConfig.DateCode8Value_0X30 = (int)dt.Rows[0]["DateCode8Format"];
            labelConfig.TempeleteBytes      = romBytes;
            labelConfig.TwoSn               = Object2Int(dt1.Rows[0]["twobar"]) == 1;//为1时表示有两个条码
            labelConfig.LabelLength         = labelLength;
            return(true);
        }
Ejemplo n.º 9
0
        //normallly we run command 2 then command 1, when byte file for image and label are generated
        //move those files to ML solution
        static void Main(string[] args)
        {
            //for each character, we have around 10000 images, either synthesized ones or dummy copies.
            //our ML solution does not randomize the order of the images, therefore it is vital that we shuffle them
            //already in this project
            Console.WriteLine("generate a byte file containing all image byte data by pointing to an image source - 1");

            //we are not sure if the synthesize works, but it is supported. if synthesize is not used, in order to gain enough
            //training examples, we are going to make copies of original ones. The images are organized by font name, not by
            //character identity, we are going to resize them into 28*28 and reorganize them into folder by character identity,
            //then for each image, either we synthesize it or or we make some copies of it (if we are using windows font for testing, 14 fonts, 1000 copies are enougth)
            Console.WriteLine("synthesize images / make copies of original ones - 2");

            //the ML pipleline takes image and label byte files generated by us as input
            //in order to make sure our own byte files are in correct format, we unpack the original
            //"..\\..\\Data\\train-labels-idx1-ubyte", "..\\..\\Data\\train-images-idx3-ubyte" files into
            //normal image files. When we view the actual images, we can be sure about the processing
            //generating the byte files for image/label

            Console.WriteLine("unpack mnist byte files into images - 3");
            LabelConfig labelConfig = null;

            if (_twoLetters.Equals("1"))
            {
                labelConfig = new TwoLetterConfig();
            }
            else
            {
                var allSingleChars = ConfigurationManager.AppSettings["GeneratedChars"];
                labelConfig = new SingleLetterConfig(allSingleChars);
            }

            var command = Console.ReadLine();

            if (command.Equals("1"))
            {
                ByteFileGenerator.GenerateByteFile(_fontDataDirDest, size, labelConfig);
            }
            else if (command.Equals("2"))
            {
                Console.WriteLine("we are going to normalize the data and put them into folder with char name, do you want to spawn 5 synthesized images per image? (false/true)");
                var shouldSynthesize = Convert.ToBoolean(Console.ReadLine());


                Console.WriteLine("generate more copies of original image? type of number, if 1 no copy is saved, if larger than 1 then N-1 more copies will be saved");
                var copy = Convert.ToInt32(Console.ReadLine());



                //the images feed into ML solution has black background
                Console.WriteLine("should make background black? (true/false)");
                var colorInvert = Convert.ToBoolean(Console.ReadLine());

                //create dirs for the chars or two letters
                labelConfig.LabelDatas.ForEach(ld => { DirGenerator.CreateDir(ld.Label, _fontDataDirDest); });

                Directory.CreateDirectory(_fontDataDir);
                Directory.CreateDirectory(_fontDataDirDest);
                ImageGenerator.GenerateImages(_fontDataDir,
                                              _fontDataDirDest,
                                              shouldSynthesize,
                                              synthesizeCount,
                                              copy,
                                              colorInvert,
                                              size);
            }
            else if (command.Equals("3"))
            {
                Console.WriteLine("read byte data from MNIST files, then output new byte files?");
                bool resaveByteFile = Convert.ToBoolean(Console.ReadLine());
                Console.WriteLine("save images to hard disk?");
                bool saveImages   = Convert.ToBoolean(Console.ReadLine());
                bool orderbylabel = false;
                if (resaveByteFile)
                {
                    Console.WriteLine("order by label?");
                    orderbylabel = Convert.ToBoolean(Console.ReadLine());
                }

                MNISTUnpack.UnpackByteFileToImages("..\\..\\Data\\train-labels-idx1-ubyte",
                                                   "..\\..\\Data\\train-images-idx3-ubyte",
                                                   _mnistDir,
                                                   resaveByteFile,
                                                   saveImages,
                                                   orderbylabel);
            }
        }