Exemplo n.º 1
0
        /// <summary>
        /// Calculate the rotation of an object from image
        /// </summary>
        /// <param name="colorBS"></param>
        /// <param name="currentBlob"></param>
        /// <param name="viBlobs"></param>
        /// <returns>angle degree</returns>
        public static float GetRotation(Image <Bgra, byte> colorBS, BlobObject currentBlob, List <BlobObject> viBlobs)
        {
            Image <Bgra, byte> observedImage = UtilitiesImage.CropImage(colorBS, currentBlob.Rect);
            //observedImage.Save("current.jpg");
            float degree = 360;

            if (viBlobs.Count == 0)
            {
                return(degree);
            }
            else
            {
                VectorOfKeyPoint keypoints1;
                VectorOfKeyPoint keypoints2;
                Matrix <float>   symMatches;
                foreach (BlobObject viblob in viBlobs)
                {
                    //viblob.Image.Save(viblob.Id + ".jpg");
                    bool isDetect = UtilitiesImage.MatchIsSame(viblob.Image, observedImage.Convert <Gray, byte>(), out keypoints1, out keypoints2, out symMatches);

                    if (isDetect)
                    {
                        degree = UtilitiesImage.GetRotationDiff(symMatches, keypoints1, keypoints2);
                    }
                }
                return(degree);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Find an object in a object list
        /// </summary>
        /// <param name="currentBlob"></param>
        /// <param name="viBlobs"></param>
        /// <returns>BlobID</returns>
        public bool RecognizeObject(Image <Gray, byte> sourceImage, Image <Gray, byte> toCompare)
        {
            bool isDetect = false;

            // MFunk: Run this a couple of times to get more robust
            int numRuns = 3;

            for (int i = 0; i < numRuns; i++)
            {
                isDetect = UtilitiesImage.MatchIsSame(toCompare, sourceImage);

                if (isDetect)
                {
                    break;
                }
            }

            // seriously no idea whats happening here but somehow this works
            if (!isDetect)
            {
                isDetect = UtilitiesImage.MatchIsSame(toCompare.Canny(10, 50), sourceImage.Canny(10, 50));
                if (isDetect)
                {
                    isDetect = true;
                }
                else
                {
                }
            }

            return(isDetect);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Find an object in a object list
        /// </summary>
        /// <param name="currentBlob"></param>
        /// <param name="viBlobs"></param>
        /// <returns>BlobID</returns>
        public static string RecognizeObject(BlobObject currentBlob, List <TrackableObject> dbObjects)
        {
            bool   isDetect = false;
            string blobId   = "not identified";

            bool careAboutWorkflow = false;

            if (WorkflowManager.Instance.LoadedWorkflow != null)
            {
                careAboutWorkflow = true;
            }

            if (dbObjects.Count != 0)
            {
                foreach (TrackableObject obj in dbObjects)
                {
                    if (careAboutWorkflow)
                    {
                        // first check if object belongs to current workingstep
                        if (obj.Category == "" + WorkflowManager.Instance.CurrentWorkingStep.StepNumber)
                        {
                            // MFunk: Run this a couple of times to get more robust
                            int numRuns = 3;

                            for (int i = 0; i < numRuns; i++)
                            {
                                isDetect = UtilitiesImage.MatchIsSame(obj.EmguImage, currentBlob.Image);

                                if (isDetect)
                                {
                                    break;
                                }
                            }

                            if (isDetect)
                            {
                                WorkflowManager.Instance.OnObjectRecognized(obj);
                                blobId = obj.Name;
                                break;
                            }
                            else
                            {
                                isDetect = UtilitiesImage.MatchIsSame(obj.EmguImage.Canny(10, 50).Convert <Gray, Int32>(), currentBlob.Image.Canny(10, 50).Convert <Gray, Int32>());
                                if (isDetect)
                                {
                                    isDetect = true;
                                    blobId   = obj.Name;
                                    WorkflowManager.Instance.OnObjectRecognized(obj);
                                    break;
                                }
                                else
                                {
                                    blobId = "not identified";
                                }
                            }

                            if (isDetect)
                            {
                                m_LastWasCorrupted = false;
                            }
                        }
                    }
                    else
                    {
                        // do not care about workflow

                        // MFunk: Run this a couple of times to get more robust
                        int numRuns = 3;

                        for (int i = 0; i < numRuns; i++)
                        {
                            isDetect = UtilitiesImage.MatchIsSame(obj.EmguImage, currentBlob.Image);

                            if (isDetect)
                            {
                                break;
                            }
                        }

                        if (isDetect)
                        {
                            WorkflowManager.Instance.OnObjectRecognized(obj);
                            blobId = obj.Name;
                            break;
                        }
                        else
                        {
                            isDetect = UtilitiesImage.MatchIsSame(obj.EmguImage.Canny(10, 50).Convert <Gray, Int32>(), currentBlob.Image.Canny(10, 50).Convert <Gray, Int32>());
                            if (isDetect)
                            {
                                isDetect = true;
                                blobId   = obj.Name;
                                WorkflowManager.Instance.OnObjectRecognized(obj);
                                break;
                            }
                            else
                            {
                                blobId = "not identified";
                            }
                        }
                    }
                }
            }

            if (isDetect)
            {
                m_LastWasCorrupted = false;
            }
            return(blobId);
        }