示例#1
0
        /// <summary>
        /// rotate the image for  <param name="angles"> angles and load them into the <param name="retList"> List.
        /// </summary>
        /// <param name="retList">the list that mean to be loaded with the new templates, create a new one if null is passed in</param>
        /// <param name="image">input image</param>
        /// <param name="angles">the number of angles</param>
        /// <param name="Width">The Width that the orginal image is cropped into, must be less than image.Width()</param>
        /// <param name="Height">The Height that the orginal image is cropped into, must be less than image.Height()</param>
        /// <param name="buildXMLTemplateFile">true to build a xml file with current templates</param>
        /// <param name="maxFeaturesPerLevel">the array of maximum features per pyrimid level, default to 200 in DEFAULT_MAX_FEATURES_PER_LEVEL from ImageTemplatePyramid.cs:56,
        ///                                     increase to increase the precision in expense of detection time-delay</param>
        /// <param name="userFunc">Input User Function for customization and diversity</param>
        /// <returns>nothing.</returns>
        private static void rotateLoad(List <TemplatePyramid> retList, Gray <byte>[,] image, int angles, int Width, int Height, bool buildXMLTemplateFile = false, int[] maxFeaturesPerLevel = null, string name = "DefaultTemplate", Func <TemplatePyramid, Gray <byte> [, ], TemplatePyramid> userFunc = null)
        {
            string resourceDir = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "Resources");

            retList = (retList == null ? new List <TemplatePyramid>() : retList);
            Width   = (Width > image.Width() ? image.Width() : Width);
            Height  = (Height > image.Height() ? image.Height() : Height);
            //userFunc = (userFunc != null) ? userFunc : (inputList, inputImage) => inputList;

            for (int i = 0; i < angles; i++)
            {
                float  ImageAngle = (float)i * 360 / angles;
                Bitmap bitmap     = image.ToBitmap();

                Bitmap   returnBitmap = new Bitmap(Width, Height);
                Graphics graphics     = Graphics.FromImage(returnBitmap);
                graphics.TranslateTransform((float)Width / 2, (float)Height / 2);
                graphics.RotateTransform(ImageAngle);
                graphics.TranslateTransform(-(float)Width / 2, -(float)Height / 2);
                graphics.DrawImage(bitmap, new System.Drawing.Point(-(image.Width() - Width) / 2, -(image.Height() - Height) / 2));
                bitmap.Dispose();
                returnBitmap.Save("TP.bmp");
                Console.WriteLine(" angle " + ImageAngle);
                Gray <byte>[,] preparedBWImage = ImageIO.LoadGray("TP.bmp").Clone();

                try
                {
                    TemplatePyramid newTemp = TemplatePyramid.CreatePyramidFromPreparedBWImage(
                        preparedBWImage, name, ImageAngle, maxNumberOfFeaturesPerLevel: maxFeaturesPerLevel);
                    if (userFunc != null)
                    {
                        newTemp = userFunc(newTemp, image);
                    }
                    retList.Add(newTemp);
                }
                catch (Exception)
                { }
            }
            if (buildXMLTemplateFile)
            {
                XMLTemplateSerializer <ImageTemplatePyramid <ImageTemplate>, ImageTemplate> .ToFile(retList, Path.Combine(resourceDir, "template" + ".xml"));
            }
        }