示例#1
0
        public virtual CropResult analyze(Bitmap input)
        {
            Image inputI  = new Image(input);
            Image outputI = new Image(input.Width, input.Height);

            prepareCie(inputI);
            edgeDetect(inputI, outputI);
            skinDetect(inputI, outputI);
            saturationDetect(inputI, outputI);

            //Bitmap output = new Bitmap(input.Width, input.Height);

            //for (int i = 0; i < input.Width; i++)
            //	for (int j = 0; j < input.Height; j++) {
            //		output.SetPixel(i, j, );
            //	}


            Bitmap score  = new Bitmap(input.Width / options.ScoreDownSample, input.Height / options.ScoreDownSample);           //, options.BufferedBitmapType);
            Image  scoreI = new Image(score);

            float       topScore = float.NegativeInfinity;
            Crop        topCrop  = null;
            List <Crop> crops    = this.crops(scoreI);

            //int l = 0;
            foreach (Crop crop in crops)
            {
                crop.score = this.score(scoreI, crop);
                if (crop.score.total > topScore)
                {
                    topCrop  = crop;
                    topScore = crop.score.total;
                }
                crop.x      *= options.ScoreDownSample;
                crop.y      *= options.ScoreDownSample;
                crop.width  *= options.ScoreDownSample;
                crop.height *= options.ScoreDownSample;

                //Crop(input, crop.width, crop.height, crop.x, crop.y).Save(lw.Utils.StringUtils.ToURL(DateTime.Now.Ticks.ToString()) + ".jpg");
            }

            CropResult result = new CropResult(topCrop, crops);

            //Graphics graphics = output.Graphics;
            //graphics.Color = Color.cyan;
            //if (topCrop != null)
            //{
            //	graphics.drawRect(topCrop.x, topCrop.y, topCrop.width, topCrop.height);
            //}

            return(result);
        }
示例#2
0
        public System.Drawing.Image Crop(System.Drawing.Image imgPhoto, int Width,
                                         int Height)
        {
            Options options = new Options();

            options.cropWidth(Width);
            options.cropHeight(Height);

            CropResult cropResult = analyze(options, (Bitmap)imgPhoto);

            return(Crop(imgPhoto, cropResult.topCrop.width, cropResult.topCrop.height, cropResult.topCrop.x, cropResult.topCrop.y));
        }