public void AddDiagonalTarget(Graphics g, Rectangle rectangle, TARGBUF TargetX, TARGBUF TargetY) { int x, y; float OffsetX = rectangle.Left + rectangle.Width / 2; float OffsetY = rectangle.Top + rectangle.Height / 2; float LineLength = 0.07f; int LEN = (int)(rectangle.Height * LineLength); float w, v; Pen PlotPen = new Pen(Color.FromArgb(255, 64, 64, 255), 4); // Plot w v mark if (TargetX.TargetFound) { w = TargetX.Adj; } else { w = 0; } if (TargetY.TargetFound) { v = TargetY.Adj; } else { v = 0; } // w = x dx + y dy // v = x dx - y dy // // x = (w + v)/2dx // y = (w - v)/2dy x = (int)(OffsetX + (w + v) * 0.5f * Diagonaldx * rectangle.Width / width); y = (int)(OffsetY + -(w - v) * 0.5f * Diagonaldy * rectangle.Height / height); ClipXY(ref rectangle, ref x, ref y); if (TargetX.TargetFound) { g.DrawLine(PlotPen, x - LEN, y - LEN, x + LEN, y + LEN); } if (TargetY.TargetFound) { g.DrawLine(PlotPen, x - LEN, y + LEN, x + LEN, y - LEN); } PlotPen.Dispose(); }
public Align() { EdgeBufX = new EDGEBUF(); EdgeBufY = new EDGEBUF(); TargetX = new TARGBUF(); TargetY = new TARGBUF(); EdgeBufDiagonalX = new EDGEBUF(); EdgeBufDiagonalY = new EDGEBUF(); TargetDiagonalX = new TARGBUF(); TargetDiagonalY = new TARGBUF(); EdgeBufLeft = new EDGEBUF(); EdgeBufRight = new EDGEBUF(); TargetLeft = new TARGBUF(); TargetRight = new TARGBUF(); }
/*******************************************************************************/ /* */ /* Returns 0 if successful */ /* nonzero if unsuccessful */ /* */ /* HowToLook = ONLYTARGET this parameter informs the target finding routine */ /* that there may be no reticle in view and that the */ /* reticle has not been located. */ /* = INSIDERET this informs the target finding routine to */ /* only look for the target inside the reticle */ /* edges that have been found */ /* */ /*******************************************************************************/ private int TargetLocate(EDGEBUF edges, double DesiredWidth, double TargetWidthTol, double Threshold, int Length, ref TARGBUF tar, Alignment_Type AlignType) { int lei, rei, BeginningOfTargetEdges = 0, EndOfTargetEdges = 0; double HRatio, WRatio, TargetWidth; double MeritValue, MaxMeritValue = -1.0F; int Polarity = AlignType == Alignment_Type.ALGN_BLK_BAR ? 1 : -1; tar.TargetFound = false; BeginningOfTargetEdges = 0; EndOfTargetEdges = edges.EdgesFound - 1; if (EndOfTargetEdges <= BeginningOfTargetEdges) // we need at least 2 edges for the target { return(1); } lei = BeginningOfTargetEdges; do { rei = EndOfTargetEdges; do { HRatio = (float)Math.Abs((float)(edges.EdgeH[lei]) / (float)(edges.EdgeH[rei])); if (HRatio > 1.0F) { HRatio = 1.0F / HRatio; } if ((edges.EdgeH[lei] * Polarity < -Threshold) && (edges.EdgeH[rei] * Polarity > Threshold) && (HRatio > 0.33333F)) { TargetWidth = (edges.EdgeC[rei]) - (edges.EdgeC[lei]); if ((TargetWidth >= DesiredWidth / TargetWidthTol) && (TargetWidth <= DesiredWidth * TargetWidthTol)) { // // Valid Target found, compute merit value // WRatio = TargetWidth / (float)DesiredWidth; if (WRatio > 1.0F) { WRatio = 1.0F / WRatio; } MeritValue = (edges.EdgeH[rei] - edges.EdgeH[lei]) * Polarity * WRatio * HRatio; if (MeritValue > MaxMeritValue) // best so far ?? { MaxMeritValue = MeritValue; tar.TargetFound = true; tar.TargetL = lei; tar.TargetR = rei; } } } } while (--rei > lei); } while (++lei < EndOfTargetEdges); if (tar.TargetFound) { tar.TargetC = (edges.EdgeC[tar.TargetL] + edges.EdgeC[tar.TargetR]) / 2; tar.Adj = tar.TargetC - 0.5f * Length; tar.ImageSizeInPixels = Length; return(0); } else { return(1); } }
public int AlignTarget(Alignment_Type AlignType, int[] XProfile, int[] YProfile, ref EDGEBUF EdgeBufX, ref EDGEBUF EdgeBufY, ref TARGBUF TargetX, ref TARGBUF TargetY, double DesiredTrgtBarWidthX, double DesiredTrgtBarWidthY, double TargetWidthTolX, double TargetWidthTolY, double EdgeThresholdX, double EdgeThresholdY, ref String err) { err = ""; EdgeBufX.EdgesFound = EdgeBufY.EdgesFound = 0; TargetX.TargetFound = TargetY.TargetFound = false; if (EdgeExtract(XProfile, ref EdgeBufX, EdgeThresholdX) != 0) { return(1); } if (EdgeExtract(YProfile, ref EdgeBufY, EdgeThresholdY) != 0) { return(1); } TargetLocate(EdgeBufX, DesiredTrgtBarWidthX, TargetWidthTolX, EdgeThresholdX, XProfile.Length, ref TargetX, AlignType); TargetLocate(EdgeBufY, DesiredTrgtBarWidthY, TargetWidthTolY, EdgeThresholdY, YProfile.Length, ref TargetY, AlignType); if (!TargetX.TargetFound && !TargetY.TargetFound) { err = "Error Finding X and Y Targets"; return(1); } else if (!TargetX.TargetFound) { err = "Error Finding X Target"; return(1); } else if (!TargetY.TargetFound) { err = "Error Finding Y Target"; return(1); } return(0); }
public void AddTarget(Graphics g, Rectangle rectangle, TARGBUF TargetX, TARGBUF TargetY) { int x = 0, y = 0, x0 = 0, y0 = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0; double LineLength = 0.1; double Scale = -rectangle.Height / (double)height; double Offset = rectangle.Top + rectangle.Height * (0.5 - LineLength); Pen PlotPen = new Pen(Color.FromArgb(255, 64, 64, 255), 4); // Plot Vertical mark if (TargetX.TargetFound) { // map profile value to x = (int)(rectangle.Left + (TargetX.TargetC * rectangle.Width) / width); y = (int)(Offset); ClipXY(ref rectangle, ref x, ref y); x0 = x; y0 = y; Offset = rectangle.Top + rectangle.Height * (0.5 + LineLength); x = (int)(rectangle.Left + (TargetX.TargetC * rectangle.Width) / width); y = (int)(Offset); ClipXY(ref rectangle, ref x, ref y); if (!TargetY.TargetFound) { g.DrawLine(PlotPen, x0, y0, x, y); } x1 = x; y1 = y; } // Plot Vertical mark Scale = rectangle.Width / (double)width; Offset = rectangle.Left + rectangle.Width * (0.5 - LineLength); if (TargetY.TargetFound) { // map profile value to y = (int)(rectangle.Top + ((height - 1 - TargetY.TargetC) * rectangle.Height) / height); x = (int)(Offset); ClipXY(ref rectangle, ref x, ref y); x2 = x; y2 = y; Offset = rectangle.Left + rectangle.Width * (0.5 + LineLength); // map profile value to y = (int)(rectangle.Top + ((height - 1 - TargetY.TargetC) * rectangle.Height) / height); x = (int)(Offset); ClipXY(ref rectangle, ref x, ref y); if (!TargetX.TargetFound) { g.DrawLine(PlotPen, x2, y2, x, y); } } if (TargetX.TargetFound && TargetY.TargetFound) { g.DrawLine(PlotPen, x0, (int)(y2 - rectangle.Height * LineLength), x0, (int)(y2 + rectangle.Height * LineLength)); g.DrawLine(PlotPen, (int)(x0 - rectangle.Height * LineLength), y2, (int)(x0 + rectangle.Height * LineLength), y2); } PlotPen.Dispose(); }
public void AddPlotsDiagonal(Graphics g, Rectangle rectangle, int[] XProfile, int[] YProfile, EDGEBUF EdgesX, EDGEBUF EdgesY, TARGBUF TargetX, TARGBUF TargetY) { int i, r, c, x, y, x0 = 0, y0 = 0; double Scale = -rectangle.Height * 0.6 / (bytes_per_pixel * width * 255); double Offset = rectangle.Top + rectangle.Height * 0.99; if (XProfile == null) { return; } Pen PlotPen = new Pen(Color.FromArgb(255, 0, 255, 0), 2); // Plot upward sloping plot for (c = 0; c < XProfile.Length; c++) { // map profile value to double w = c; double v = Scale * (XProfile[c] - (0.5 * bytes_per_pixel * width * 255)); x = (int)(rectangle.Left + (w + v) * 0.5f * Diagonaldx * rectangle.Width / width); y = (int)((rectangle.Top + rectangle.Height) - (w - v) * 0.5f * Diagonaldy * rectangle.Height / height); ClipXY(ref rectangle, ref x, ref y); if (c > 0) { g.DrawLine(PlotPen, x0, y0, x, y); } x0 = x; y0 = y; } // Draw circles around the center of the edges if (TargetX.TargetFound) { for (i = 0; i < EdgesX.EdgesFound; i++) { if (i == TargetX.TargetL || i == TargetX.TargetR) { double w = EdgesX.EdgeC[i]; double v = Scale * (InterpolateY(XProfile, (int)(EdgesX.EdgeC[i] + 0.5f)) - (0.5 * bytes_per_pixel * width * 255)); int xp = (int)(rectangle.Left + (w + v) * 0.5f * Diagonaldx * rectangle.Width / width); int yp = (int)((rectangle.Top + rectangle.Height) - (w - v) * 0.5f * Diagonaldy * rectangle.Height / height); g.DrawEllipse(PlotPen, xp - 4.0f, yp - 4.0f, 8.0f, 8.0f); } } } // Plot Downward sloping plot Scale = rectangle.Width * 0.15 / (bytes_per_pixel * height * 255); Offset = rectangle.Left + rectangle.Width * 0.01; for (r = 0; r < YProfile.Length; r++) { // map profile value to double w = r; double v = Scale * (YProfile[r] - (0.5 * bytes_per_pixel * width * 255)); x = (int)(rectangle.Left + (w + v) * 0.5f * Diagonaldx * rectangle.Width / width); y = (int)(rectangle.Top + (w - v) * 0.5f * Diagonaldy * rectangle.Height / height); ClipXY(ref rectangle, ref x, ref y); if (r > 0) { g.DrawLine(PlotPen, x0, y0, x, y); } x0 = x; y0 = y; } // Draw circles around the center of the edges if (TargetY.TargetFound) { for (i = 0; i < EdgesY.EdgesFound; i++) { if (i == TargetY.TargetL || i == TargetY.TargetR) { double w = EdgesY.EdgeC[i]; double v = Scale * (InterpolateY(YProfile, (int)(EdgesY.EdgeC[i] + 0.5f)) - (0.5 * bytes_per_pixel * width * 255)); int xp = (int)(rectangle.Left + (w + v) * 0.5f * Diagonaldx * rectangle.Width / width); int yp = (int)(rectangle.Top + (w - v) * 0.5f * Diagonaldy * rectangle.Height / height); g.DrawEllipse(PlotPen, xp - 4.0f, yp - 4.0f, 8.0f, 8.0f); } } } PlotPen.Dispose(); }
public void AddPlotsDouble(Graphics g, Rectangle rectangle, int[] XProfile, int[] YProfile, EDGEBUF EdgesX, EDGEBUF EdgesY, TARGBUF TargetX, TARGBUF TargetY) { int i, r, x, y, x0 = 0, y0 = 0; double Scale = -rectangle.Height * 0.6 / (bytes_per_pixel * width * 255); double Offset = rectangle.Top + rectangle.Height * 0.99; if (XProfile == null) { return; } Pen PlotPen = new Pen(Color.FromArgb(255, 0, 255, 0), 2); // Plot Vertical plot Scale = rectangle.Width * 0.15 / (bytes_per_pixel * height * 255); Offset = rectangle.Left + rectangle.Width * 0.01; for (r = 0; r < height; r++) { // map profile value to y = rectangle.Top + ((height - 1 - r) * rectangle.Height) / height; x = (int)(Offset + Scale * YProfile[r]); ClipXY(ref rectangle, ref x, ref y); if (r > 0) { g.DrawLine(PlotPen, x0, y0, x, y); } x0 = x; y0 = y; } // Draw circles around the center of the edges if (TargetY.TargetFound) { for (i = 0; i < EdgesY.EdgesFound; i++) { if (i == TargetY.TargetL || i == TargetY.TargetR) { float yc = EdgesY.EdgeC[i]; float xc = InterpolateY(YProfile, yc); float yp = rectangle.Top + ((height - 1 - yc) * rectangle.Height) / height; float xp = (float)(xc * Scale + Offset); g.DrawEllipse(PlotPen, xp - 4.0f, yp - 4.0f, 8.0f, 8.0f); } } } // Plot Vertical plot Scale = rectangle.Width * 0.15 / (bytes_per_pixel * height * 255); Offset = rectangle.Left + rectangle.Width * 0.8; for (r = 0; r < height; r++) { // map profile value to y = rectangle.Top + ((height - 1 - r) * rectangle.Height) / height; x = (int)(Offset + Scale * YProfile[r]); ClipXY(ref rectangle, ref x, ref y); if (r > 0) { g.DrawLine(PlotPen, x0, y0, x, y); } x0 = x; y0 = y; } // Draw circles around the center of the edges if (TargetY.TargetFound) { for (i = 0; i < EdgesY.EdgesFound; i++) { if (i == TargetY.TargetL || i == TargetY.TargetR) { float yc = EdgesY.EdgeC[i]; float xc = InterpolateY(YProfile, yc); float yp = rectangle.Top + ((height - 1 - yc) * rectangle.Height) / height; float xp = (float)(xc * Scale + Offset); g.DrawEllipse(PlotPen, xp - 4.0f, yp - 4.0f, 8.0f, 8.0f); } } } PlotPen.Dispose(); }