示例#1
0
        public IActionResult GetById(int id)
        {
            ImageEvent imageEvent = new ImageEvent();

            if (id > 0)
            {
                imageEvent = _repository.GetById <ImageEvent>(id);
            }

            if (String.IsNullOrEmpty(imageEvent.Name))
            {
                return(BadRequest("Not found"));
            }

            var body   = _repository.GetById <Body>(imageEvent.Id);
            var result = _repository.GetById <Result>(body.Id);
            var size   = _repository.GetById <Size>(result.Id);

            //var detectionBoxes = _repository.List<DetectionBoxes>().Select(d => d.);

            imageEvent.Body             = body;
            imageEvent.Body.Result      = result;
            imageEvent.Body.Result.Size = size;
            //imageEvent.Body.Result.Detection_boxes = detectionBoxes;


            return(Ok(ImageEventDTO.FromImageEvent(imageEvent)));
        }
示例#2
0
 private static void OnImage(Message msg, bool isEdited)
 {
     ImageEvent?.Invoke(new MessageEventArgs()
     {
         msg = msg, isEdited = isEdited
     });
 }
        public IActionResult GetLast(string edgeDevice)
        {
            ImageEvent imageEvent = new ImageEvent();

            var strGetData = _redisDb.GetEvent(edgeDevice);

            if (String.IsNullOrEmpty(strGetData) || String.IsNullOrEmpty(edgeDevice))
            {
                return(BadRequest("No image events were found"));
            }

            ImageEventDTO imageEventDTO = JsonConvert.DeserializeObject <ImageEventDTO>(strGetData);

            imageEvent = ImageEventDTO.ToImageEvent(imageEventDTO);

            //imageEvent = _inMemRepository.GetLast(edgeDevice);

            //if (String.IsNullOrEmpty(imageEvent.Name) || String.IsNullOrEmpty(edgeDevice))
            //{
            //    return BadRequest("Not found");
            //}

            //var body = _inMemRepository.GetById<Body>(imageEvent.Id);
            //var result = _inMemRepository.GetById<Result>(body.Id);
            //var size = _inMemRepository.GetById<Size>(result.Id);
            ////var detectionBoxes = _repository.List<DetectionBoxes>().Select(d => d.);

            //imageEvent.Body = body;
            //imageEvent.Body.Result = result;
            //imageEvent.Body.Result.Size = size;
            //imageEvent.Body.Result.Detection_boxes = detectionBoxes;


            return(Ok(ImageEventDTO.FromImageEvent(imageEvent)));
        }
示例#4
0
        private async void btn_Select(object sender, RoutedEventArgs e)
        {
            ModelItem loadFrom = ModelItem.Parent;
            string    loadFromSelectorString = "";

            while (loadFrom.Parent != null)
            {
                var p = loadFrom.Properties.Where(x => x.Name == "Image").FirstOrDefault();
                if (p != null)
                {
                    loadFromSelectorString = loadFrom.GetValue <string>("Selector");
                    break;
                }
                loadFrom = loadFrom.Parent;
            }
            var Image       = loadFrom.GetValue <string>("Image");
            var stream      = new System.IO.MemoryStream(Convert.FromBase64String(Image));
            var b           = new System.Drawing.Bitmap(stream);
            var Threshold   = loadFrom.GetValue <double>("Threshold");
            var CompareGray = loadFrom.GetValue <bool>("CompareGray");
            var Processname = loadFrom.GetValue <string>("Processname");
            var limit       = loadFrom.GetValue <Rectangle>("Limit");

            if (Threshold < 0.5)
            {
                Threshold = 0.8;
            }

            Interfaces.GenericTools.Minimize();
            System.Threading.Thread.Sleep(100);
            var matches = ImageEvent.waitFor(b, Threshold, Processname, TimeSpan.FromMilliseconds(100), CompareGray, limit);

            if (matches.Count() == 0)
            {
                Interfaces.GenericTools.Restore();
                return;
            }
            var match = matches[0];

            Rectangle rect = Rectangle.Empty;

            using (Interfaces.Overlay.OverlayWindow _overlayWindow = new Interfaces.Overlay.OverlayWindow(true))
            {
                _overlayWindow.BackColor = System.Drawing.Color.Blue;
                _overlayWindow.Visible   = true;
                _overlayWindow.Bounds    = match;
                _overlayWindow.TopMost   = true;
                rect = await getrectangle.GetitAsync();
            }

            ModelItem.Properties["OffsetX"].SetValue(new System.Activities.InArgument <int>(rect.X - match.X));
            ModelItem.Properties["OffsetY"].SetValue(new System.Activities.InArgument <int>(rect.Y - match.Y));
            ModelItem.Properties["Width"].SetValue(new System.Activities.InArgument <int>(rect.Width));
            ModelItem.Properties["Height"].SetValue(new System.Activities.InArgument <int>(rect.Height));
            Interfaces.GenericTools.Restore();
        }
示例#5
0
 // event callback for new images
 private void Camera_FrameReady(object Sender, ImageEvent e)
 {
     // is the workerthread already processing an image? return.. (skip this image)
     if (_workerThreadIsBusy.WaitOne(0))
     {
         return;     // skip frame.
     }
     //create a 'global' ref so the workerthread can access it.
     _myImage = e.Image;
     // signal the workerthread, so it starts processing the current image.
     _workerThreadIsBusy.Set();
 }
示例#6
0
    private IEnumerator ProcessImageRequest(string endpoint, ImageEvent onSuccess)
    {
        using (UnityWebRequest www = UnityWebRequest.GetTexture(imageBaseUri + endpoint + baseArgs, true)) {
            yield return(www.Send());

            //if(www.isNetworkError || www.isHttpError) {
            if (www.isError)
            {
                onError.Invoke(www.error);
            }
            else
            {
                onSuccess.Invoke(DownloadHandlerTexture.GetContent(www));
            }
        }
    }
示例#7
0
        private async Task ExtractPics(string rootHtml, Seedling seedling)
        {
            var imageDiv = Regex.Match(rootHtml, @"<div id=\""thumbs_list\"">.*?<\/div>", RegexOptions.Multiline)
                           .Groups[0]
                           .Value;

            Regex.Matches(imageDiv,
                          @"<a href=""(https:\/\/.*?\.jpg)"".*?src=""(https:\/\/.*?\.jpg)",
                          RegexOptions.Multiline)
            .ForEach(m =>
            {    ///TODO Async
                var img = new ImageEvent
                {
                    Name       = seedling.Name,
                    Bytes      = _httpExtractor.GetBytes(m.Groups[1].Value).Result,
                    ThumbBytes = _httpExtractor.GetBytes(m.Groups[2].Value).Result,
                };
                img.Hash = SHA256.Create().ComputeHash(img.Bytes);
                _bus.Publish(img);
            });
        }
    public void SendEvent(MouseEventArgs e, ImageEvent Evt)
    {
        System.Drawing.Point PNT = PointConverter(e);

        switch (Evt)
        {
        case ImageEvent.MouseClick:
            if (ImageMouseClick != null)
            {
                ImageMouseClick(new MouseEventArgs(e.Button, e.Clicks, PNT.X, PNT.Y, e.Delta));
            }

            break;

        case ImageEvent.MouseDown:
            if (ImageMouseDown != null)
            {
                ImageMouseDown(new MouseEventArgs(e.Button, e.Clicks, PNT.X, PNT.Y, e.Delta));
            }

            break;

        case ImageEvent.MouseMove:
            if (ImageMouseMove != null)
            {
                ImageMouseMove(new MouseEventArgs(e.Button, e.Clicks, PNT.X, PNT.Y, e.Delta));
            }

            break;

        case ImageEvent.MouseUp:
            if (ImageMouseUp != null)
            {
                ImageMouseUp(new MouseEventArgs(e.Button, e.Clicks, PNT.X, PNT.Y, e.Delta));
            }

            break;
        }
    }
示例#9
0
 // Run a GET on an image
 public void GetImage(string endpoint, ImageEvent onSuccess)
 {
     StartCoroutine(ProcessImageRequest(endpoint, onSuccess));
 }
示例#10
0
    void ShowMessage(GameEvent e, Channel MessageChannel)
    {
        GameObject   message;
        ImageEvent   imageEvent   = e as ImageEvent;
        OfflineEvent offlineEvent = e as OfflineEvent;

        if (imageEvent != null)
        {
            //Handle image messages
            //Get the image from the image manager, and figure out whether it's landscape or portrait
            ImageMapping im = ImageManager.instance.GetImage(imageEvent.ImageName);
            if (im == null)
            {
                Debug.LogError("Image " + imageEvent.ImageName + " not found in the ImageManager");
                return;
            }
            if (im.orientation == ImageOrientation.LANDSCAPE)
            {
                message = GameObject.Instantiate(LandscapeImagePrefab, MessageChannel.ContentPanel.transform);
            }
            else
            {
                AkSoundEngine.PostEvent("Picture", gameObject);
                message = GameObject.Instantiate(PortraitImagePrefab, MessageChannel.ContentPanel.transform);
            }
            message.GetComponent <ImageMessageUI>().image.sprite = im.sprite;
            CleanCanvases(MessageChannel);
        }
        else if (offlineEvent != null)
        {
            SetCharacterOffline(offlineEvent.CharacterName);
        }
        else if (e.Channel == "Group")
        {
            message = GameObject.Instantiate(MessageChannel.IncomingMessagePrefab, MessageChannel.ContentPanel.transform);
            //If we're in a group chat, the message has a portrait and a name that needs to be set up.

            Talking T = message.GetComponent <Talking>();
            T.NameText.text = (e.CharacterName + " is typing...");

            MessageUI M           = message.GetComponent <MessageUI>();
            Channel   CharChannel = Channels.Find(x => x.ChannelName == e.CharacterName);
            if (CharChannel != null)
            {
                M.CharacterImage.sprite = CharChannel.Portrait;
                M.BackgroundImage.color = CharChannel.ChatBubbleColor;
            }
            M.MessageText.text = e.Content;
            M.MessageChannel   = MessageChannel;
            M.CharacterName    = e.CharacterName;
            SetCharacterOnline(e.CharacterName);

            if (CurrentlyActiveChannel != e.Channel)
            {
                StartCoroutine(PreFinishAnimation(M));
            }
            else
            {
                BeginAnimation(M);
            }
        }
        else
        {
            message = GameObject.Instantiate(MessageChannel.IncomingMessagePrefab, MessageChannel.ContentPanel.transform);
            Talking T = message.GetComponent <Talking>();
            T.NameText.text = (e.CharacterName + " is typing...");

            MessageUI M = message.GetComponent <MessageUI>();
            //Single messages don't have to worry about the name or portrait either, just the text content
            M.MessageText.text = e.Content;
            M.MessageChannel   = MessageChannel;
            M.CharacterName    = e.CharacterName;
            SetCharacterOnline(e.CharacterName);
            M.BackgroundImage.color = MessageChannel.ChatBubbleColor;
            if (CurrentlyActiveChannel != e.Channel)
            {
                StartCoroutine(PreFinishAnimation(M));
            }
            else
            {
                BeginAnimation(M);
            }
        }
    }
示例#11
0
 public ImageEventEntityEvent(ImageEvent item)
 {
     // For future functionality
 }
示例#12
0
    //Here we figure out who is saying this line, when, and how long we should wait before the next one
    void ParseLine(string line, List <string> tags, List <string> globalTags)
    {
        string characterName      = "";
        string timeString         = "";
        string contentString      = "";
        string channel            = "";
        float  delayTimeInSeconds = 0.0f;
        string absoluteTimeStamp  = "";
        bool   shouldWait         = false;

        //The global tags determine the channel we're part of
        if (globalTags != null && globalTags.Count > 0)
        {
            channel = globalTags[0];
        }
        else
        {
            Debug.LogError("This ink file isn't tagged with a global channel identifier!");
        }
        //Separate out the character/time info from the text content
        //TODO: pick another character for this, or parse correctly to avoid the : in time strings
        string[] subStrings = line.Split(';');
        //If there was a section at the beginning that means we have meta display info (this might not exist for character chats, we'll see)
        if (subStrings.Length > 1)
        {
            string metaInfo = subStrings[0];
            //Now we separate out the meta info into character name and display time
            string[] metaArray = metaInfo.Split('@');
            if (metaArray.Length > 1)
            {
                characterName = metaArray[0];
                timeString    = metaArray[1];
            }
            else
            {
                //Maybe here we have the ability to only include a timestamp, for character-specific chats?
                characterName = subStrings[0];
            }
            contentString = subStrings[1];


            //Debug.Log("ParseString found - Name: " + characterName + " Time: " + timeString + " Content: " + contentString+" Channel: "+channel);

            foreach (string Tag in tags)
            {
                string[] tagpieces = Tag.Split('=');
                if (tagpieces.Length == 2)
                {
                    switch (tagpieces[0])
                    {
                    case "delay":
                        if (float.TryParse(tagpieces[1], out delayTimeInSeconds))
                        {
                            //Yay everything worked OK
                            Debug.Log("Got a delay value of " + delayTimeInSeconds + " from a tag.");
                        }
                        else
                        {
                            Debug.LogError("Found a 'delay' value in the tag " + Tag + " but it had an invalid timing value " + tagpieces[1] + "!");
                        }
                        break;

                    case "time":

                        absoluteTimeStamp = tagpieces[1];
                        break;
                    }
                }
                else if (tagpieces.Length == 1)
                {
                    switch (tagpieces[0])
                    {
                    case "wait":
                        shouldWait = true;
                        break;
                    }
                }
            }

            if (contentString.StartsWith("<") && !contentString.Contains("sprite"))
            {
                //This is an image message, not a normal message


                ImageEvent imageEvent = new ImageEvent();
                imageEvent.Content       = contentString;
                imageEvent.DisplayTime   = timeString;
                imageEvent.CharacterName = characterName;


                imageEvent.Channel               = channel;
                imageEvent.ShouldWaitAfter       = shouldWait;
                imageEvent.AbsoluteTimeString    = absoluteTimeStamp;
                imageEvent.GameTimeToBeActivated = ParseAbsoluteTimestamp(absoluteTimeStamp);

                int StartIndex = 0;
                StartIndex = contentString.IndexOf("<", StartIndex);
                string ImageName = contentString.Substring(StartIndex + 1, contentString.Length - 2);

                imageEvent.ImageName = ImageName;

                //Debug.Log("Calculated game time active to be " + imageEvent.GameTimeToBeActivated);
                TimelineManager.instance.AddEventToQueue(imageEvent);
                CurrentTimeClocks[channel] = imageEvent.GameTimeToBeActivated;
            }
            else if (contentString.StartsWith("[") && contentString.Contains("offline"))
            {
                //This is an offline message, not a normal message


                OfflineEvent offlineEvent = new OfflineEvent();
                offlineEvent.Content       = contentString;
                offlineEvent.DisplayTime   = timeString;
                offlineEvent.CharacterName = characterName;


                offlineEvent.Channel               = channel;
                offlineEvent.ShouldWaitAfter       = shouldWait;
                offlineEvent.AbsoluteTimeString    = absoluteTimeStamp;
                offlineEvent.GameTimeToBeActivated = ParseAbsoluteTimestamp(absoluteTimeStamp);
                offlineEvent.offline               = true;

                //Debug.Log("Calculated game time active to be " + imageEvent.GameTimeToBeActivated);
                TimelineManager.instance.AddEventToQueue(offlineEvent);
                CurrentTimeClocks[channel] = offlineEvent.GameTimeToBeActivated;
            }
            else
            {
                GameEvent gameEvent = new GameEvent();
                gameEvent.Content       = contentString;
                gameEvent.DisplayTime   = timeString;
                gameEvent.CharacterName = characterName;


                gameEvent.Channel               = channel;
                gameEvent.ShouldWaitAfter       = shouldWait;
                gameEvent.AbsoluteTimeString    = absoluteTimeStamp;
                gameEvent.GameTimeToBeActivated = ParseAbsoluteTimestamp(absoluteTimeStamp);

                Debug.Log("Calculated game time active to be " + gameEvent.GameTimeToBeActivated + " Current time: " + TimelineManager.instance.GetCurrentTime());
                TimelineManager.instance.AddEventToQueue(gameEvent);
                CurrentTimeClocks[channel] = gameEvent.GameTimeToBeActivated;
            }
        }
        else
        {
            //This line wasn't constructed appropriately, let's log an error
            Debug.LogError("String " + line + " in channel " + channel + " has no meta information (character name and in-game timestamp).");
        }
    }
示例#13
0
 public void TrigerImageEvent(object sender, ImageEventArgs e)
 {
     ImageEvent?.Invoke(sender, e);
 }
示例#14
0
        public static ImageEventDTO FromImageEvent(ImageEvent item)
        {
            ImageEventDTO imageEventDTO = new ImageEventDTO
            {
                Id             = item.Id,
                Name           = item.Name,
                EdgeDeviceName = item.EdgeDeviceName,
                CaptureTime    = item.CaptureTime,
                Source         = item.Source,
                TimeRecieved   = DateTimeOffset.Now,
                TimeSent       = DateTimeOffset.MinValue,
                Type           = item.Type,
                Body           = new BodyDTO
                {
                    Dest_img  = item.Body.Dest_img,
                    MessageId = item.Body.MessageId,
                    ModuleId  = item.Body.ModuleId,
                    Src_img   = item.Body.Src_img,
                    Result    = new ResultDTO
                    {
                        Detection_boxes   = new List <DetectionBoxesDTO>(),
                        Detection_classes = new List <DetectionClassDTO>(),
                        Detection_scores  = new List <DetectionScoreDTO>(),
                        Size           = new SizeDTO(),
                        Num_detections = item.Body.Result.Num_detections
                    }
                }
            };

            foreach (var i in item.Body.Result.Detection_boxes)
            {
                var detectionBoxes = new DetectionBoxesDTO();
                foreach (var b in i.Detection_boxes)
                {
                    detectionBoxes.Detection_boxes.Add(new DetectionBoxDTO
                    {
                        Detection_box = b.Detection_box
                    });
                }

                imageEventDTO.Body.Result.Detection_boxes.Add(detectionBoxes);
            }

            foreach (var i in item.Body.Result.Detection_classes)
            {
                imageEventDTO.Body.Result.Detection_classes.Add(new DetectionClassDTO
                {
                    Detection_class = i.Detection_class
                });
            }

            foreach (var i in item.Body.Result.Detection_scores)
            {
                imageEventDTO.Body.Result.Detection_scores.Add(new DetectionScoreDTO
                {
                    Detection_score = i.Detection_score
                });
            }

            return(imageEventDTO);
        }
示例#15
0
        public static ImageEvent ToImageEvent(ImageEventDTO item)
        {
            var imageEvent = new ImageEvent
            {
                CaptureTime    = item.CaptureTime,
                EdgeDeviceName = item.EdgeDeviceName,
                Source         = item.Source,
                TimeRecieved   = DateTimeOffset.Now,
                Type           = item.Type,
                Name           = item.Name,
                Body           = new Body
                {
                    Dest_img  = item.Body.Dest_img,
                    MessageId = item.Body.MessageId,
                    ModuleId  = item.Body.ModuleId,
                    Src_img   = item.Body.Src_img,
                    Result    = new Result
                    {
                        Num_detections    = item.Body.Result.Num_detections,
                        Detection_boxes   = new List <DetectionBoxes>(),
                        Detection_classes = new List <DetectionClass>(),
                        Detection_scores  = new List <DetectionScore>(),
                        Size = new Size
                        {
                            Height = item.Body.Result.Size.Height,
                            Width  = item.Body.Result.Size.Width
                        }
                    }
                }
            };

            foreach (var i in item.Body.Result.Detection_boxes)
            {
                var detectionBoxesItem = new DetectionBoxes();
                foreach (var b in i.Detection_boxes)
                {
                    detectionBoxesItem.Detection_boxes.Add(new DetectionBox
                    {
                        Detection_box = b.Detection_box
                    });
                }
                imageEvent.Body.Result.Detection_boxes.Add(detectionBoxesItem);
            }

            foreach (var i in item.Body.Result.Detection_classes)
            {
                imageEvent.Body.Result.Detection_classes.Add(new DetectionClass
                {
                    Detection_class = i.Detection_class
                });
            }

            foreach (var i in item.Body.Result.Detection_scores)
            {
                imageEvent.Body.Result.Detection_scores.Add(new DetectionScore
                {
                    Detection_score = i.Detection_score
                });
            }

            return(imageEvent);
        }