示例#1
0
        public List <PointF> Process(LockBitmap before, Bitmap after, LockBitmap debuggingImage)
        {
            LockBitmap    a   = new LockBitmap(after);
            List <PointF> ret = SubProcess(before, a, debuggingImage, m_laserMagnitudeThreshold);

            a.UnlockBits();
            return(ret);
        }
示例#2
0
        /// <summary>
        /// Set the row color of a Bitmap
        /// </summary>
        /// <param name="image"></param>
        /// <param name="y"></param>
        /// <param name="colors"></param>
        public static void SetRowColors(this Bitmap image, int y, Color[] colors)
        {
            LockBitmap lbmp = new LockBitmap(image);

            for (int x = 0; x < colors.Length; x++)
            {
                lbmp.SetPixel(x, y, colors[x]);
            }
            lbmp.UnlockBits();
        }
示例#3
0
		/// <summary>
		/// Overlay Pixel Location to a bitmap
		/// </summary>
		/// <param name="image"></param>
		/// <param name="pixels"></param>
        public static void OverlayPixels(this Bitmap image, List<PointF> pixels)
		{
			LockBitmap lbmp = new LockBitmap(image);
			for (int iPx = 0; iPx < pixels.Count; iPx++)
			{
				int x = (int)(pixels[iPx].X);
				int y = (int)(pixels[iPx].Y);
				lbmp.SetPixel(x, y, Color.Red);
			}
			lbmp.UnlockBits();
		}
示例#4
0
        /// <summary>
        /// Overlay Pixel Location to a bitmap
        /// </summary>
        /// <param name="image"></param>
        /// <param name="pixels"></param>
        public static void OverlayPixels(this Bitmap image, List <PointF> pixels)
        {
            LockBitmap lbmp = new LockBitmap(image);

            for (int iPx = 0; iPx < pixels.Count; iPx++)
            {
                int x = (int)(pixels[iPx].X);
                int y = (int)(pixels[iPx].Y);
                lbmp.SetPixel(x, y, Color.Red);
            }
            lbmp.UnlockBits();
        }
示例#5
0
        /**
         * Detects the laser in x, y pixel coordinates.
         * @param debuggingImage - If non-NULL, it will be populated with the processed image that was used to detect the laser locations.
         *     This can be helpful when debugging laser detection issues.
         * @param laserLocations - Output variable to store the laser locations.
         * @param maxNumLocations - The maximum number of locations to store in @p laserLocations.
         * @param thresholdFactor - Scales the laser threshold by this amount.  default = 1.0
         * @return Returns the number of locations written to @p laserLocations.
         */
        public List <PointF> Process(Bitmap before, Bitmap after, Bitmap debuggingImage)
        {
            LockBitmap    b   = new LockBitmap(before);
            LockBitmap    d   = debuggingImage != null ? new LockBitmap(debuggingImage) : null;
            List <PointF> ret = Process(b, after, d);

            b.UnlockBits();
            if (d != null)
            {
                d.UnlockBits();
            }

            return(ret);
        }
示例#6
0
        /// <summary>
        /// Get All the pixels of a Bitmap
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public static List <List <Color> > GetPixels(this Bitmap image)
        {
            LockBitmap           lbmp = new LockBitmap(image);
            List <List <Color> > ret  = new List <List <Color> >(lbmp.Height);

            for (int y = 0; y < lbmp.Height; y++)
            {
                List <Color> line = new List <Color>(lbmp.Width);
                for (int x = 0; x < lbmp.Width; x++)
                {
                    line.Add(lbmp.GetPixel(x, y));
                }
                ret.Add(line);
            }
            lbmp.UnlockBits();
            return(ret);
        }
示例#7
0
        private List <PointF> SubProcess(LockBitmap before, LockBitmap after, LockBitmap debuggingImage,
                                         double laserThreshold)
        {
            int           firstRowLaserCol = before.Width / 2;
            List <PointF> laserLocations   = new List <PointF>(before.Height);


            int left_Clip   = 0;
            int top_Clip    = 0;
            int right_Clip  = left_Clip + before.Width;
            int bottom_Clip = top_Clip + before.Height;

            int width   = before.Width;
            int height  = before.Height;
            int rowStep = width;

            int numLocations = 0;

            int numMerged = 0;

            // The location that we last detected a laser line
            int prevLaserCol = firstRowLaserCol;


            /** The LaserRanges for each column */
            LaserRange[] laserRanges = new LaserRange[before.Height + 1];

            double[] magSquare = new double[before.Width];

            //            for (int y = 0; y < height && numLocations < height; y++)
            for (int y = top_Clip; y < bottom_Clip && numLocations < height; y++)
            {
                // The column that the laser started and ended on
                int numLaserRanges = 0;
                laserRanges[numLaserRanges].startCol = -1;
                laserRanges[numLaserRanges].endCol   = -1;

                //		        for (int  x = 0; x < rowStep; x += 1)
                /**/
                for (int x = left_Clip; x < right_Clip; x += 1)
                {
                    /**/
                    // Perform image subtraction
                    int r     = before.GetRed(x, y) - after.GetRed(x, y);
                    int magSq = r * r;
                    magSquare[x] = magSq;
                    byte mag = (byte)(255.0f * (magSq * 0.000015379f));
                    if (debuggingImage != null)
                    {
                        if (mag > laserThreshold)
                        {
                            debuggingImage.SetPixel(x, y, Color.FromArgb(255, mag, mag, mag));
                        }
                        else if (magSq > 0)
                        {
                            debuggingImage.SetPixel(x, y, Color.FromArgb(255, mag, mag, 0));
                        }
                        else
                        {
                            debuggingImage.SetPixel(x, y, Color.Black);
                        }
                    }

                    // Compare it against the threshold
                    if (mag > laserThreshold)
                    {
                        // The start of pixels with laser in them
                        if (laserRanges[numLaserRanges].startCol == -1)
                        {
                            laserRanges[numLaserRanges].startCol = x;
                        }
                    }
                    // The end of pixels with laser in them
                    else if (laserRanges[numLaserRanges].startCol != -1)
                    {
                        int laserWidth = x - laserRanges[numLaserRanges].startCol;
                        if (laserWidth <= m_maxLaserWidth && laserWidth >= m_minLaserWidth)
                        {
                            // If this range was real close to the previous one, merge them instead of creating a new one
                            bool wasMerged = false;
                            if (numLaserRanges > 0)
                            {
                                int rangeDistance = laserRanges[numLaserRanges].startCol - laserRanges[numLaserRanges - 1].endCol;
                                if (rangeDistance < RANGE_DISTANCE_THRESHOLD)
                                {
                                    laserRanges[numLaserRanges - 1].endCol    = x;
                                    laserRanges[numLaserRanges - 1].centerCol = (laserRanges[numLaserRanges - 1].startCol + laserRanges[numLaserRanges - 1].endCol) / 2;
                                    wasMerged = true;
                                    numMerged++;
                                }
                            }

                            // Proceed to the next laser range
                            if (!wasMerged)
                            {
                                // Add this range as a candidate
                                laserRanges[numLaserRanges].endCol    = x;
                                laserRanges[numLaserRanges].centerCol = (laserRanges[numLaserRanges].startCol + laserRanges[numLaserRanges].endCol) / 2;

                                numLaserRanges++;
                            }

                            // Reinitialize the range
                            laserRanges[numLaserRanges].startCol = -1;
                            laserRanges[numLaserRanges].endCol   = -1;
                        }
                        // There was a false positive
                        else
                        {
                            laserRanges[numLaserRanges].startCol = -1;
                        }
                    }
                }                 // foreach column


                // If we have a valid laser region
                if (numLaserRanges > 0)
                {
                    int rangeChoice = DetectBestLaserRange(laserRanges, numLaserRanges, prevLaserCol);
                    prevLaserCol = laserRanges[rangeChoice].centerCol;

                    double centerCol = DetectLaserRangeCenter(laserRanges[rangeChoice], magSquare);

                    PointF location = new PointF((float)centerCol, y);
                    laserLocations.Add(location);

                    // If this is the first row that a laser is detected in, set the firstRowLaserCol member
                    if (laserLocations.Count == 1)
                    {
                        firstRowLaserCol = laserRanges[rangeChoice].startCol;
                    }
                }
            }             // foreach row
示例#8
0
		/// <summary>
		/// Get All the pixels of a Bitmap
		/// </summary>
		/// <param name="image"></param>
		/// <returns></returns>
		public static List<List<Color>> GetPixels(this Bitmap image)
		{
			LockBitmap lbmp = new LockBitmap(image);
			List<List<Color>> ret = new List<List<Color>>(lbmp.Height);
			for (int y = 0; y < lbmp.Height; y++)
			{
				List<Color> line = new List<Color>(lbmp.Width);
				for (int x = 0; x < lbmp.Width; x++)
					line.Add(lbmp.GetPixel(x, y));
				ret.Add(line);
			}
			lbmp.UnlockBits();
			return ret;
		}
示例#9
0
		/// <summary>
		/// Set the row color of a Bitmap
		/// </summary>
		/// <param name="image"></param>
		/// <param name="y"></param>
		/// <param name="colors"></param>
		public static void SetRowColors(this Bitmap image, int y, Color[] colors)
		{
			LockBitmap lbmp = new LockBitmap(image);
			for (int x = 0; x < colors.Length; x++)
				lbmp.SetPixel(x, y, colors[x]);
			lbmp.UnlockBits();
		}
示例#10
0
		private List<PointF> SubProcess(LockBitmap before, LockBitmap after, LockBitmap debuggingImage,
				 double laserThreshold)
		{
			int firstRowLaserCol = before.Width / 2;
            List<PointF> laserLocations = new List<PointF>(before.Height);


			int left_Clip = 0;
			int top_Clip = 0;
			int right_Clip = left_Clip + before.Width;
			int bottom_Clip = top_Clip + before.Height;

			int width = before.Width;
			int height = before.Height;
			int rowStep = width;

			int numLocations = 0;

			int numMerged = 0;

			// The location that we last detected a laser line
			int prevLaserCol = firstRowLaserCol;


			/** The LaserRanges for each column */
			LaserRange[] laserRanges = new LaserRange[before.Height + 1];

			double[] magSquare = new double[before.Width];

			//            for (int y = 0; y < height && numLocations < height; y++)
			for (int y = top_Clip; y < bottom_Clip && numLocations < height; y++)
			{

				// The column that the laser started and ended on
				int numLaserRanges = 0;
				laserRanges[numLaserRanges].startCol = -1;
				laserRanges[numLaserRanges].endCol = -1;

				//		        for (int  x = 0; x < rowStep; x += 1)
				/**/
				for (int x = left_Clip; x < right_Clip; x += 1)
				{
					/**/
					// Perform image subtraction
					int r = before.GetRed(x, y) - after.GetRed(x, y);
					int magSq = r * r;
					magSquare[x] = magSq;
					byte mag = (byte)(255.0f * (magSq * 0.000015379f));
					if (debuggingImage != null)
					{
						if (mag > laserThreshold)
							debuggingImage.SetPixel(x,y, Color.FromArgb(255, mag, mag, mag));
						else if (magSq > 0)
							debuggingImage.SetPixel(x,y, Color.FromArgb(255, mag, mag, 0));
						else
							debuggingImage.SetPixel(x,y, Color.Black);
					}

					// Compare it against the threshold
					if (mag > laserThreshold)
					{
						// The start of pixels with laser in them
						if (laserRanges[numLaserRanges].startCol == -1)
						{
							laserRanges[numLaserRanges].startCol = x;
						}

					}
					// The end of pixels with laser in them
					else if (laserRanges[numLaserRanges].startCol != -1)
					{
						int laserWidth = x - laserRanges[numLaserRanges].startCol;
						if (laserWidth <= m_maxLaserWidth && laserWidth >= m_minLaserWidth)
						{
							// If this range was real close to the previous one, merge them instead of creating a new one
							bool wasMerged = false;
							if (numLaserRanges > 0)
							{
								int rangeDistance = laserRanges[numLaserRanges].startCol - laserRanges[numLaserRanges - 1].endCol;
								if (rangeDistance < RANGE_DISTANCE_THRESHOLD)
								{
									laserRanges[numLaserRanges - 1].endCol = x;
									laserRanges[numLaserRanges - 1].centerCol =(laserRanges[numLaserRanges - 1].startCol + laserRanges[numLaserRanges - 1].endCol) / 2;
									wasMerged = true;
									numMerged++;
								}
							}

							// Proceed to the next laser range
							if (!wasMerged)
							{
								// Add this range as a candidate
								laserRanges[numLaserRanges].endCol = x;
								laserRanges[numLaserRanges].centerCol = (laserRanges[numLaserRanges].startCol + laserRanges[numLaserRanges].endCol) / 2;

								numLaserRanges++;
							}

							// Reinitialize the range
							laserRanges[numLaserRanges].startCol = -1;
							laserRanges[numLaserRanges].endCol = -1;
						}
						// There was a false positive
						else
						{
							laserRanges[numLaserRanges].startCol = -1;
						}
					}
				} // foreach column


				// If we have a valid laser region
				if (numLaserRanges > 0)
				{
					int rangeChoice = DetectBestLaserRange(laserRanges, numLaserRanges, prevLaserCol);
					prevLaserCol = laserRanges[rangeChoice].centerCol;

					double centerCol = DetectLaserRangeCenter(laserRanges[rangeChoice],magSquare);

                    PointF location = new PointF((float)centerCol, y);
					laserLocations.Add(location);

					// If this is the first row that a laser is detected in, set the firstRowLaserCol member
					if (laserLocations.Count == 1)
					{
						firstRowLaserCol = laserRanges[rangeChoice].startCol;
					}

				}
			} // foreach row
示例#11
0
        public List<PointF> Process(LockBitmap before, Bitmap after, LockBitmap debuggingImage)
		{

			LockBitmap a = new LockBitmap(after);
            List<PointF> ret = SubProcess(before, a, debuggingImage, m_laserMagnitudeThreshold);

			a.UnlockBits();
			return ret;
		}
示例#12
0
		/**
	 * Detects the laser in x, y pixel coordinates.
	 * @param debuggingImage - If non-NULL, it will be populated with the processed image that was used to detect the laser locations.
	 *     This can be helpful when debugging laser detection issues.
	 * @param laserLocations - Output variable to store the laser locations.
	 * @param maxNumLocations - The maximum number of locations to store in @p laserLocations.
	 * @param thresholdFactor - Scales the laser threshold by this amount.  default = 1.0
	 * @return Returns the number of locations written to @p laserLocations.
	 */
        public List<PointF> Process(Bitmap before, Bitmap after, Bitmap debuggingImage)
		{

			LockBitmap b = new LockBitmap(before);
			LockBitmap d = debuggingImage != null ? new LockBitmap(debuggingImage) : null;
            List<PointF> ret = Process(b, after, d);
			b.UnlockBits();
			if(d!=null)
				d.UnlockBits();

			return ret;
		}