Ejemplo n.º 1
0
        public static UIImage DrawResults(UIImage img, MultiboxGraph.Result result, float scoreThreshold)
        {
            Rectangle[] locations = ScaleLocation(result.DecodedLocations, (int)img.Size.Width, (int)img.Size.Height);

            UIGraphics.BeginImageContextWithOptions(img.Size, false, 0);
            var context = UIGraphics.GetCurrentContext();

            img.Draw(new CGPoint());
            context.SetStrokeColor(UIColor.Red.CGColor);
            context.SetLineWidth(2);
            for (int i = 0; i < result.Scores.Length; i++)
            {
                if (result.Scores[i] > scoreThreshold)
                {
                    Rectangle rect   = locations[result.Indices[i]];
                    CGRect    cgRect = new CGRect(rect.X, rect.Y, rect.Width, rect.Height);
                    context.AddRect(cgRect);
                    context.DrawPath(CGPathDrawingMode.Stroke);
                }
            }
            UIImage imgWithRect = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();
            return(imgWithRect);
        }
Ejemplo n.º 2
0
        public static void DrawResults(NSImage img, MultiboxGraph.Result result, float scoreThreshold)
        {
            Rectangle[] locations = ScaleLocation(result.DecodedLocations, (int)img.Size.Width, (int)img.Size.Height);
            img.LockFocus();

            NSColor redColor = NSColor.Red;

            redColor.Set();
            var context   = NSGraphicsContext.CurrentContext;
            var cgcontext = context.CGContext;

            cgcontext.ScaleCTM(1, -1);
            cgcontext.TranslateCTM(0, -img.Size.Height);
            //context.IsFlipped = !context.IsFlipped;
            for (int i = 0; i < result.Scores.Length; i++)
            {
                if (result.Scores[i] > scoreThreshold)
                {
                    Rectangle rect = locations[result.Indices[i]];
                    //img.Draw()
                    //Trace.WriteLine(String.Format("x: {0}, y: {1}, w: {2}, h: {3}", rect.X, rect.Y, rect.Width, rect.Height));
                    CGRect cgRect = new CGRect(rect.X, rect.Y, rect.Width, rect.Height);
                    //img.Draw(cgRect);
                    //CGPath path = CGPath.FromRect(cgRect);
                    //NSBezierPath path = NSBezierPath.FromOvalInRect(cgRect);
                    //path.Fill();
                    //path.Stroke();
                    NSBezierPath.StrokeRect(cgRect);
                    //img.Draw(cgRect, );
                }
            }
            img.UnlockFocus();
        }
Ejemplo n.º 3
0
        public byte[] DrawResultsToJpeg(String fileName, MultiboxGraph.Result detectResult, float scoreThreshold = 0.2f)
        {
#if __ANDROID__
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.InMutable = true;
            Android.Graphics.Bitmap bmp = BitmapFactory.DecodeFile(fileName, options);
            MultiboxGraph.DrawResults(bmp, detectResult, scoreThreshold);
            using (MemoryStream ms = new MemoryStream())
            {
                bmp.Compress(Bitmap.CompressFormat.Jpeg, 90, ms);
                return(ms.ToArray());
            }
#elif __MACOS__
            NSImage img = NSImage.ImageNamed(fileName);
            MultiboxGraph.DrawResults(img, detectResult, scoreThreshold);
            var    imageData = img.AsTiff();
            var    imageRep  = NSBitmapImageRep.ImageRepsWithData(imageData)[0] as NSBitmapImageRep;
            var    jpegData  = imageRep.RepresentationUsingTypeProperties(NSBitmapImageFileType.Jpeg, null);
            byte[] jpeg      = new byte[jpegData.Length];
            System.Runtime.InteropServices.Marshal.Copy(jpegData.Bytes, jpeg, 0, (int)jpegData.Length);
            return(jpeg);
#elif __IOS__
            UIImage uiimage = new UIImage(fileName);

            UIImage newImg   = MultiboxGraph.DrawResults(uiimage, detectResult, scoreThreshold);
            var     jpegData = newImg.AsJPEG();
            byte[]  jpeg     = new byte[jpegData.Length];
            System.Runtime.InteropServices.Marshal.Copy(jpegData.Bytes, jpeg, 0, (int)jpegData.Length);
            return(jpeg);
#else
            throw new Exception("Not implemented");
#endif
        }
Ejemplo n.º 4
0
        public static void DrawResults(Bitmap bmp, MultiboxGraph.Result result, float scoreThreshold)
        {
            Rectangle[] locations = ScaleLocation(result.DecodedLocations, bmp.Width, bmp.Height);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                for (int i = 0; i < result.Scores.Length; i++)
                {
                    if (result.Scores[i] > scoreThreshold)
                    {
                        Rectangle rect   = locations[result.Indices[i]];
                        Pen       redPen = new Pen(Color.Red, 3);

                        g.DrawRectangle(redPen, rect);
                    }
                }
                g.Save();
            }
        }
Ejemplo n.º 5
0
        public static void DrawResults(Android.Graphics.Bitmap bmp, MultiboxGraph.Result result, float scoreThreshold)
        {
            Rectangle[] locations = ScaleLocation(result.DecodedLocations, bmp.Width, bmp.Height);

            Android.Graphics.Paint p = new Android.Graphics.Paint();
            p.SetStyle(Paint.Style.Stroke);
            p.AntiAlias = true;
            p.Color     = Android.Graphics.Color.Red;
            Canvas c = new Canvas(bmp);


            for (int i = 0; i < result.Scores.Length; i++)
            {
                if (result.Scores[i] > scoreThreshold)
                {
                    Rectangle             rect = locations[result.Indices[i]];
                    Android.Graphics.Rect r    = new Rect(rect.Left, rect.Top, rect.Right, rect.Bottom);
                    c.DrawRect(r, p);
                }
            }
        }
Ejemplo n.º 6
0
        public static void DrawResults(Texture2D image, MultiboxGraph.Result result, float scoreThreshold)
        {
            Rect[] locations = ScaleLocation(result.DecodedLocations, image.width, image.height);

            Color color = new Color(1.0f, 0, 0);//Set color to red

            for (int i = 0; i < result.Scores.Length; i++)
            {
                if (result.Scores[i] > scoreThreshold)
                {
                    Rect r = locations[result.Indices[i]];
                    //Texture 2D coordinates is flipped upside down, we need to do the same flipping for the Rectangle
                    r.y = image.height - r.y - r.height;
                    DrawRect(image, r, color);
                }
            }
            image.Apply();
            //GUI.color = Color.white;//Reset color to white

            /*
             * Android.Graphics.Paint p = new Android.Graphics.Paint();
             * p.SetStyle(Paint.Style.Stroke);
             * p.AntiAlias = true;
             * p.Color = Android.Graphics.Color.Red;
             * Canvas c = new Canvas(bmp);
             *
             *
             * for (int i = 0; i < result.Scores.Length; i++)
             * {
             *  if (result.Scores[i] > scoreThreshold)
             *  {
             *      Rectangle rect = locations[result.Indices[i]];
             *      Android.Graphics.Rect r = new Rect(rect.Left, rect.Top, rect.Right, rect.Bottom);
             *      c.DrawRect(r, p);
             *  }
             * }*/
        }