public static Cube AnalyseCube(List<ColorFilter> filters, int faceletMinWidth, int faceletMinHeight)
        {
            /*
            1- Get all images from Arduino
            2- Open a thread to each face and call ImageAnalyser.AnalyseImageSample()
            3- Wait all 6 threads
            4- Sort the positions of the facelets to the 6 faces
            5- Create the string of original cube
            6- Create new cube
             */
            Cube newCube = new Cube();

            const int nFaces = 6;
            ManualResetEvent[] doneEvents = new ManualResetEvent[nFaces];
            ImageSample imgSmp = new ImageSample();
            imgSmp.FaceletMinWidth = faceletMinWidth;
            imgSmp.FaceletMinHeight = faceletMinHeight;
            List<ImageAnalyser> analysers = new List<ImageAnalyser>();
            for (int i = 0; i < nFaces; i++)
            {
                doneEvents[i] = new ManualResetEvent(false);
                ImageAnalyser imgAn = new ImageAnalyser();
                imgAn.Filters = filters;
                imgSmp.FaceNumber = i;
                /*
                 * Aqui, deve ser colocado o trecho de código
                 * em que é pedi ao arduino que faça os movimentos
                 * para posicionar a face desejada para a câmera.
                 * Ao final, não esquecer de setar a propriedade Sample, do objeto imgSmp
                    Ex.: imgSmp.Sample = image;
                 */
                imgAn.Sample = imgSmp.Clone();
                analysers.Add(imgAn);
                ThreadPool.QueueUserWorkItem(imgAn.AnalyseImageSample, i);
            }
            WaitHandle.WaitAll(doneEvents);

            return newCube;
        }
Example #2
0
 /// <summary>
 /// Finds the objects of the image
 /// </summary>
 /// <param name="image">The image to look for objects</param>
 /// <param name="filter">The filter with the minHeight and minWidth</param>
 private void FindObjectsOfImage(Image image, ColorFilter filter)
 {
     ImageAnalyser analyser = new ImageAnalyser();
     Graphics g = Graphics.FromImage(picbVideoCapture.Image);
     List<Rectangle> blocks = analyser.GetSquares(CubeAnalyser.SourceImage, (int)numMinWidth.Value, (int)numMinHeight.Value);
     FindObjectsOfImage(image, filter, blocks, g, analyser);
 }
Example #3
0
 /// <summary>
 /// Find the objects in the image.
 /// </summary>
 /// <param name="image">The image to search for objects</param>
 /// <param name="filter">The filter with color</param>
 /// <param name="g">The Graphics to draw the rectangles</param>
 /// <param name="analyser">The ImageAnalyser to analysis the image</param>
 private void FindObjectsOfImage(Image image, ColorFilter filter, List<Rectangle> blocksFace, Graphics g, ImageAnalyser analyser)
 {
     Pen p = new Pen(filter.BorderColor, 3.0F);
     foreach (Rectangle item in analyser.GetObjectsCoordinates(image, filter))
     {
         VisualCubeBlock newFacelet = new VisualCubeBlock();
         newFacelet.Color = ColorTranslate.getFaceColorByColor(p.Color);
         Rectangle coord = new Rectangle();
         if (HasParentBlock(blocksFace, item, out coord))
         {
             newFacelet.Rectangle = coord;
             this.CurrentFace.AddBlock(newFacelet.Clone(), true);
             g.DrawRectangle(p, coord);
         }
         newFacelet.Dispose();
     }
 }
Example #4
0
 /// <summary>
 /// Find all objects in image.
 /// </summary>
 private void FindObjectsOfAllImages()
 {
     if (CubeAnalyser.SourceImage != null)
     {
         this.CurrentFace.ClearBlocks();
         ImageAnalyser analyser = new ImageAnalyser();
         picbVideoCapture.Image = (Image)CubeAnalyser.SourceImage.Clone();
         Graphics g = Graphics.FromImage(picbVideoCapture.Image);
         List<Rectangle> blocks = analyser.GetSquares(CubeAnalyser.SourceImage, (int)numMinWidth.Value, (int)numMinHeight.Value);
         //Color1
         FindObjectsOfImage(picbRedFilter.Image, StoredData.GetFilter(picbRedFilter.Name), blocks, g, analyser);
         //Color2
         FindObjectsOfImage(picbBlueFilter.Image, StoredData.GetFilter(picbBlueFilter.Name), blocks, g, analyser);
         //Color3
         FindObjectsOfImage(picbGreenFilter.Image, StoredData.GetFilter(picbGreenFilter.Name), blocks, g, analyser);
         //Color4
         FindObjectsOfImage(picbYellowFilter.Image, StoredData.GetFilter(picbYellowFilter.Name), blocks, g, analyser);
         //Color5
         FindObjectsOfImage(picbOrangeFilter.Image, StoredData.GetFilter(picbOrangeFilter.Name), blocks, g, analyser);
         //Color6
         FindObjectsOfImage(picbWhiteFilter.Image, StoredData.GetFilter(picbWhiteFilter.Name), blocks, g, analyser);
     }
 }
Example #5
0
 /// <summary>
 /// Filter especific image.
 /// </summary>
 /// <param name="picBox">Picturebox to show the filtered image</param>
 private void FilterImage(PictureBox picBox)
 {
     if (picbVideoCapture.Image != null)
     {
         ImageAnalyser analyser = new ImageAnalyser();
         picBox.Image = analyser.ApplyColorFilter(StoredData.GetFilter(picBox.Name), CubeAnalyser.SourceImage);
     }
 }
Example #6
0
 /// <summary>
 /// Filter all images
 /// </summary>
 private void FilterAllImages()
 {
     if (picbVideoCapture.Image != null)
     {
         ImageAnalyser analyser = new ImageAnalyser();
         //Color 1;
         picbRedFilter.Image = analyser.ApplyColorFilter(StoredData.GetFilter(picbRedFilter.Name), CubeAnalyser.SourceImage);
         //Color 2;
         picbBlueFilter.Image = analyser.ApplyColorFilter(StoredData.GetFilter(picbBlueFilter.Name), CubeAnalyser.SourceImage);
         //Color 3;
         picbGreenFilter.Image = analyser.ApplyColorFilter(StoredData.GetFilter(picbGreenFilter.Name), CubeAnalyser.SourceImage);
         //Color 4;
         picbYellowFilter.Image = analyser.ApplyColorFilter(StoredData.GetFilter(picbYellowFilter.Name), CubeAnalyser.SourceImage);
         //Color 5;
         picbOrangeFilter.Image = analyser.ApplyColorFilter(StoredData.GetFilter(picbOrangeFilter.Name), CubeAnalyser.SourceImage);
         //Color 6;
         picbWhiteFilter.Image = analyser.ApplyColorFilter(StoredData.GetFilter(picbWhiteFilter.Name), CubeAnalyser.SourceImage);
         FindObjectsOfAllImages();
     }
 }
        public static Cube AnalyseCube(List<ColorFilter> filters, int faceletMinWidth, int faceletMinHeight, ArduinoChannel channel)
        {
            /*
              1- Get all images from Arduino
              2- Open a thread to each face and call ImageAnalyser.AnalyseImageSample()
              3- Wait all 6 threads
              4- Sort the positions of the facelets to the 6 faces
              5- Create the string of original cube
              6- Create new cube
               */
            if (channel == null)
            {
                return null;
            }

            // inicializa visão do Arduino
            channel.SendInitVision();

            Cube newCube = new Cube();

            const int nFaces = 6;
            ManualResetEvent[] doneEvents = new ManualResetEvent[nFaces];
            ImageSample imgSmp = new ImageSample();
            imgSmp.FaceletMinWidth = faceletMinWidth;
            imgSmp.FaceletMinHeight = faceletMinHeight;
            List<ImageAnalyser> analysers = new List<ImageAnalyser>();
            for (int i = 0; i < nFaces; i++)
            {
                doneEvents[i] = new ManualResetEvent(false);
                ImageAnalyser imgAn = new ImageAnalyser();
                imgAn.Filters = filters;
                imgSmp.FaceNumber = i;

                PositioningFace(channel, i+1);
                imgSmp.SampleImg = CubeAnalyser.SourceImage;

                imgAn.Sample = imgSmp.Clone();
                analysers.Add(imgAn);
                ThreadPool.QueueUserWorkItem(imgAn.AnalyseImageSample, doneEvents[i]);
            }
            foreach (ManualResetEvent item in doneEvents)
            {
                WaitHandle hdl = (WaitHandle)item;
                hdl.WaitOne();
            }

            int[] faces;
            Dictionary<CubeFace, CubeFaceType> cubeMap = new Dictionary<CubeFace, CubeFaceType>();
            for (int i = 0; i < nFaces; i++)
            {
                Dictionary<CubeFaceletType, CubeFaceColor> tmpFacelets = new Dictionary<CubeFaceletType, CubeFaceColor>();
                faces = SortFacelets((CubeFaceType)i);
                for (int j = 0; j < 9; j++)
                {
                    tmpFacelets.Add((CubeFaceletType)faces[j], GetCubeFaceColor(analysers[i].Sample.Cores[j]));
                }
                cubeMap.Add(new CubeFace(tmpFacelets), (CubeFaceType)i);
            }
            newCube = new Cube(cubeMap);
            return newCube;
        }