private void button2_Click_1(object sender, EventArgs e) // Detect edges { if (!OPEN) { MessageBox.Show("Please open an image"); return; } progressBar1.Visible = true; progressBar1.Value = 0; if (OrigIm.N_Bits == 24) { SigmaIm.SigmaColor(OrigIm, 1, 30, this); ExtremIm.ExtremVarColor(SigmaIm, 2, this); // it was 2 } else { SigmaIm.SigmaNewM(OrigIm, 1, 30, this); ExtremIm.ExtremVar(SigmaIm, 2, this); // it was 2 } Threshold = (int)numericUpDown1.Value; int NX = OrigIm.width; CombIm.LabelCellsSign(Threshold, ExtremIm); CombIm.CleanCombNew(21, this); CombIm.CheckComb(7); for (int y = 0; y < OrigIm.height; y++) { for (int x = 0; x < OrigIm.width; x++) { if (ExtremIm.N_Bits == 24) { CombIm.Grid[2 * x + 1 + (2 * NX + 1) * (2 * y + 1)] = ExtremIm.Grid[1 + 3 * (x + NX * y)]; } else { CombIm.Grid[2 * x + 1 + (2 * NX + 1) * (2 * y + 1)] = SigmaIm.Grid[x + NX * y]; } } } EdgeIm.CracksToPixel(CombIm); EdgeBmp = new Bitmap(OrigIm.width, OrigIm.height, PixelFormat.Format24bppRgb); EdgeIm.ImageToBitmapOld(EdgeBmp, this); pictureBox2.Image = EdgeBmp; int nBits = CombIm.N_Bits; int maxL2 = 40000, maxV = 150000, maxArc = 40000, sizeX = EdgeIm.width / 8, sizeY = EdgeIm.height / 8, nx = EdgeIm.width / sizeX + 1, ny = EdgeIm.height / sizeY + 1, maxArcInPScell = 1200; L = new CListLines(maxL2, maxV, maxArc, nx, ny, maxArcInPScell, sizeX, sizeY); eps = 2.0; switch (width / 500) { case 0: eps = 1.01; break; case 1: eps = 1.05; break; case 2: eps = 1.20; break; case 3: eps = 1.70; break; } L.SearchPoly(ref CombIm, eps, this); bool RECT = true; int nArcs = L.MakeArcsTwo(pictureBox2, this); L.MakeDarts(this); bool ORI = false; RECT = false; int nPoint = 1; L.DrawArcs(ORI, RECT, nPoint, this); label4.Visible = true; int nEllipse = 0; //int Dir, rv = -1; Dir = L.FindEllipsesMode(SigmaIm, ListEllipse, ref nEllipse, this); label4.Text = "Recognized bicycle"; label4.Visible = true; label5.Visible = false; L.MakeDrawing(ListEllipse[0], ListEllipse[1], Dir, this); button3.Visible = true; radioButton1.Visible = true; radioButton2.Visible = true; label5.Text = "Click 'Save result'"; label5.Visible = true; if (MessReturn("Form1 258: Processing finished. Returning.") < 0) { return; } }
private void button3_Click(object sender, EventArgs e) // Polygons { int nBits = CombIm.N_Bits; if (!EDGES) { MessageBox.Show("Click edge detection"); return; } if (!radioButton1.Checked && !radioButton2.Checked) { MessageBox.Show("Choose a radio button with 'Radii'"); return; } OrigIm.ImageToBitmapOld(BmpPictBox1, this); int maxL2 = 100000, maxV = 220000, maxArc = 40000; L = new CListLines(maxL2, maxV, maxArc); int marginX = (pictureBox2.Width - (int)(Scale1 * OrigIm.width)) / 2; int marginY = (pictureBox2.Height - (int)(Scale1 * OrigIm.height)) / 2; int PicBoxInd = 1; if (radioButton1.Checked) { Ins1 = new CInscript(PicBoxInd, 0.6, 0, 0, OrigIm.width, Color.Yellow, this); radio1_Checked = true; } else if (radioButton2.Checked) { Ins1 = new CInscript(PicBoxInd, 0.8, 0, 0, OrigIm.width, Color.Yellow, this); radio2_Checked = true; } PicBoxInd = 2; Ins2 = new CInscript(PicBoxInd, 0.5, 0, 0, OrigIm.width, Color.White, this); CombIm.nLoop = nLoop; CombIm.denomProg = denomProg; // 0 1 2 3 4 5 6 7 int[] minRad = { 10, 14, 23, 35, 53, 80, 120, 180 }; int[] maxRad = { 20, 30, 46, 70, 106, 160, 240, 360 }; double[] ProtEps = { 1.05, 1.15, 1.23, 1.35, 1.50, 1.67, 1.85, 2.0 }; double maxAngle1 = 0.0, maxAngle2 = 0.0; optVar1 = optVar2 = -1; optNcircle1 = optNcircle2 = 0; int nVar = 8; int maxCircle = 2000; nBest = 0; nCircle = new int[nVar]; Circle = new CCircle[nVar, maxCircle]; // declared in Form1 for (int iv = 0; iv < nVar; iv++) { for (int i = 0; i < maxCircle; i++) { Circle[iv, i] = new CCircle(); } } BestCircles1 = new CCircle[6000]; for (int i = 0; i < 600; i++) { BestCircles1[i] = new CCircle(); } BestCircles2 = new CCircle[600]; for (int i = 0; i < 600; i++) { BestCircles2[i] = new CCircle(); } int nArcs = 0, rv = 1; int iVarStart = 0, iVarEnd = 7; if (radioButton1.Checked) { iVarEnd = 4; } else if (radioButton2.Checked) { iVarStart = 3; } else { MessageBox.Show("Chose a radio button with 'Radii'"); } progressBar1.Value = 0; progressBar1.Visible = true; progressBar1.Step = 20; for (int iVar = iVarStart; iVar <= iVarEnd; iVar++) //=========================================== { progressBar1.PerformStep(); eps = ProtEps[iVar]; numericUpDown2.Value = (decimal)eps; rv = L.SearchPoly(ref CombIm, eps, this); if (rv < 0) { break; } double maxSinus = 0.7, maxProportion = 0.2; L.CheckSmooth(maxSinus, maxProportion); rv = L.DrawPolygons(pictureBox2, EdgeIm, this); EDGES = false; POLY = true; nArcs = L.MakeArcs3(pictureBox2, minRad[iVar], maxRad[iVar], eps, this); if (nArcs < 0) { break; } nBest = 0; nCircle[iVar] = 0; int[] iBestCircles1 = new int[100]; nCircle[iVar] = L.MakeCirclesEl(Circle, iVar, ref nCircle[iVar], minRad[iVar], maxRad[iVar], iBestCircles1, ref nBest); if (nCircle[iVar] < 0) { break; } double SumAngle; //if (nCircle[iVar] > 0) SumAngle = TestCircles(Circle, iVar, nCircle[iVar]); if (nCircle[iVar] > 0) { SumAngle = TestCircles(Circle, iVar, nCircle); } else { SumAngle = 0.0; } if (radioButton1.Checked) { int cnt = 0; if (SumAngle > maxAngle1) { cnt = 0; for (int iCircle = 0; iCircle < nCircle[iVar]; iCircle++) { if (Circle[iVar, iCircle].good) { BestCircles1[cnt] = Circle[iVar, iCircle]; cnt++; } } maxAngle1 = SumAngle; optVar1 = iVar; optNcircle1 = cnt; } } if (radioButton2.Checked) { int cnt = 0; if (SumAngle > maxAngle2) { cnt = 0; for (int iCircle = 0; iCircle < nCircle[iVar]; iCircle++) { if (Circle[iVar, iCircle].good) { BestCircles2[cnt] = Circle[iVar, iCircle]; cnt++; } } maxAngle2 = SumAngle; optVar2 = iVar; optNcircle2 = cnt; } } } //=========================== end for (int iVar... ================================== if (rv < 0) { return; } progressBar1.Visible = false; if (radioButton1.Checked) { nBest = L.ShowBestCircles3(BestCircles1, optNcircle1, 2.0, this); MessageBox.Show("Form1: Number of recognized circles is " + nBest); } if (radioButton2.Checked) { nBest = L.ShowBestCircles3(BestCircles2, optNcircle2, 1.0, this); MessageBox.Show("Form1: Number of recognized circles is " + nBest); } label5.Visible = true; label5.Text = "Recognized circles"; label6.Visible = true; label6.Text = "Polygons"; button4.Visible = true; button5.Visible = true; groupBox2.Visible = true; } //*************************** end Polygons *******************************