示例#1
0
        /// <summary>
        /// Find the location of the first always black spot
        /// </summary>
        /// <param name="binarPlaces">Five projected probable locations</param>
        /// <param name="original">The source image, where the spots will be searched</param>
        /// <returns>Location on the image and its number</returns>
        private WeightCenter FindBinaryPlace(byte[, ,] original, List <Point3D> binarPlaces)
        {
            int     sumMin = 765; // 255 * 3 - the max sum possible
            int     sum;
            byte    R, G, B;      // b0g1r2
            Point3D pMin            = null;
            int     foundedPosition = 0;

            for (int i = 0; i < 5; i++)
            {
                if ((binarPlaces[i].X < 0) || (binarPlaces[i].Y < 0) ||
                    (binarPlaces[i].X >= original.GetLength(1)) ||
                    (binarPlaces[i].Y >= original.GetLength(0)))
                {
                    return(WeightCenter.Empty);
                }

                R   = original[(int)(binarPlaces[i].Y), (int)(binarPlaces[i].X), 2];
                G   = original[(int)(binarPlaces[i].Y), (int)(binarPlaces[i].X), 1];
                B   = original[(int)(binarPlaces[i].Y), (int)(binarPlaces[i].X), 0];
                sum = R + G + B;
                if (sum < sumMin) // Find the darkest spot
                {
                    foundedPosition = i;
                    sumMin          = sum;
                    pMin            = binarPlaces[i];
                }
            }
            WeightCenter w = new WeightCenter((int)pMin.X, (int)pMin.Y, foundedPosition);

            //Visualization.VisualizeWeightCenter(w, imgOriginal.Data, FrameRows, FrameCols, 100);
            //Visualization.VisualizeWeightCenter(w, imgR.Data, FrameRows, FrameCols);

            return(new WeightCenter((int)pMin.X, (int)pMin.Y, foundedPosition));
        }
示例#2
0
        } // End FindSpots

        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="color"></param>
        /// <returns></returns>
        private static WeightCenter CalculateWeightCenter(byte[, ,] source, int x, int y,
                                                          int width, int height, FilterColors color)
        {
            int sum_x = 0, sum_y = 0, n = 0;

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    if (source[i + y, j + x, (byte)color] == 255)
                    {
                        sum_x += j;
                        sum_y += i;
                        n++;
                    }
                }
            }

            WeightCenter w;

            if (n > 0)
            {
                w = new WeightCenter(
                    x + (int)Math.Round((double)(sum_x / n), 0),
                    y + (int)Math.Round((double)(sum_y / n), 0), y);
            }
            else
            {
                w = WeightCenter.Empty;
            }
            return(w);
        }
示例#3
0
 public bool Equals(WeightCenter w)
 {
     // Return true if the fields match:
     return((this.x == w.x) &&
            (this.x == w.y) &&
            (this.rowStart == w.rowStart));
 }
示例#4
0
        private void RetrieveColorInformation(FilterColors color, byte[,,] original,
                                              WeightCenter colorSpotLocation, Point3D whiteSpotLocation, Point3D blackSpotLocation)
        {
            if (WhiteSpot == Color.Empty)
            {
                WhiteSpot = ImageProcessing.GetColor(
                    original,
                    new WeightCenter((int)whiteSpotLocation.X, (int)whiteSpotLocation.Y, 0), 0);
            }

            if (BlackSpot == Color.Empty)
            {
                BlackSpot = ImageProcessing.GetColor(
                    original,
                    new WeightCenter((int)blackSpotLocation.X, (int)blackSpotLocation.Y, 0), 0);
            }

            Color colorSpot = ImageProcessing.GetColor(original, colorSpotLocation, 0);

            switch (color)
            {
            case FilterColors.B:
                if (BlueSpot == Color.Empty)
                {
                    BlueSpot = colorSpot;
                }
                break;

            case FilterColors.G:
                if (GreenSpot == Color.Empty)
                {
                    GreenSpot = colorSpot;
                }
                break;

            case FilterColors.R:
                if (RedSpot == Color.Empty)
                {
                    RedSpot = colorSpot;
                }
                break;

            case FilterColors.Y:
                if (YellowSpot == Color.Empty)
                {
                    YellowSpot = colorSpot;
                }
                break;

            default:
                break;
            }

            RecalcVectors();
            RotateColorVectors();
        }
示例#5
0
        public static void VisualizeWeightCenter(WeightCenter w, byte[, ,] destination, int FrameRows, int FrameCols, byte colorCross = 255)
        {
            int wx, wy;

            if ((w.x > 0) && (w.y > 0))
            {
                int crossHairSize = 4;

                wx = w.x;
                wy = w.y;

                // Draw white pixels on X and Y axis
                for (int i = (-1 * crossHairSize); i < crossHairSize; i++)
                {
                    // Checks if a white cross is drawn outside the picture
                    if (((wx + i) > (FrameCols - 1)) || ((wy + i) > (FrameRows - 1)))
                    {
                        break;
                    }
                    if (((wx + i) <= 1) || ((wy + i) <= 1))
                    {
                        break;
                    }
                    // pixels are indexed as row -> col, therefore wy and wx are in this order, row = wy, col = wx
                    if ((colorCross > 255) || (colorCross < 0))
                    {
                        colorCross = 255;
                    }
                    if ((wy > FrameRows - 1) || (wy < 0))
                    {
                        break;
                    }
                    if ((wx > FrameCols - 1) || (wx < 0))
                    {
                        break;
                    }
                    destination[wy + i, wx, 2] = destination[wy + i, wx, 1] = destination[wy + i, wx, 0] = colorCross;
                    destination[wy, wx + i, 2] = destination[wy, wx + i, 1] = destination[wy, wx + i, 0] = colorCross;
                }
            }
        }
示例#6
0
        private void zoomPicBox1_MouseClick(object sender, MouseEventArgs e)
        {
            int          x           = zoomPicBox1.CurrentState.OriginalX;
            int          y           = zoomPicBox1.CurrentState.OriginalY;
            WeightCenter coordinates = new WeightCenter(x, y, 0);
            Color        pixelColor  = ImageProcessing.GetColor(imageCopy.Data,
                                                                coordinates, (int)numericUpDownBorderPixels.Value);

            labelPixelColor.Text        = string.Format("{0} {1} {2}", pixelColor.R, pixelColor.G, pixelColor.B);
            textBoxPixelColor.BackColor = pixelColor;
            Vector3D pixelVector = new Vector3D(pixelColor);

            pixelVector.Normalize();
            textBoxPixelColor.Text = pixelVector.ToString();

            if (MouseRecognitionModule.IsInitialized)
            {
                Vector3D redVector, greenVector, blueVector, yellowVector;
                redVector    = MouseRecognitionModule.RedVector;
                greenVector  = MouseRecognitionModule.GreenVector;
                blueVector   = MouseRecognitionModule.BlueVector;
                yellowVector = MouseRecognitionModule.YellowVector;
                Vector3D currentVector = new Vector3D(pixelColor);
                currentVector.Normalize();

                // Distances
                double distance = Geometry.Distance(currentVector, redVector);
                textBoxRDist.Text = distance.ToString();
                distance          = Geometry.Distance(currentVector, greenVector);
                textBoxGDist.Text = distance.ToString();
                distance          = Geometry.Distance(currentVector, blueVector);
                textBoxBDist.Text = distance.ToString();
                distance          = Geometry.Distance(currentVector, yellowVector);
                textBoxYDist.Text = distance.ToString();
            }
        }
示例#7
0
        /// <summary>
        /// Calculate the exact 8 locations of binary code for reading
        /// </summary>
        /// <param name="original">Frame from which will be founded the always first black spot</param>
        /// <param name="sourceBinPars">Orientation parameters of descriptor</param>
        /// <param name="destBinPars">Orientation parameters of projection from camera</param>
        /// <returns>Eight positions of binary code according projection</returns>
        private List <Point3D> CalcBinaryPlaces(byte[, ,] original, Point3D[] sourceBinPars, Point3D[] destBinPars, out WeightCenter binFound)
        {
            List <Point3D> binarPlacesHomography = Geometry.homography_calc(
                new List <Point3D>(dataMouse.binarPlacesBase), sourceBinPars, destBinPars);

            binFound = FindBinaryPlace(original, binarPlacesHomography);
            if (binFound == WeightCenter.Empty)
            {
                return(null);
            }

            List <Point3D> binar8Codes = new List <Point3D>(Geometry.CloneList(dataMouse.binarSpotsSide01));

            // Rotate the 8 binary codes according the founded position
            Geometry.p_rotZ(binar8Codes, dataMouse.SinCosDescriptor[binFound.rowStart], 1);
            binar8Codes = Geometry.homography_calc(binar8Codes, sourceBinPars, destBinPars);

            return(binar8Codes);
        }