private static double[] getCentroid(ImageObject imageObject)
 {
     Contract.Requires(null!=imageObject);
     imageObject.EnsureAssignedToLayer();
     var boundingBox=imageObject.Contour.FindBoundingBox();
     var centroid=new double[2];
     double area=0;
     for(var i=boundingBox.Y;i<boundingBox.Bottom;i++)
         for(var j=boundingBox.X;j<boundingBox.Right;j++)
             if(imageObject.Id==imageObject.Layer.Map[j,i]) {
                 centroid[0]+=j;
                 centroid[1]+=i;
                 area++;
             }
     centroid[0]=(centroid[0]/area);
     centroid[1]=(centroid[1]/area);
     return centroid;
 }
Example #2
0
        /// <summary>
        /// инициализация объектов
        /// </summary>
        public static void Load()
        {
            Random rnd = new Random();

            objs = new BaseObject[30];
            for (int i = 0; i < objs.Length - 1; i++)
            {
                int tmp = rnd.Next(5, 25);
                objs[i] = new Star(new Point(i * 50, i * 35), new Point(50 - i, 50 - i), new Size(tmp, tmp));
            }
            objs[objs.Length - 1] = new CoolComet(new Point(29 * 12, 400), new Point(10, 15));
            monsters = new ImageObject[10];
            for (int i = 0; i < monsters.Length; i++)
            {
                int tmp = rnd.Next(5, 25);
                monsters[i] = new ImageObject(new Point((i + 40) * 12, i * 30), new Point(5 - i, 15 - i), new Size((int)(tmp * 2.2), (int)(tmp * 2.2)), "image.png");
            }
            //bul = new Bullet(new Point(0,rnd.Next(0,500)),new Point(10,0),new Size(49,100));
        }
Example #3
0
        public override void Init()
        {
            base.Init();
            this.LoadResource();

            cells = new Cell[10, 10];
            double cellSizeX = new ImageObject(2).SizeX;
            double cellSizeY = new ImageObject(2).SizeY;

            for (int y = 0; y < 10; y++)
            {
                for (int x = 0; x < 10; x++)
                {
                    cells[y, x]      = new Cell(new ImageObject(1), new ImageObject(2));
                    cells[y, x].PosX = 100 + cellSizeX * x + cellSizeX * y / 2;
                    cells[y, x].PosY = 100 + cellSizeY / 4 * y;
                }
            }
        }
Example #4
0
        /// <summary>
        /// Returns image on the list closest to input milepost.
        /// </summary>
        /// <param name="dMilepost">Milepost for which image is desired</param>
        /// <returns>Image object nearest to milepost.</returns>
        private ImageObject GetNearestImage(double dMilepost)
        {
            ImageObject imageObject = null;
            double      dClosest    = double.MaxValue;
            int         nIndex      = 0;

            foreach (ImageObject io in m_listImageObjects)
            {
                double dDifference = Math.Abs(io.Milepost - dMilepost);
                if (dDifference < dClosest)
                {
                    dClosest             = dDifference;
                    imageObject          = io;
                    m_nCurrentImageIndex = nIndex;
                }
                nIndex++;
            }
            return(imageObject);
        }
Example #5
0
    //Match features from canvas and show image om screen (download image)
    public IEnumerator MatchAndDownload()
    {
        ImageObject image;
        GameObject  instantiatedWait = Instantiate(wait, screenshotPreview.transform);

        //Pick the pixels inside the square
        ImagePartToByteArray();

        //Get imageList
        yield return(imageList.GetTextFromURL());

        Debug.Log("Image list count: " + imageList.getImageList().Count);

        //Don't match features if no images is on the canvas
        if (imageList.getImageList().Count == 0)
        {
            image = new ImageObject(Convert.ToBase64String(imagePart), -1);
        }
        // Match feature from images on canvas.
        else
        {
            image = featureMatcher.DownloadImage(Convert.ToBase64String(imagePart), imageList.getImageList());
            Debug.Log("Features tracking done");
        }
        Destroy(instantiatedWait);
        if (image.index == -1)
        {
            Debug.Log("No match");
            yield break;
        }

        ui.Show(GameObject.Find("Panel"));

        Texture2D winnerImageTexture = new Texture2D(image.imageMat.cols(), image.imageMat.rows(), TextureFormat.RGB24, false);

        Debug.Log("texture: " + winnerImageTexture);
        Utils.matToTexture2D(image.imageMat, winnerImageTexture);

        imagePreview.GetComponent <RectTransform>().sizeDelta = new Vector2(winnerImageTexture.width, winnerImageTexture.height);

        // Set the sprite to the imagePreview
        imagePreview.GetComponent <RawImage>().texture = winnerImageTexture;
    }
Example #6
0
        private void DecrementNavigation()
        {
            bool        bStop = false;
            ImageObject io    = m_NavigationObject.IncrementUpdate(-1, out bStop);

            if (!bStop)
            {
                this.UpdateNavigation         = false;
                toolStripTextBoxStation.Text  = io.Milepost.ToString();
                toolStripComboBoxSection.Text = io.Section;
                ImageViewManager.UpdateNavigateTick(ImageViewManager.TreeView.Nodes, m_NavigationObject);
                if (toolStripTextBoxFrameDelay.Visible)
                {
                    toolStripTextBoxFrameDelay.Visible = false;
                    toolStripLabelSecond.Text          = toolStripTextBoxFrameDelay.Text + " seconds";
                }
                this.UpdateNavigation = true;
            }
        }
        public void get_ImageManipulatorTypeTest()
        {
            Bitmap b   = new Bitmap(10, 10);
            Image  img = (Image)b;

            ImageManipulatorType.Name manipulator = ImageManipulatorType.Name.ERROR_DIFFUSION;
            ImageObject target = new ImageObject(img, manipulator);

            ImageManipulatorType.Name expected = ImageManipulatorType.Name.ERROR_DIFFUSION;
            ImageManipulatorType.Name actual;
            actual = target.get_ImageManipulatorType();
            Assert.AreEqual(expected, actual);

            manipulator = ImageManipulatorType.Name.BLACKWHITE;
            target      = new ImageObject(img, manipulator);

            actual = target.get_ImageManipulatorType();
            Assert.AreNotEqual(expected, actual);
        }
Example #8
0
            /// <summary>
            /// Parse the operand string provided to IF_MATCH opcode to get
            /// image object components.
            /// </summary>
            /// <param name="operand">A string separated by "|"</param>
            /// <returns></returns>
            public static ImageObject Parse(string operand)
            {
                ImageObject theObject = new ImageObject();

                if (operand.IndexOf('|') > 0)
                {
                    string[] components = operand.Split(new char[] { '|' });
                    theObject.ImageName = components[0];
                    if (components.Length > 1)
                    {
                        string[] angleAndError = components[1].Split(new char[] { ',' });
                        int.TryParse(angleAndError[0], out theObject.Angle);
                        if (angleAndError.Length > 1)
                        {
                            int.TryParse(angleAndError[1], out theObject.AngleError);
                        }
                    }
                }
                else
                {
                    var baseUri = new Uri("file://");
                    var uri     = new Uri(baseUri, operand);
                    if (uri.Segments.Count() > 1)
                    {
                        theObject.ImageName = uri.Segments[1];
                        NameValueCollection query = HttpUtility.ParseQueryString(uri.Query);
                        if (query["ratioReferenceMatch"] != null)
                        {
                            var val = Convert.ToDouble(query["ratioReferenceMatch"]);
                            theObject.RatioReferenceMatch = (float)val;
                        }
                        if (query["angle"] != null)
                        {
                            Int32.TryParse(query["angle"], out theObject.Angle);
                        }
                        if (query["angleError"] != null)
                        {
                            Int32.TryParse(query["angleError"], out theObject.Angle);
                        }
                    }
                }
                return(theObject);
            }
Example #9
0
        /// <summary>
        /// Method detects face on image provided as byte array.
        /// </summary>
        /// <param name="Image">[In]ImageObject object</param>
        /// <returns>Method returns list with detected faces or empty list when no faces found.</returns>
        public List <DETECTED_ITEM> DetectFaces(ImageObject ImageObject)
        {
            List <DETECTED_ITEM> DetectedFaces = new List <DETECTED_ITEM>();

            if ((ImageObject != null) && (FaceDetector_DetectFaces(IntObjPtr, ImageObject.InnerPtr) == FACE_DETECTION_RESULT.FD_RESULT_OK))
            {
                int DetectedCount = FaceDetector_GetDetectedCount(IntObjPtr);
                if (DetectedCount > 0)
                {
                    for (int i = 0; i < DetectedCount; i++)
                    {
                        DETECTED_ITEM Item = new DETECTED_ITEM();
                        FaceDetector_GetDetectedItem(IntObjPtr, i, ref Item);
                        DetectedFaces.Add(Item);
                    }
                    FaceDetector_DetectReset(IntObjPtr);
                }
            }
            return(DetectedFaces);
        }
Example #10
0
        public override void OnInit()
        {
            SetBounds(300, 300, 800, 600);

            SetTitle("F**k the world");

            //replace with a file path in desk
            var b = ImageObject.FromFile(@"C:\frice.png", 300, 400, 50, 50);

//			var c = ImageObject.FromWeb("https://avatars1.githubusercontent.com/u/21008243", 400, 300);

            //can resize:
//			c.Height = 100;
//			c.Width = 100;
            b.MoveList.Add(new SimpleMove(-10, -10));
//			c.MoveList.Add(new SimpleMove(-10, 10));
            AddObject(b);
            AddObject(new SimpleText(ColorResource.高坂穗乃果, "Hello World", 10, 10));
//			AddObject(c);
        }
Example #11
0
        private ERR_RESULT inner_AddImgObject(ImageObject obj, XElement objectsNode)
        {
            ERR_RESULT result    = new ERR_RESULT();
            XElement   objNode   = null;
            XElement   labelNode = null;
            XElement   posNode   = null;
            XElement   sizeNode  = null;

            try
            {
                foreach (ImageObject.IMAGEPOSITION pos in obj.objects)
                {
                    objNode   = new XElement("object");
                    labelNode = new XElement("label", pos.label);

                    String posVal = pos.LT_pos.X.ToString() + "," + pos.LT_pos.Y.ToString();
                    posNode = new XElement("pos", posVal);

                    String sizeVal = pos.width + "," + pos.height;
                    sizeNode = new XElement("size", sizeVal);

                    objNode.Add(labelNode);
                    objNode.Add(posNode);
                    objNode.Add(sizeNode);

                    objectsNode.Add(objNode);
                }

                return(result);
            }
            catch (_XmlException err)
            {
                result = ErrProcess.SetErrResult(err);
                return(result);
            }
            catch (Exception err)
            {
                result = ErrProcess.SetErrResult(err);
                return(result);
            }
        }
Example #12
0
        /// <summary>
        /// Retrieves first section in precedent order for a section.
        /// </summary>
        /// <param name="strSection"></param>
        /// <returns></returns>
        private ImageObject GetNearestImage(String strSection)
        {
            ImageObject imageObject = null;
            int         nMinimum    = int.MaxValue;
            int         nIndex      = 0;

            foreach (ImageObject io in m_listImageObjects)
            {
                if (io.Section == strSection)
                {
                    if (io.Precedent < nMinimum)
                    {
                        nMinimum             = io.Precedent;
                        imageObject          = io;
                        m_nCurrentImageIndex = nIndex;
                    }
                }
                nIndex++;
            }
            return(imageObject);
        }
Example #13
0
        public override void OnInit()
        {
            Width  = 800;
            Height = 600;

//			var b = new ShapeObject(ColorResource.小埋色, new FCircle(40), 300, 200);
            var a = new ShapeObject(ColorResource.吾王蓝, new FCircle(40), 300, 200);
//			var c = new ShapeObject(ColorResource.基佬紫, new FCircle(40), 300, 200);
            //replace with a file path in disk
//			var b = ImageObject.FromFile(@"C:\frice.png", 300, 200, 100, 100);
            var b = ImageObject.FromWeb("https://avatars3.githubusercontent.com/u/16398479", 300, 200, 100, 100);
            var c = ImageObject.FromWeb("https://avatars1.githubusercontent.com/u/21008243", 300, 200, 100, 100);

//			AddObjects(a, b, c);
            AddObject(a);
            AddObject(b);
            AddObject(c);
            RandomMove(a, 1000);
            RandomMove(b, 1500);
            RandomMove(c, 750);
        }
Example #14
0
        /// <summary>
        /// 重绘控件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            base.OnPaint(e);


            try
            {
                if (state == State.MouseOver && _OverImg == null)
                {
                    base.InvokePaintBackground(this, new PaintEventArgs(e.Graphics, base.ClientRectangle));
                    ImageDrawRect.DrawRect(e.Graphics, NormalImg, e.ClipRectangle, 1, 1);
                    LineartBrush = new LinearGradientBrush(
                        new Rectangle(0, 0, ClientRectangle.Width, ClientRectangle.Height),
                        Color.FromArgb(230, Color.White), Color.FromArgb(250, Color.White), 90);
                    g.FillRectangle(LineartBrush, new Rectangle(0, 0, ClientRectangle.Width, ClientRectangle.Height));
                    ImageDrawRect.DrawRect(g, ImageObject.GetResBitmap("GSSUI.ASkinImg.ButtonImg.Botton2.png"), e.ClipRectangle, Rectangle.FromLTRB(10, 10, 10, 10), 1, 5);
                }
            }
            catch
            { }
        }
Example #15
0
        public ImageObject UploadImage(string base64FileContent, string fileName, string description, string userName)
        {
            var result = new ImageObject();

            // TODO: Check for correct data type and deal with base64 prefix

            var user = _context.Users.FirstOrDefault(u => u.UserName == userName);

            if (user == null)
            {
                throw new AppException("Error retrieving logged in user!");
            }
            else
            {
                result.UploadedBy = user;
            }

            if (base64FileContent == null || base64FileContent.Length == 0)
            {
                throw new AppException("File you are trying to upload is empty!");
            }

            var path = _appEnvironment.WebRootPath + $"\\Images\\{user.Id}\\" + fileName;

            var file = new FileInfo(path);

            file.Directory.Create(); // Create folder if there is none
            var bytes = Convert.FromBase64String(base64FileContent);

            File.WriteAllBytes(path, bytes);

            result.Name        = fileName;
            result.Description = description;
            result.Path        = path.Replace(_appEnvironment.WebRootPath, "..").Replace("\\", "/");

            _context.ImageObjects.Add(result);
            _context.SaveChanges();

            return(result);
        }
        /// <summary>
        /// 方法说明:装载图片文件
        /// 作    者:jason.tang
        /// 完成时间:2013-02-05
        /// </summary>
        /// <param name="image">图片对象</param>
        private void LoadImage(ImageObject image, DataGridView datagridview)
        {
            PictureBox pic = new PictureBox();

            pic.SizeMode = PictureBoxSizeMode.StretchImage;
            pic.Name     = Guid.NewGuid().ToString();
            pic.Width    = image.Width;
            pic.Height   = image.Height;

            if (!File.Exists(image.ImagePath))
            {
                pic.Image = Properties.Resources.none_img;
            }
            else
            {
                pic.Image         = Image.FromFile(image.ImagePath);
                pic.ImageLocation = image.ImagePath;
            }

            datagridview.Controls.Add(pic);
            pic.Location = new Point(image.LocationX, image.LocationY);
        }
    public void AddObjectToLayer(ImageObject objectToAdd)
    {
        allObjects.Add(objectToAdd);

        if (objectToAdd.GetComponent <RectTransform>() == null)
        {
            objectToAdd.gameObject.AddComponent <RectTransform>();
        }

        objectToAdd.transform.SetParent(transform);

        Vector3 localPos = objectToAdd.transform.localPosition;

        objectToAdd.transform.localPosition = new Vector3(Screen.width + (objectToAdd.GetComponent <RectTransform>().sizeDelta.x * 2) + localPos.x, 0, localPos.z);

        objectToAdd.gameObject.name = "Image " + allObjects.Count;

        objectToAdd.SortLayer     = canvas.sortingOrder;
        objectToAdd.EndPosition   = new Vector3(0 - objectToAdd.GetComponent <RectTransform>().sizeDelta.x * 2, objectToAdd.transform.position.y);
        objectToAdd.StartTime     = Time.time;
        objectToAdd.JourneyLength = Vector3.Distance(transform.position, objectToAdd.EndPosition);
    }
Example #18
0
        /// <summary>
        /// 执行插入图像命令
        /// </summary>
        public static void InsertImage(this HtmlDocument document, ImageObject image)
        {
            string hspace = (image.HorizontalSpace > 0 ? "hspace=\"" + image.HorizontalSpace + "\" " : string.Empty);
            string vspace = (image.VerticalSpace > 0 ? "vspace=\"" + image.VerticalSpace + "\" " : string.Empty);
            string border = (image.BorderSize > 0 ? "border=\"" + image.BorderSize + "\" " : string.Empty);
            string align  = (image.Alignment != ImageAlignment.Default ? "align=\"" + image.Alignment.Value + "\" " : string.Empty);
            string title  = (string.IsNullOrEmpty(image.TitleText) == false ? "title=\"" + image.TitleText + "\" " : string.Empty);
            string tx     = string.Empty;

            if (string.IsNullOrEmpty(image.LinkUrl))
            {
                tx = string.Format("<img src=\"{0}\" alt=\"{1}\" width=\"{2}\" height=\"{3}\" {4}{5}{6}{7}{8} />",
                                   image.ImageUrl, image.AltText, image.Width, image.Height, title, hspace, vspace, border, align);
            }
            else
            {
                string url = image.ImageUrl.HtmlEncoding();
                tx = string.Format("<a href=\"{0}\"><img src=\"{1}\" alt=\"{2}\" width=\"{3}\" height=\"{4}\" {5}{6}{7}{8}{9} /></a>",
                                   image.LinkUrl, image.ImageUrl, image.AltText, image.Width, image.Height, title, hspace, vspace, border, align);
            }
            document.InsertHTML(tx);
        }
        public void get_lastTest()
        {
            PixelState target = PixelState.getInstance();
            Bitmap     b      = new Bitmap(10, 10);
            Image      img    = (Image)b;

            ImageObject imgObj1 = new ImageObject(img, ImageManipulatorType.Name.INVERT);
            ImageObject imgObj2 = new ImageObject(img, ImageManipulatorType.Name.GRAYSCALE);
            ImageObject imgObj3 = new ImageObject(img, ImageManipulatorType.Name.RGB_RED);

            target.add(imgObj3);
            target.add(imgObj2);
            target.add(imgObj1);

            I_ImageObject img_last = target.get_last();

            Assert.AreEqual(img_last.get_ImageManipulatorType(), imgObj1.get_ImageManipulatorType());

            target.add(imgObj3);
            img_last = target.get_last();
            Assert.AreEqual(img_last.get_ImageManipulatorType(), imgObj3.get_ImageManipulatorType());
        }
        public ActionResult AddImage(ImageObject imageObject, int accomodationId)
        {
            string fileName  = Path.GetFileNameWithoutExtension(imageObject.ImageFile.FileName);
            string extension = Path.GetExtension(imageObject.ImageFile.FileName);

            fileName = fileName + "" + extension;
            imageObject.ImagePath = "~/Content/images/accomodation/" + fileName;
            fileName = Path.Combine(Server.MapPath("~/Content/images/accomodation/"), fileName);
            imageObject.ImageFile.SaveAs(fileName);

            ImageModels image = new ImageModels();

            image.ImagePath = imageObject.ImagePath;
            image.Title     = imageObject.Title;

            var accomodation = sqlDB.Accomodations.Where(a => a.Id == accomodationId).FirstOrDefault();

            image.Accomodation = accomodation;

            sqlDB.Images.Add(image);
            sqlDB.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
Example #21
0
        /// <summary>
        /// Find current section for new Route/Direction
        /// </summary>
        /// <param name="strRoute"></param>
        /// <param name="strDirection"></param>
        /// <param name="imageObject"></param>
        public void UpdateFacilitySection(String strFacility, String strSection, ImageObject imageObject)
        {
            m_listSections = GlobalDatabaseOperations.GetSections(strFacility, this.NetworkID);

            if (imageObject != null)
            {
                //Search this list to find which section
                foreach (SectionObject so in m_listSections)
                {
                    if (imageObject.Section == so.Section)
                    {
                        this.CurrentSection = so;
                    }
                }
            }
            else
            {
                if (m_listSections.Count > 0)
                {
                    this.CurrentSection = m_listSections[0];
                }
            }
        }
Example #22
0
        public override void OnClick(double x, double y, int b)
        {
            FObject a;

            switch (b)
            {
            case 0:
                a = _x.Clone();
                break;

            case 2:
                a = ImageObject.FromFile(@"C:\frice.png", 0, 0, 100, 100);
                break;

            default:
                a = new ShapeObject(ColorResource.DrakGray, new FCircle(50.0), 0, 0);
                break;
            }
            a.SetCentre(x, y);
            a.AddAnims(new SimpleMove(30, -500));
            a.AddAnims(new AccelerateMove(0, 800));
            AddObject(a);
        }
Example #23
0
        /// <summary>
        /// Get the previous image viewed.
        /// </summary>
        /// <returns></returns>
        public System.Drawing.Image GetPreviousImage()
        {
            currentImage = BootedPictures.Current;
            if (BootedPictures.Count > 1)
            {
                while (pictureEnumerator.MovePrevious() && currentImage != null && currentImage.Equals(pictureEnumerator.Current))
                {
                    ;
                }
                BootedPictures.AddNext((Picture)pictureEnumerator.Current);
            }
            return(currentImage.Image);

            /*
             * if (pictureEnumerator.MovePrevious())
             * {
             *  currentImage = BootedPictures.Current;
             *  Picture p = new Picture(BootedPictures.Current.Name);
             *  BootedPictures.AddNext(pictureEnumerator.GetIndex(p, LIMITS));
             *  return currentImage.Image;
             * }
             * return null;*/
        }
Example #24
0
        public JsonResult GetProduct(int id)
        {
            var productBo = m_facade.GetProductById(id);

            if (productBo == null)
            {
                return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
            }

            var imageFileDescription = ImageObject.GetImageLinkById(productBo.Id);
            var product = new
            {
                id             = productBo.Id,
                catalogId      = productBo.CatalogId,
                name           = productBo.Name,
                description    = productBo.Description,
                fileLink       = imageFileDescription.FileLink,
                isDefaultImage = imageFileDescription.IsDefaultImage,
                qty            = ""
            };

            return(Json(product, JsonRequestBehavior.AllowGet));
        }
Example #25
0
        private void Relayout()
        {
            if (m_label == null)
            {
                m_label          = new LabelObject(this, Font, MaskText(m_text, MaskChar), LabelAlign.Start, LabelAlign.Start);
                m_label.Position = TextPadding.TopLeft;
            }
            else
            {
                m_label.Text = MaskText(m_text, MaskChar);
            }

            m_label.Color = TextColor;
            m_label.Scale = FontSize;
            m_label.Alpha = Alpha;

            if (m_cursor == null)
            {
                m_cursor = new ImageObject(this, Font.GetSprites(CursorChar, Vector2.Zero)[0]);
                m_cursor.Sprite.Color     = CursorColor;
                m_cursor.Scale            = FontSize;
                m_cursor.Transform.Parent = Transform;
            }

            /* // Nomad: I'm not sure it is normal to resize text edit depending on it's content. It looks like leftovers from WidgetLabel copy-paste
             * Vector2 minSize = m_label.Size * FontSize + TextPadding.Size;
             * if (minSize.X < Size.X)
             *   minSize.X = Size.X;
             * if (minSize.Y < Size.Y)
             *   minSize.Y = Size.Y;
             *
             * Size = minSize;*/

            m_needLayout = false;

            UpdateCursor(0);
        }
Example #26
0
        /// <summary>
        /// 方法说明:装载图片文件
        /// 作    者:jason.tang
        /// 完成时间:2013-01-22
        /// </summary>
        /// <param name="image">图片对象</param>
        private void LoadImage(ImageObject image, DataGridView datagridview)
        {
            PictureBox pic = new PictureBox();

            pic.SizeMode = PictureBoxSizeMode.StretchImage;
            pic.Name     = Guid.NewGuid().ToString();
            pic.Width    = image.Width;
            pic.Height   = image.Height;

            if (!File.Exists(image.ImagePath))
            {
                //MessageBox.Show(string.Format("图形文件加载失败\r\n请检查路径{0}",image.ImagePath), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //return;
                pic.Image = Properties.Resources.none_img;
            }
            else
            {
                pic.Image         = Image.FromFile(image.ImagePath);
                pic.ImageLocation = image.ImagePath;
            }

            datagridview.Controls.Add(pic);
            pic.Location = new Point(image.LocationX, image.LocationY);
        }
Example #27
0
        public IActionResult identify([FromBody] ImageObject imageObject)
        {
            // Saving Image on Server
            SaveImage(imageObject.Image);

            try
            {
                // Start process and return logs
                String myData = "";
                myData = StartProcess();

                // Delete Image from Server
                DeletFoto();

                return(Content(myData, "application/json"));
            }
            catch (Exception e)
            {
                // Create readable error
                string error = CreateError(e);

                return(Content(error, "application/json"));
            }
        }
        private int[] GetHistogram(ImageObject obj, GrayscaleProcessor p)
        {
            Rectangle boundingBox = obj.Contour.FindBoundingBox();

              int y2 = boundingBox.Bottom;
              int x2 = boundingBox.Right;
              int y1 = boundingBox.Y;
              int x1 = boundingBox.X;

              int[] histogram = new int[256];

              for (int dy = y1; dy < y2; dy++) for (int dx = x1; dx < x2; dx++)
            {
              if (obj.Layer.Map[dx, dy] != obj.Id) continue;

              histogram[p[dx, dy]]++;
            }

              return histogram;
        }
Example #29
0
 public async Task <HttpResponseMessage> Post(Uri uri, ImageObject imageObject)
 {
     return(await httpClient.PostAsJsonAsync(uri, imageObject));
 }
Example #30
0
        public async Task <AnalyzeImageModel> GetImageAnalysisCustomModel(string imageUrl)
        {
            var analyzeImageModel = new AnalyzeImageModel();
            // Creating a list that defines the features to be extracted from the image.

            List <VisualFeatureTypes?> features = new List <VisualFeatureTypes?>()
            {
                VisualFeatureTypes.Categories, VisualFeatureTypes.Description,
                VisualFeatureTypes.Faces, VisualFeatureTypes.ImageType,
                VisualFeatureTypes.Tags, VisualFeatureTypes.Adult,
                VisualFeatureTypes.Color, VisualFeatureTypes.Brands,
                VisualFeatureTypes.Objects
            };
            ImageAnalysis results = await _computerVisionClient.AnalyzeImageAsync(imageUrl, features);

            // </snippet_analyze_call>

            // <snippet_describe>
            // Sunmarizes the image content.
            foreach (var caption in results.Description.Captions)
            {
                var item = new Summary()
                {
                    Name       = caption.Text,
                    Confidence = caption.Confidence
                };
                analyzeImageModel.Summary.Add(item);
            }
            // </snippet_describe>

            // <snippet_categorize>
            // Display categories the image is divided into.
            foreach (var category in results.Categories)
            {
                var item = new Category()
                {
                    Name       = category.Name,
                    Confidence = category.Score
                };
                analyzeImageModel.Categories.Add(item);
            }
            // </snippet_categorize>

            // <snippet_tags>
            // Image tags and their confidence score
            foreach (var tag in results.Tags)
            {
                var item = new Tag()
                {
                    Name       = tag.Name,
                    Confidence = tag.Confidence
                };
                analyzeImageModel.Tags.Add(item);
            }
            // </snippet_tags>

            // <snippet_objects>
            // Objects
            foreach (var obj in results.Objects)
            {
                var item = new ImageObject()
                {
                    Name       = obj.ObjectProperty,
                    Confidence = obj.Confidence,
                    LocationX1 = obj.Rectangle.X,
                    LocationX2 = obj.Rectangle.X + obj.Rectangle.W,
                    LocationY1 = obj.Rectangle.Y,
                    LocationY2 = obj.Rectangle.Y + obj.Rectangle.H
                };
                analyzeImageModel.Objects.Add(item);
            }
            // </snippet_objects>

            // <snippet_faces>
            // Faces
            foreach (var face in results.Faces)
            {
                var item = new Face()
                {
                    Gender     = face.Gender.HasValue ? face.Gender.Value.ToString() : string.Empty,
                    Age        = face.Age,
                    LocationX1 = face.FaceRectangle.Left,
                    LocationX2 = face.FaceRectangle.Left,
                    LocationY1 = face.FaceRectangle.Top + face.FaceRectangle.Width,
                    LocationY2 = face.FaceRectangle.Top + face.FaceRectangle.Height
                };
                analyzeImageModel.Faces.Add(item);
            }
            // </snippet_faces>

            // <snippet_adult>
            // Adult or racy content, if any.
            Console.WriteLine("Adult:");
            if (results.Adult != null)
            {
                var adult = new Adult()
                {
                    IsAdultContent = results.Adult.IsAdultContent,
                    AdultScore     = results.Adult.AdultScore,
                    IsRacyContent  = results.Adult.IsRacyContent,
                    RacyScore      = results.Adult.RacyScore
                };
                analyzeImageModel.Adult = adult;
            }
            // </snippet_adult>

            // <snippet_brands>
            // Well-known (or custom, if set) brands.
            foreach (var brand in results.Brands)
            {
                var item = new Brand()
                {
                    Name       = brand.Name,
                    Confidence = brand.Confidence,
                    LocationX1 = brand.Rectangle.X,
                    LocationX2 = brand.Rectangle.X + brand.Rectangle.W,
                    LocationY1 = brand.Rectangle.Y,
                    LocationY2 = brand.Rectangle.Y + brand.Rectangle.H
                };
                analyzeImageModel.Brands.Add(item);
            }
            // </snippet_brands>

            // <snippet_celebs>
            // Celebrities in image, if any.
            foreach (var category in results.Categories)
            {
                if (category.Detail?.Celebrities != null)
                {
                    foreach (var celeb in category.Detail.Celebrities)
                    {
                        var item = new Celebrity()
                        {
                            Name       = celeb.Name,
                            Confidence = celeb.Confidence,
                            LocationX1 = celeb.FaceRectangle.Left,
                            LocationX2 = celeb.FaceRectangle.Top,
                            LocationY1 = celeb.FaceRectangle.Height,
                            LocationY2 = celeb.FaceRectangle.Width
                        };
                        analyzeImageModel.Celebrities.Add(item);
                    }
                }
            }
            // </snippet_celebs>


            // <snippet_landmarks>
            // Popular landmarks in image, if any.
            foreach (var category in results.Categories)
            {
                if (category.Detail?.Landmarks != null)
                {
                    foreach (var landmark in category.Detail.Landmarks)
                    {
                        var item = new Landmark()
                        {
                            Name       = landmark.Name,
                            Confidence = landmark.Confidence,
                        };
                        analyzeImageModel.Landmarks.Add(item);
                    }
                }
            }
            // </snippet_landmarks>

            // <snippet_color>
            // Identifies the color scheme.
            if (results.Color != null)
            {
                var color = new ImageColor()
                {
                    IsBWImg                 = results.Color.IsBWImg,
                    AccentColor             = results.Color.AccentColor,
                    DominantColorBackground = results.Color.DominantColorBackground,
                    DominantColorForeground = results.Color.DominantColorForeground,
                    DominantColors          = string.Join(",", results.Color.DominantColors)
                };
                analyzeImageModel.Color = color;
            }
            // </snippet_color>

            // <snippet_type>
            // Detects the image types.
            if (results.ImageType != null)
            {
                var imagetype = new Model.ImageType()
                {
                    ClipArtType     = results.ImageType.ClipArtType,
                    LineDrawingType = results.ImageType.LineDrawingType
                };
                analyzeImageModel.ImageType = imagetype;
            }
            // </snippet_type>
            return(analyzeImageModel);
        }
Example #31
0
        void OnListViewItemTapped(object sender, ItemTappedEventArgs e)
        {
            ImageObject tappedItem = e.Item as ImageObject;

            App.Current.MainPage.Navigation.PushAsync(new FullView(tappedItem, localEmail));
        }
Example #32
0
 public HUD(Torch.Scene scene, Torch.Object parent) : base(scene, parent)
 {
     _interactIcon = new ImageObject(Game, this, "HUD/interacticon");
 }
Example #33
0
 private void AddObject(ref string s, long cnt, ImageObject Obj)
 {
     s = s + "Object #" + cnt.ToString();
     s = s + " Pixels:" + Obj.Pixels.ToString() + " Intervals:" + Obj.Intervals.ToString();
     s = s + " Rect:" + Obj.Rectangle.Left.ToString() + ":" + Obj.Rectangle.Top.ToString() + "-" + Obj.Rectangle.Right.ToString() + ":" + Obj.Rectangle.Bottom.ToString();
     s = s + Environment.NewLine;
 }
        private double GetContourGradient(ImageObject obj, GrayscaleProcessor gp)
        {
            int[] nX = { +1, 0, -1, 0 };
              int[] nY = { 0, +1, 0, -1 };

              int height = gp.Height;
              int width = gp.Width;

              double sumInner = 0.0, sumOuter = 0.0;
              double numInner = 0.0, numOuter = 0.0;

              for (int i = 0; i < obj.Contour.Length; i++)
              {
            Point p = obj.Contour[i];

            for (int j = 0; j < 4; j++)
            {
              int x = p.X + nX[j];
              int y = p.Y + nY[j];

              if (x < 0 || y < 0 || x >= width || y >= height) continue;

              if (obj.Contour.Contains(x, y)) continue;

              UInt32 intensity = gp[x, y];

              if (obj.Layer.Map[x, y] == obj.Id)
              {
            sumInner += intensity;
            numInner++;
              }
              else
              {
            sumOuter += intensity;
            numOuter++;
              }
            }
              }

              double meanInner = sumInner / numInner;
              double meanOuter = sumOuter / numOuter;

              return meanInner - meanOuter;
        }