Changeset 68

User picture

Author: Slipy90

(2011/10/27 12:31) 7 months ago

GUI ÁTALAKÍTÁS ELŐTT II.

Affected files

Added trunk/JPS_PuzzleDetectorWithCam/JPS_PuzzleDetectorWithCam/bin/Debug/ZedGraph.xml

Show contents

Added trunk/JPS_PuzzleDetectorWithCam/JPS_PuzzleDetectorWithCam/bin/Release/JPS_PuzzleDetectorWithCam.vshost.exe.manifest

Show contents

Updated trunk/JPS_PuzzleDetectorWithCam/JPS_PuzzleDetectorWithCam/ImageFunction.cs Download diff

6768
41
			set { ImageFunction.thresholdHighValue = value; }
41
			set { ImageFunction.thresholdHighValue = value; }
42
		}
42
		}
43
43
44
        public static Image<Gray, Byte> BinarizeHSV(Image<Bgr, Byte> srcImage, byte thresholdVal)
44
        public static Image<Gray, Byte> Binarize(Image<Bgr, Byte> srcImage, byte thresholdVal)
45
        {
45
        {
46
            Image<Gray, Byte> dstImage = new Image<Gray, byte>(srcImage.Size);
46
            Image<Gray, Byte> dstImage = new Image<Gray, byte>(srcImage.Size);
47
47
48
            Image<Luv, Byte> srcImageHSV = new Image<Luv, byte>(srcImage.Bitmap);
48
            Image<Luv, Byte> srcImageHSV = new Image<Luv, byte>(srcImage.Bitmap);
49
49
50
            Image<Gray, Byte>[] channels = srcImageHSV.Split();
50
            Image<Gray, Byte>[] channels = srcImageHSV.Split();
51
            Image<Gray, Byte> imgSat = channels[1];
51
            Image<Gray, Byte> imgMask = channels[1];
52
52
53
            dstImage = imgSat
53
            dstImage = imgMask
54
                        .ThresholdBinaryInv(new Gray(thresholdVal), new Gray(255))
54
                        .ThresholdBinaryInv(new Gray(thresholdVal), new Gray(255))
55
                        .SmoothMedian(7)
55
                        .SmoothMedian(7)
56
                        //.Erode(1)
56
                        //.Erode(1)
...
...
592
            return new Image<Bgr, byte>(dstImage);
592
            return new Image<Bgr, byte>(dstImage);
593
        }
593
        }
594
        #endregion
594
        #endregion
595
595
    }
596
    }
596
597
597
    public enum CameraMoveDirection
598
    public enum CameraMoveDirection

Updated trunk/JPS_PuzzleDetectorWithCam/JPS_PuzzleDetectorWithCam/MainForm.cs Download diff

6768
90
		private void timerOriginal_Tick(object sender, EventArgs e) 
90
		private void timerOriginal_Tick(object sender, EventArgs e) 
91
		{
91
		{
92
            // Élő képhez ez kell
92
            // Élő képhez ez kell
93
            capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 1280);
93
            //capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 1280);
94
            capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 720);
94
            //capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 720);
95
            captureFrame = capture.QueryFrame(); captureGrayFrame = capture.QueryGrayFrame();
95
            //captureFrame = capture.QueryFrame(); captureGrayFrame = capture.QueryGrayFrame();
96
96
97
            //if (firstDetect)
97
            //if (firstDetect)
98
            //{
98
            //{
...
...
108
                histoForm.Image = captureGrayFrame;
108
                histoForm.Image = captureGrayFrame;
109
			}
109
			}
110
110
111
            //if (rBtnThresholdSimple.Checked)
111
            imgBinarized = ImageFunction.Binarize(captureFrame, 152);
112
            //    imgBinarized = ImageFunction.BinarizeSimple(captureGrayFrame);
112
            picBoxCamBinarized.Image = captureFrame.Or(imgBinarized.Convert<Bgr, Byte>());
113
            //else if (rBtnThresholdDouble.Checked)
114
            //    imgBinarized = ImageFunction.BinarizeDouble(captureGrayFrame);
115
            //else if (rBtnThresholdOtsu.Checked)
116
            //    imgBinarized = ImageFunction.BinarizeOtsu(captureGrayFrame);
117
113
118
            //picBoxCamBinarized.Image = imgBinarized;
119
120
            imgBinarized = ImageFunction.BinarizeHSV(captureFrame, 152);
121
            picBoxCamBinarized.Image = imgBinarized;
122
123
            //imgCannyEdgeDetected = ImageFunction.Canny(captureGrayFrame);
114
            //imgCannyEdgeDetected = ImageFunction.Canny(captureGrayFrame);
124
            //if (numUpDownDilateIter.Value > 0 && numUpDownErodeIter.Value == 0)
115
            //if (numUpDownDilateIter.Value > 0 && numUpDownErodeIter.Value == 0)
125
            //{
116
            //{
...
...
212
                picBoxCamOriginal.Image = captureFrame;
203
                picBoxCamOriginal.Image = captureFrame;
213
                //firstCenterPoint = true;
204
                //firstCenterPoint = true;
214
            }
205
            }
215
216
            //picBoxCamBinarized.Image = ImageFunction.GetCorners(captureGrayFrame);
217
            //try
218
            //{
219
            //    //rawContours = ImageFunction.GetContours(imgCannyEdgeDetected, true, .5);
220
            //    PuzzleFunction.Cut(captureFrame, rawContours);
221
            //}
222
            //catch (ArgumentException ex)
223
            //{
224
            //    ErrorMessage(ex.Message);
225
            //}
226
227
            //lbPuzzlePieces.DataSource = PuzzleFunction.PuzzlePieces.ToArray();
228
            //picBoxCamOriginal.Image = captureFrame;
229
230
			//lbPuzzlePieces.DataSource = PuzzleFunction.PuzzlePieces.ToArray();
231
		}
206
		}
232
		#endregion
207
		#endregion
233
208
...
...
366
                for (int i = 0; i < currPiece.Sides.Count; i++)
341
                for (int i = 0; i < currPiece.Sides.Count; i++)
367
                {
342
                {
368
                    if (i == 0)
343
                    if (i == 0)
369
                        tmp.Draw(new CircleF(currPiece.Sides[i].Corners[0], 3), new Bgr(0, 255, 0), 1);
344
                        tmp.Draw(new CircleF(currPiece.Sides[i].Corners[0], 5), new Bgr(0, 255, 0), -1);
370
                    if (i == 1)
345
                    if (i == 1)
371
                        tmp.Draw(new CircleF(currPiece.Sides[i].Corners[0], 3), new Bgr(255, 0, 0), 1);
346
                        tmp.Draw(new CircleF(currPiece.Sides[i].Corners[0], 5), new Bgr(255, 0, 0), -1);
372
                    if (i == 2)
347
                    if (i == 2)
373
                        tmp.Draw(new CircleF(currPiece.Sides[i].Corners[0], 3), new Bgr(0, 0, 255), 1);
348
                        tmp.Draw(new CircleF(currPiece.Sides[i].Corners[0], 5), new Bgr(0, 0, 255), -1);
374
                    if (i == 3)
349
                    if (i == 3)
375
                        tmp.Draw(new CircleF(currPiece.Sides[i].Corners[0], 3), new Bgr(255, 255, 0), 1);
350
                        tmp.Draw(new CircleF(currPiece.Sides[i].Corners[0], 5), new Bgr(255, 255, 0), -1);
376
                }
351
                }
377
                picBoxPuzzlePiece.Image = tmp;
352
                picBoxCannyEdge.Image = tmp;
378
353
379
                //picBoxCannyEdge.Image = PuzzlePiece.GenerateSignatureImage(currPiece.Signature);
354
                //picBoxCannyEdge.Image = PuzzlePiece.GenerateSignatureImage(currPiece.Signature);
380
355

Updated trunk/JPS_PuzzleDetectorWithCam/JPS_PuzzleDetectorWithCam/MainForm.Designer.cs Download diff

6768
34
            this.kilépésToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
34
            this.kilépésToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
35
            this.menuHisztogram = new System.Windows.Forms.ToolStripMenuItem();
35
            this.menuHisztogram = new System.Windows.Forms.ToolStripMenuItem();
36
            this.statusStrip = new System.Windows.Forms.StatusStrip();
36
            this.statusStrip = new System.Windows.Forms.StatusStrip();
37
            this.picBoxCannyEdge = new Emgu.CV.UI.ImageBox();
38
            this.timerOriginal = new System.Windows.Forms.Timer(this.components);
37
            this.timerOriginal = new System.Windows.Forms.Timer(this.components);
39
            this.groupBox1 = new System.Windows.Forms.GroupBox();
38
            this.groupBox1 = new System.Windows.Forms.GroupBox();
40
            this.btnDetect = new System.Windows.Forms.Button();
39
            this.btnDetect = new System.Windows.Forms.Button();
...
...
42
            this.picBoxCamOriginal = new Emgu.CV.UI.ImageBox();
41
            this.picBoxCamOriginal = new Emgu.CV.UI.ImageBox();
43
            this.groupBox2 = new System.Windows.Forms.GroupBox();
42
            this.groupBox2 = new System.Windows.Forms.GroupBox();
44
            this.groupBox4 = new System.Windows.Forms.GroupBox();
43
            this.groupBox4 = new System.Windows.Forms.GroupBox();
45
            this.labThresholdValHigh = new System.Windows.Forms.Label();
46
            this.numUpDownThresholdHigh = new System.Windows.Forms.NumericUpDown();
47
            this.labThresholdValLow = new System.Windows.Forms.Label();
44
            this.labThresholdValLow = new System.Windows.Forms.Label();
48
            this.numUpDownThresholdLow = new System.Windows.Forms.NumericUpDown();
45
            this.numUpDownThresholdLow = new System.Windows.Forms.NumericUpDown();
49
            this.groupBox3 = new System.Windows.Forms.GroupBox();
50
            this.rBtnThresholdOtsu = new System.Windows.Forms.RadioButton();
51
            this.rBtnThresholdDouble = new System.Windows.Forms.RadioButton();
52
            this.rBtnThresholdSimple = new System.Windows.Forms.RadioButton();
53
            this.picBoxCamBinarized = new Emgu.CV.UI.ImageBox();
46
            this.picBoxCamBinarized = new Emgu.CV.UI.ImageBox();
54
            this.groupBox5 = new System.Windows.Forms.GroupBox();
55
            this.label3 = new System.Windows.Forms.Label();
56
            this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
57
            this.groupBox6 = new System.Windows.Forms.GroupBox();
58
            this.numUpDownErodeIter = new System.Windows.Forms.NumericUpDown();
59
            this.numUpDownDilateIter = new System.Windows.Forms.NumericUpDown();
60
            this.label2 = new System.Windows.Forms.Label();
61
            this.label1 = new System.Windows.Forms.Label();
62
            this.gBoxPuzzlePieces = new System.Windows.Forms.GroupBox();
47
            this.gBoxPuzzlePieces = new System.Windows.Forms.GroupBox();
63
            this.txtPuzzleSideType = new System.Windows.Forms.TextBox();
48
            this.txtPuzzleSideType = new System.Windows.Forms.TextBox();
64
            this.label4 = new System.Windows.Forms.Label();
49
            this.label4 = new System.Windows.Forms.Label();
...
...
68
            this.btnAssembling = new System.Windows.Forms.Button();
53
            this.btnAssembling = new System.Windows.Forms.Button();
69
            this.label5 = new System.Windows.Forms.Label();
54
            this.label5 = new System.Windows.Forms.Label();
70
            this.labCamMoveDirection = new System.Windows.Forms.Label();
55
            this.labCamMoveDirection = new System.Windows.Forms.Label();
56
            this.histogram = new Emgu.CV.UI.HistogramBox();
57
            this.numUpDownThresholdHigh = new System.Windows.Forms.NumericUpDown();
58
            this.labThresholdValHigh = new System.Windows.Forms.Label();
59
            this.rBtnThresholdSimple = new System.Windows.Forms.RadioButton();
60
            this.rBtnThresholdDouble = new System.Windows.Forms.RadioButton();
61
            this.rBtnThresholdOtsu = new System.Windows.Forms.RadioButton();
62
            this.groupBox3 = new System.Windows.Forms.GroupBox();
71
            this.labTeszt = new System.Windows.Forms.Label();
63
            this.labTeszt = new System.Windows.Forms.Label();
72
            this.histogram = new Emgu.CV.UI.HistogramBox();
64
            this.picBoxCannyEdge = new Emgu.CV.UI.ImageBox();
65
            this.groupBox6 = new System.Windows.Forms.GroupBox();
66
            this.label1 = new System.Windows.Forms.Label();
67
            this.label2 = new System.Windows.Forms.Label();
68
            this.numUpDownDilateIter = new System.Windows.Forms.NumericUpDown();
69
            this.numUpDownErodeIter = new System.Windows.Forms.NumericUpDown();
70
            this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
71
            this.label3 = new System.Windows.Forms.Label();
72
            this.groupBox5 = new System.Windows.Forms.GroupBox();
73
            this.menuStrip.SuspendLayout();
73
            this.menuStrip.SuspendLayout();
74
            ((System.ComponentModel.ISupportInitialize)(this.picBoxCannyEdge)).BeginInit();
75
            this.groupBox1.SuspendLayout();
74
            this.groupBox1.SuspendLayout();
76
            ((System.ComponentModel.ISupportInitialize)(this.picBoxCamOriginal)).BeginInit();
75
            ((System.ComponentModel.ISupportInitialize)(this.picBoxCamOriginal)).BeginInit();
77
            this.groupBox2.SuspendLayout();
76
            this.groupBox2.SuspendLayout();
78
            this.groupBox4.SuspendLayout();
77
            this.groupBox4.SuspendLayout();
78
            ((System.ComponentModel.ISupportInitialize)(this.numUpDownThresholdLow)).BeginInit();
79
            ((System.ComponentModel.ISupportInitialize)(this.picBoxCamBinarized)).BeginInit();
80
            this.gBoxPuzzlePieces.SuspendLayout();
81
            ((System.ComponentModel.ISupportInitialize)(this.picBoxPuzzlePiece)).BeginInit();
79
            ((System.ComponentModel.ISupportInitialize)(this.numUpDownThresholdHigh)).BeginInit();
82
            ((System.ComponentModel.ISupportInitialize)(this.numUpDownThresholdHigh)).BeginInit();
80
            ((System.ComponentModel.ISupportInitialize)(this.numUpDownThresholdLow)).BeginInit();
81
            this.groupBox3.SuspendLayout();
83
            this.groupBox3.SuspendLayout();
82
            ((System.ComponentModel.ISupportInitialize)(this.picBoxCamBinarized)).BeginInit();
84
            ((System.ComponentModel.ISupportInitialize)(this.picBoxCannyEdge)).BeginInit();
83
            this.groupBox5.SuspendLayout();
84
            ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
85
            this.groupBox6.SuspendLayout();
85
            this.groupBox6.SuspendLayout();
86
            ((System.ComponentModel.ISupportInitialize)(this.numUpDownDilateIter)).BeginInit();
86
            ((System.ComponentModel.ISupportInitialize)(this.numUpDownErodeIter)).BeginInit();
87
            ((System.ComponentModel.ISupportInitialize)(this.numUpDownErodeIter)).BeginInit();
87
            ((System.ComponentModel.ISupportInitialize)(this.numUpDownDilateIter)).BeginInit();
88
            ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
88
            this.gBoxPuzzlePieces.SuspendLayout();
89
            this.groupBox5.SuspendLayout();
89
            ((System.ComponentModel.ISupportInitialize)(this.picBoxPuzzlePiece)).BeginInit();
90
            this.SuspendLayout();
90
            this.SuspendLayout();
91
            // 
91
            // 
92
            // menuStrip
92
            // menuStrip
...
...
131
            this.statusStrip.TabIndex = 6;
131
            this.statusStrip.TabIndex = 6;
132
            this.statusStrip.Text = "statusStrip1";
132
            this.statusStrip.Text = "statusStrip1";
133
            // 
133
            // 
134
            // picBoxCannyEdge
135
            // 
136
            this.picBoxCannyEdge.Location = new System.Drawing.Point(6, 19);
137
            this.picBoxCannyEdge.Name = "picBoxCannyEdge";
138
            this.picBoxCannyEdge.Size = new System.Drawing.Size(309, 220);
139
            this.picBoxCannyEdge.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
140
            this.picBoxCannyEdge.TabIndex = 7;
141
            this.picBoxCannyEdge.TabStop = false;
142
            // 
143
            // timerOriginal
134
            // timerOriginal
144
            // 
135
            // 
145
            this.timerOriginal.Enabled = true;
136
            this.timerOriginal.Enabled = true;
...
...
217
            this.groupBox4.TabStop = false;
208
            this.groupBox4.TabStop = false;
218
            this.groupBox4.Text = "Küszöb érték(ek)";
209
            this.groupBox4.Text = "Küszöb érték(ek)";
219
            // 
210
            // 
220
            // labThresholdValHigh
221
            // 
222
            this.labThresholdValHigh.AutoSize = true;
223
            this.labThresholdValHigh.Location = new System.Drawing.Point(128, 21);
224
            this.labThresholdValHigh.Name = "labThresholdValHigh";
225
            this.labThresholdValHigh.Size = new System.Drawing.Size(35, 13);
226
            this.labThresholdValHigh.TabIndex = 8;
227
            this.labThresholdValHigh.Text = "Felső:";
228
            this.labThresholdValHigh.Visible = false;
229
            // 
230
            // numUpDownThresholdHigh
231
            // 
232
            this.numUpDownThresholdHigh.Location = new System.Drawing.Point(172, 19);
233
            this.numUpDownThresholdHigh.Maximum = new decimal(new int[] {
234
            255,
235
            0,
236
            0,
237
            0});
238
            this.numUpDownThresholdHigh.Name = "numUpDownThresholdHigh";
239
            this.numUpDownThresholdHigh.Size = new System.Drawing.Size(40, 20);
240
            this.numUpDownThresholdHigh.TabIndex = 9;
241
            this.numUpDownThresholdHigh.Value = new decimal(new int[] {
242
            100,
243
            0,
244
            0,
245
            0});
246
            this.numUpDownThresholdHigh.Visible = false;
247
            this.numUpDownThresholdHigh.ValueChanged += new System.EventHandler(this.numUpDownThresholdHigh_ValueChanged);
248
            // 
249
            // labThresholdValLow
211
            // labThresholdValLow
250
            // 
212
            // 
251
            this.labThresholdValLow.AutoSize = true;
213
            this.labThresholdValLow.AutoSize = true;
...
...
274
            0});
236
            0});
275
            this.numUpDownThresholdLow.ValueChanged += new System.EventHandler(this.numUpDownThresholdLow_ValueChanged);
237
            this.numUpDownThresholdLow.ValueChanged += new System.EventHandler(this.numUpDownThresholdLow_ValueChanged);
276
            // 
238
            // 
277
            // groupBox3
278
            // 
279
            this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
280
                        | System.Windows.Forms.AnchorStyles.Right)));
281
            this.groupBox3.Controls.Add(this.rBtnThresholdOtsu);
282
            this.groupBox3.Controls.Add(this.rBtnThresholdDouble);
283
            this.groupBox3.Controls.Add(this.rBtnThresholdSimple);
284
            this.groupBox3.Location = new System.Drawing.Point(6, 245);
285
            this.groupBox3.Name = "groupBox3";
286
            this.groupBox3.Size = new System.Drawing.Size(309, 49);
287
            this.groupBox3.TabIndex = 8;
288
            this.groupBox3.TabStop = false;
289
            this.groupBox3.Text = "Módszer";
290
            // 
291
            // rBtnThresholdOtsu
292
            // 
293
            this.rBtnThresholdOtsu.AutoSize = true;
294
            this.rBtnThresholdOtsu.Checked = true;
295
            this.rBtnThresholdOtsu.Location = new System.Drawing.Point(172, 19);
296
            this.rBtnThresholdOtsu.Name = "rBtnThresholdOtsu";
297
            this.rBtnThresholdOtsu.Size = new System.Drawing.Size(47, 17);
298
            this.rBtnThresholdOtsu.TabIndex = 0;
299
            this.rBtnThresholdOtsu.TabStop = true;
300
            this.rBtnThresholdOtsu.Text = "Otsu";
301
            this.rBtnThresholdOtsu.UseVisualStyleBackColor = true;
302
            this.rBtnThresholdOtsu.CheckedChanged += new System.EventHandler(this.rBtnThresholdOtsu_CheckedChanged);
303
            // 
304
            // rBtnThresholdDouble
305
            // 
306
            this.rBtnThresholdDouble.AutoSize = true;
307
            this.rBtnThresholdDouble.Location = new System.Drawing.Point(80, 19);
308
            this.rBtnThresholdDouble.Name = "rBtnThresholdDouble";
309
            this.rBtnThresholdDouble.Size = new System.Drawing.Size(86, 17);
310
            this.rBtnThresholdDouble.TabIndex = 0;
311
            this.rBtnThresholdDouble.Text = "Hiszterézises";
312
            this.rBtnThresholdDouble.UseVisualStyleBackColor = true;
313
            this.rBtnThresholdDouble.CheckedChanged += new System.EventHandler(this.rBtnThresholdDouble_CheckedChanged);
314
            // 
315
            // rBtnThresholdSimple
316
            // 
317
            this.rBtnThresholdSimple.AutoSize = true;
318
            this.rBtnThresholdSimple.Location = new System.Drawing.Point(6, 19);
319
            this.rBtnThresholdSimple.Name = "rBtnThresholdSimple";
320
            this.rBtnThresholdSimple.Size = new System.Drawing.Size(68, 17);
321
            this.rBtnThresholdSimple.TabIndex = 0;
322
            this.rBtnThresholdSimple.Text = "Egyszerű";
323
            this.rBtnThresholdSimple.UseVisualStyleBackColor = true;
324
            this.rBtnThresholdSimple.CheckedChanged += new System.EventHandler(this.rBtnThresholdSimple_CheckedChanged);
325
            // 
326
            // picBoxCamBinarized
239
            // picBoxCamBinarized
327
            // 
240
            // 
328
            this.picBoxCamBinarized.Location = new System.Drawing.Point(6, 19);
241
            this.picBoxCamBinarized.Location = new System.Drawing.Point(6, 19);
...
...
332
            this.picBoxCamBinarized.TabIndex = 5;
245
            this.picBoxCamBinarized.TabIndex = 5;
333
            this.picBoxCamBinarized.TabStop = false;
246
            this.picBoxCamBinarized.TabStop = false;
334
            // 
247
            // 
335
            // groupBox5
336
            // 
337
            this.groupBox5.Controls.Add(this.label3);
338
            this.groupBox5.Controls.Add(this.numericUpDown1);
339
            this.groupBox5.Controls.Add(this.groupBox6);
340
            this.groupBox5.Controls.Add(this.picBoxCannyEdge);
341
            this.groupBox5.Location = new System.Drawing.Point(666, 28);
342
            this.groupBox5.Name = "groupBox5";
343
            this.groupBox5.Size = new System.Drawing.Size(320, 357);
344
            this.groupBox5.TabIndex = 11;
345
            this.groupBox5.TabStop = false;
346
            this.groupBox5.Text = "Éldetektált kép";
347
            // 
348
            // label3
349
            // 
350
            this.label3.AutoSize = true;
351
            this.label3.Location = new System.Drawing.Point(12, 317);
352
            this.label3.Name = "label3";
353
            this.label3.Size = new System.Drawing.Size(179, 13);
354
            this.label3.TabIndex = 10;
355
            this.label3.Text = "A puzzle darab %os aránya a képen:";
356
            // 
357
            // numericUpDown1
358
            // 
359
            this.numericUpDown1.Location = new System.Drawing.Point(197, 315);
360
            this.numericUpDown1.Name = "numericUpDown1";
361
            this.numericUpDown1.Size = new System.Drawing.Size(40, 20);
362
            this.numericUpDown1.TabIndex = 11;
363
            this.numericUpDown1.Value = new decimal(new int[] {
364
            80,
365
            0,
366
            0,
367
            0});
368
            // 
369
            // groupBox6
370
            // 
371
            this.groupBox6.Controls.Add(this.numUpDownErodeIter);
372
            this.groupBox6.Controls.Add(this.numUpDownDilateIter);
373
            this.groupBox6.Controls.Add(this.label2);
374
            this.groupBox6.Controls.Add(this.label1);
375
            this.groupBox6.Location = new System.Drawing.Point(6, 245);
376
            this.groupBox6.Name = "groupBox6";
377
            this.groupBox6.Size = new System.Drawing.Size(308, 49);
378
            this.groupBox6.TabIndex = 9;
379
            this.groupBox6.TabStop = false;
380
            this.groupBox6.Text = "Dialtáció/Erózió iterációk száma";
381
            // 
382
            // numUpDownErodeIter
383
            // 
384
            this.numUpDownErodeIter.Location = new System.Drawing.Point(178, 19);
385
            this.numUpDownErodeIter.Maximum = new decimal(new int[] {
386
            1000,
387
            0,
388
            0,
389
            0});
390
            this.numUpDownErodeIter.Name = "numUpDownErodeIter";
391
            this.numUpDownErodeIter.Size = new System.Drawing.Size(40, 20);
392
            this.numUpDownErodeIter.TabIndex = 10;
393
            this.numUpDownErodeIter.ValueChanged += new System.EventHandler(this.numUpDownErodeIter_ValueChanged);
394
            // 
395
            // numUpDownDilateIter
396
            // 
397
            this.numUpDownDilateIter.Location = new System.Drawing.Point(63, 19);
398
            this.numUpDownDilateIter.Maximum = new decimal(new int[] {
399
            1000,
400
            0,
401
            0,
402
            0});
403
            this.numUpDownDilateIter.Name = "numUpDownDilateIter";
404
            this.numUpDownDilateIter.Size = new System.Drawing.Size(40, 20);
405
            this.numUpDownDilateIter.TabIndex = 10;
406
            this.numUpDownDilateIter.Value = new decimal(new int[] {
407
            1,
408
            0,
409
            0,
410
            0});
411
            this.numUpDownDilateIter.ValueChanged += new System.EventHandler(this.numUpDownDilateIter_ValueChanged);
412
            // 
413
            // label2
414
            // 
415
            this.label2.AutoSize = true;
416
            this.label2.Location = new System.Drawing.Point(121, 21);
417
            this.label2.Name = "label2";
418
            this.label2.Size = new System.Drawing.Size(39, 13);
419
            this.label2.TabIndex = 7;
420
            this.label2.Text = "Erózió:";
421
            this.label2.TextAlign = System.Drawing.ContentAlignment.TopRight;
422
            // 
423
            // label1
424
            // 
425
            this.label1.AutoSize = true;
426
            this.label1.Location = new System.Drawing.Point(6, 21);
427
            this.label1.Name = "label1";
428
            this.label1.Size = new System.Drawing.Size(51, 13);
429
            this.label1.TabIndex = 7;
430
            this.label1.Text = "Dilatáció:";
431
            this.label1.TextAlign = System.Drawing.ContentAlignment.TopRight;
432
            // 
433
            // gBoxPuzzlePieces
248
            // gBoxPuzzlePieces
434
            // 
249
            // 
435
            this.gBoxPuzzlePieces.Controls.Add(this.txtPuzzleSideType);
250
            this.gBoxPuzzlePieces.Controls.Add(this.txtPuzzleSideType);
...
...
517
            this.labCamMoveDirection.TabIndex = 16;
332
            this.labCamMoveDirection.TabIndex = 16;
518
            this.labCamMoveDirection.Text = "-";
333
            this.labCamMoveDirection.Text = "-";
519
            // 
334
            // 
335
            // histogram
336
            // 
337
            this.histogram.Location = new System.Drawing.Point(339, 406);
338
            this.histogram.Name = "histogram";
339
            this.histogram.Size = new System.Drawing.Size(647, 225);
340
            this.histogram.TabIndex = 14;
341
            // 
342
            // numUpDownThresholdHigh
343
            // 
344
            this.numUpDownThresholdHigh.Location = new System.Drawing.Point(172, 19);
345
            this.numUpDownThresholdHigh.Maximum = new decimal(new int[] {
346
            255,
347
            0,
348
            0,
349
            0});
350
            this.numUpDownThresholdHigh.Name = "numUpDownThresholdHigh";
351
            this.numUpDownThresholdHigh.Size = new System.Drawing.Size(40, 20);
352
            this.numUpDownThresholdHigh.TabIndex = 9;
353
            this.numUpDownThresholdHigh.Value = new decimal(new int[] {
354
            100,
355
            0,
356
            0,
357
            0});
358
            this.numUpDownThresholdHigh.Visible = false;
359
            this.numUpDownThresholdHigh.ValueChanged += new System.EventHandler(this.numUpDownThresholdHigh_ValueChanged);
360
            // 
361
            // labThresholdValHigh
362
            // 
363
            this.labThresholdValHigh.AutoSize = true;
364
            this.labThresholdValHigh.Location = new System.Drawing.Point(128, 21);
365
            this.labThresholdValHigh.Name = "labThresholdValHigh";
366
            this.labThresholdValHigh.Size = new System.Drawing.Size(35, 13);
367
            this.labThresholdValHigh.TabIndex = 8;
368
            this.labThresholdValHigh.Text = "Felső:";
369
            this.labThresholdValHigh.Visible = false;
370
            // 
371
            // rBtnThresholdSimple
372
            // 
373
            this.rBtnThresholdSimple.AutoSize = true;
374
            this.rBtnThresholdSimple.Location = new System.Drawing.Point(6, 19);
375
            this.rBtnThresholdSimple.Name = "rBtnThresholdSimple";
376
            this.rBtnThresholdSimple.Size = new System.Drawing.Size(68, 17);
377
            this.rBtnThresholdSimple.TabIndex = 0;
378
            this.rBtnThresholdSimple.Text = "Egyszerű";
379
            this.rBtnThresholdSimple.UseVisualStyleBackColor = true;
380
            this.rBtnThresholdSimple.CheckedChanged += new System.EventHandler(this.rBtnThresholdSimple_CheckedChanged);
381
            // 
382
            // rBtnThresholdDouble
383
            // 
384
            this.rBtnThresholdDouble.AutoSize = true;
385
            this.rBtnThresholdDouble.Location = new System.Drawing.Point(80, 19);
386
            this.rBtnThresholdDouble.Name = "rBtnThresholdDouble";
387
            this.rBtnThresholdDouble.Size = new System.Drawing.Size(86, 17);
388
            this.rBtnThresholdDouble.TabIndex = 0;
389
            this.rBtnThresholdDouble.Text = "Hiszterézises";
390
            this.rBtnThresholdDouble.UseVisualStyleBackColor = true;
391
            this.rBtnThresholdDouble.CheckedChanged += new System.EventHandler(this.rBtnThresholdDouble_CheckedChanged);
392
            // 
393
            // rBtnThresholdOtsu
394
            // 
395
            this.rBtnThresholdOtsu.AutoSize = true;
396
            this.rBtnThresholdOtsu.Checked = true;
397
            this.rBtnThresholdOtsu.Location = new System.Drawing.Point(172, 19);
398
            this.rBtnThresholdOtsu.Name = "rBtnThresholdOtsu";
399
            this.rBtnThresholdOtsu.Size = new System.Drawing.Size(47, 17);
400
            this.rBtnThresholdOtsu.TabIndex = 0;
401
            this.rBtnThresholdOtsu.TabStop = true;
402
            this.rBtnThresholdOtsu.Text = "Otsu";
403
            this.rBtnThresholdOtsu.UseVisualStyleBackColor = true;
404
            this.rBtnThresholdOtsu.CheckedChanged += new System.EventHandler(this.rBtnThresholdOtsu_CheckedChanged);
405
            // 
406
            // groupBox3
407
            // 
408
            this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
409
                        | System.Windows.Forms.AnchorStyles.Right)));
410
            this.groupBox3.Controls.Add(this.rBtnThresholdOtsu);
411
            this.groupBox3.Controls.Add(this.rBtnThresholdDouble);
412
            this.groupBox3.Controls.Add(this.rBtnThresholdSimple);
413
            this.groupBox3.Location = new System.Drawing.Point(6, 245);
414
            this.groupBox3.Name = "groupBox3";
415
            this.groupBox3.Size = new System.Drawing.Size(309, 49);
416
            this.groupBox3.TabIndex = 8;
417
            this.groupBox3.TabStop = false;
418
            this.groupBox3.Text = "Módszer";
419
            // 
520
            // labTeszt
420
            // labTeszt
521
            // 
421
            // 
522
            this.labTeszt.AutoSize = true;
422
            this.labTeszt.AutoSize = true;
...
...
526
            this.labTeszt.TabIndex = 16;
426
            this.labTeszt.TabIndex = 16;
527
            this.labTeszt.Text = "-";
427
            this.labTeszt.Text = "-";
528
            // 
428
            // 
529
            // histogram
429
            // picBoxCannyEdge
530
            // 
430
            // 
531
            this.histogram.Location = new System.Drawing.Point(339, 406);
431
            this.picBoxCannyEdge.Location = new System.Drawing.Point(6, 19);
532
            this.histogram.Name = "histogram";
432
            this.picBoxCannyEdge.Name = "picBoxCannyEdge";
533
            this.histogram.Size = new System.Drawing.Size(647, 225);
433
            this.picBoxCannyEdge.Size = new System.Drawing.Size(309, 220);
534
            this.histogram.TabIndex = 14;
434
            this.picBoxCannyEdge.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
435
            this.picBoxCannyEdge.TabIndex = 7;
436
            this.picBoxCannyEdge.TabStop = false;
535
            // 
437
            // 
438
            // groupBox6
439
            // 
440
            this.groupBox6.Controls.Add(this.numUpDownErodeIter);
441
            this.groupBox6.Controls.Add(this.numUpDownDilateIter);
442
            this.groupBox6.Controls.Add(this.label2);
443
            this.groupBox6.Controls.Add(this.label1);
444
            this.groupBox6.Location = new System.Drawing.Point(6, 245);
445
            this.groupBox6.Name = "groupBox6";
446
            this.groupBox6.Size = new System.Drawing.Size(308, 49);
447
            this.groupBox6.TabIndex = 9;
448
            this.groupBox6.TabStop = false;
449
            this.groupBox6.Text = "Dialtáció/Erózió iterációk száma";
450
            // 
451
            // label1
452
            // 
453
            this.label1.AutoSize = true;
454
            this.label1.Location = new System.Drawing.Point(6, 21);
455
            this.label1.Name = "label1";
456
            this.label1.Size = new System.Drawing.Size(51, 13);
457
            this.label1.TabIndex = 7;
458
            this.label1.Text = "Dilatáció:";
459
            this.label1.TextAlign = System.Drawing.ContentAlignment.TopRight;
460
            // 
461
            // label2
462
            // 
463
            this.label2.AutoSize = true;
464
            this.label2.Location = new System.Drawing.Point(121, 21);
465
            this.label2.Name = "label2";
466
            this.label2.Size = new System.Drawing.Size(39, 13);
467
            this.label2.TabIndex = 7;
468
            this.label2.Text = "Erózió:";
469
            this.label2.TextAlign = System.Drawing.ContentAlignment.TopRight;
470
            // 
471
            // numUpDownDilateIter
472
            // 
473
            this.numUpDownDilateIter.Location = new System.Drawing.Point(63, 19);
474
            this.numUpDownDilateIter.Maximum = new decimal(new int[] {
475
            1000,
476
            0,
477
            0,
478
            0});
479
            this.numUpDownDilateIter.Name = "numUpDownDilateIter";
480
            this.numUpDownDilateIter.Size = new System.Drawing.Size(40, 20);
481
            this.numUpDownDilateIter.TabIndex = 10;
482
            this.numUpDownDilateIter.Value = new decimal(new int[] {
483
            1,
484
            0,
485
            0,
486
            0});
487
            this.numUpDownDilateIter.ValueChanged += new System.EventHandler(this.numUpDownDilateIter_ValueChanged);
488
            // 
489
            // numUpDownErodeIter
490
            // 
491
            this.numUpDownErodeIter.Location = new System.Drawing.Point(178, 19);
492
            this.numUpDownErodeIter.Maximum = new decimal(new int[] {
493
            1000,
494
            0,
495
            0,
496
            0});
497
            this.numUpDownErodeIter.Name = "numUpDownErodeIter";
498
            this.numUpDownErodeIter.Size = new System.Drawing.Size(40, 20);
499
            this.numUpDownErodeIter.TabIndex = 10;
500
            this.numUpDownErodeIter.ValueChanged += new System.EventHandler(this.numUpDownErodeIter_ValueChanged);
501
            // 
502
            // numericUpDown1
503
            // 
504
            this.numericUpDown1.Location = new System.Drawing.Point(197, 315);
505
            this.numericUpDown1.Name = "numericUpDown1";
506
            this.numericUpDown1.Size = new System.Drawing.Size(40, 20);
507
            this.numericUpDown1.TabIndex = 11;
508
            this.numericUpDown1.Value = new decimal(new int[] {
509
            80,
510
            0,
511
            0,
512
            0});
513
            // 
514
            // label3
515
            // 
516
            this.label3.AutoSize = true;
517
            this.label3.Location = new System.Drawing.Point(12, 317);
518
            this.label3.Name = "label3";
519
            this.label3.Size = new System.Drawing.Size(179, 13);
520
            this.label3.TabIndex = 10;
521
            this.label3.Text = "A puzzle darab %os aránya a képen:";
522
            // 
523
            // groupBox5
524
            // 
525
            this.groupBox5.Controls.Add(this.label3);
526
            this.groupBox5.Controls.Add(this.numericUpDown1);
527
            this.groupBox5.Controls.Add(this.groupBox6);
528
            this.groupBox5.Controls.Add(this.picBoxCannyEdge);
529
            this.groupBox5.Location = new System.Drawing.Point(666, 28);
530
            this.groupBox5.Name = "groupBox5";
531
            this.groupBox5.Size = new System.Drawing.Size(320, 357);
532
            this.groupBox5.TabIndex = 11;
533
            this.groupBox5.TabStop = false;
534
            this.groupBox5.Text = "Éldetektált kép";
535
            // 
536
            // MainForm
536
            // MainForm
537
            // 
537
            // 
538
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
538
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
...
...
555
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
555
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
556
            this.menuStrip.ResumeLayout(false);
556
            this.menuStrip.ResumeLayout(false);
557
            this.menuStrip.PerformLayout();
557
            this.menuStrip.PerformLayout();
558
            ((System.ComponentModel.ISupportInitialize)(this.picBoxCannyEdge)).EndInit();
559
            this.groupBox1.ResumeLayout(false);
558
            this.groupBox1.ResumeLayout(false);
560
            ((System.ComponentModel.ISupportInitialize)(this.picBoxCamOriginal)).EndInit();
559
            ((System.ComponentModel.ISupportInitialize)(this.picBoxCamOriginal)).EndInit();
561
            this.groupBox2.ResumeLayout(false);
560
            this.groupBox2.ResumeLayout(false);
562
            this.groupBox4.ResumeLayout(false);
561
            this.groupBox4.ResumeLayout(false);
563
            this.groupBox4.PerformLayout();
562
            this.groupBox4.PerformLayout();
563
            ((System.ComponentModel.ISupportInitialize)(this.numUpDownThresholdLow)).EndInit();
564
            ((System.ComponentModel.ISupportInitialize)(this.picBoxCamBinarized)).EndInit();
565
            this.gBoxPuzzlePieces.ResumeLayout(false);
566
            this.gBoxPuzzlePieces.PerformLayout();
567
            ((System.ComponentModel.ISupportInitialize)(this.picBoxPuzzlePiece)).EndInit();
564
            ((System.ComponentModel.ISupportInitialize)(this.numUpDownThresholdHigh)).EndInit();
568
            ((System.ComponentModel.ISupportInitialize)(this.numUpDownThresholdHigh)).EndInit();
565
            ((System.ComponentModel.ISupportInitialize)(this.numUpDownThresholdLow)).EndInit();
566
            this.groupBox3.ResumeLayout(false);
569
            this.groupBox3.ResumeLayout(false);
567
            this.groupBox3.PerformLayout();
570
            this.groupBox3.PerformLayout();
568
            ((System.ComponentModel.ISupportInitialize)(this.picBoxCamBinarized)).EndInit();
571
            ((System.ComponentModel.ISupportInitialize)(this.picBoxCannyEdge)).EndInit();
569
            this.groupBox5.ResumeLayout(false);
570
            this.groupBox5.PerformLayout();
571
            ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
572
            this.groupBox6.ResumeLayout(false);
572
            this.groupBox6.ResumeLayout(false);
573
            this.groupBox6.PerformLayout();
573
            this.groupBox6.PerformLayout();
574
            ((System.ComponentModel.ISupportInitialize)(this.numUpDownDilateIter)).EndInit();
574
            ((System.ComponentModel.ISupportInitialize)(this.numUpDownErodeIter)).EndInit();
575
            ((System.ComponentModel.ISupportInitialize)(this.numUpDownErodeIter)).EndInit();
575
            ((System.ComponentModel.ISupportInitialize)(this.numUpDownDilateIter)).EndInit();
576
            ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
576
            this.gBoxPuzzlePieces.ResumeLayout(false);
577
            this.groupBox5.ResumeLayout(false);
577
            this.gBoxPuzzlePieces.PerformLayout();
578
            this.groupBox5.PerformLayout();
578
            ((System.ComponentModel.ISupportInitialize)(this.picBoxPuzzlePiece)).EndInit();
579
            this.ResumeLayout(false);
579
            this.ResumeLayout(false);
580
            this.PerformLayout();
580
            this.PerformLayout();
581
581
...
...
586
		private System.Windows.Forms.MenuStrip menuStrip;
586
		private System.Windows.Forms.MenuStrip menuStrip;
587
		private System.Windows.Forms.ToolStripMenuItem menuFile;
587
		private System.Windows.Forms.ToolStripMenuItem menuFile;
588
		private System.Windows.Forms.ToolStripMenuItem kilépésToolStripMenuItem;
588
		private System.Windows.Forms.ToolStripMenuItem kilépésToolStripMenuItem;
589
		private System.Windows.Forms.StatusStrip statusStrip;
589
        private System.Windows.Forms.StatusStrip statusStrip;
590
		private Emgu.CV.UI.ImageBox picBoxCannyEdge;
591
		private System.Windows.Forms.Timer timerOriginal;
590
		private System.Windows.Forms.Timer timerOriginal;
592
		private System.Windows.Forms.GroupBox groupBox1;
591
		private System.Windows.Forms.GroupBox groupBox1;
593
		private Emgu.CV.UI.ImageBox picBoxCamOriginal;
592
		private Emgu.CV.UI.ImageBox picBoxCamOriginal;
594
		private System.Windows.Forms.GroupBox groupBox2;
593
		private System.Windows.Forms.GroupBox groupBox2;
595
		private System.Windows.Forms.GroupBox groupBox4;
594
        private System.Windows.Forms.GroupBox groupBox4;
596
		private System.Windows.Forms.Label labThresholdValHigh;
597
		private System.Windows.Forms.NumericUpDown numUpDownThresholdHigh;
598
		private System.Windows.Forms.Label labThresholdValLow;
595
		private System.Windows.Forms.Label labThresholdValLow;
599
		private System.Windows.Forms.NumericUpDown numUpDownThresholdLow;
596
        private System.Windows.Forms.NumericUpDown numUpDownThresholdLow;
600
		private System.Windows.Forms.GroupBox groupBox3;
597
        private Emgu.CV.UI.ImageBox picBoxCamBinarized;
601
		private System.Windows.Forms.RadioButton rBtnThresholdOtsu;
602
		private System.Windows.Forms.RadioButton rBtnThresholdDouble;
603
		private System.Windows.Forms.RadioButton rBtnThresholdSimple;
604
		private Emgu.CV.UI.ImageBox picBoxCamBinarized;
605
		private System.Windows.Forms.GroupBox groupBox5;
606
		private System.Windows.Forms.GroupBox groupBox6;
607
		private System.Windows.Forms.NumericUpDown numUpDownErodeIter;
608
		private System.Windows.Forms.NumericUpDown numUpDownDilateIter;
609
		private System.Windows.Forms.Label label2;
610
        private System.Windows.Forms.Label label1;
611
		private System.Windows.Forms.Label label3;
612
        private System.Windows.Forms.NumericUpDown numericUpDown1;
613
		private System.Windows.Forms.ToolStripMenuItem menuHisztogram;
598
		private System.Windows.Forms.ToolStripMenuItem menuHisztogram;
614
		private System.Windows.Forms.GroupBox gBoxPuzzlePieces;
599
		private System.Windows.Forms.GroupBox gBoxPuzzlePieces;
615
		private System.Windows.Forms.ListBox lbPuzzlePieces;
600
		private System.Windows.Forms.ListBox lbPuzzlePieces;
...
...
622
        private System.Windows.Forms.Button btnAssembling;
607
        private System.Windows.Forms.Button btnAssembling;
623
        private System.Windows.Forms.Label label5;
608
        private System.Windows.Forms.Label label5;
624
        private System.Windows.Forms.Label labCamMoveDirection;
609
        private System.Windows.Forms.Label labCamMoveDirection;
610
        private Emgu.CV.UI.HistogramBox histogram;
611
        private System.Windows.Forms.Label labThresholdValHigh;
612
        private System.Windows.Forms.NumericUpDown numUpDownThresholdHigh;
613
        private System.Windows.Forms.GroupBox groupBox3;
614
        private System.Windows.Forms.RadioButton rBtnThresholdOtsu;
615
        private System.Windows.Forms.RadioButton rBtnThresholdDouble;
616
        private System.Windows.Forms.RadioButton rBtnThresholdSimple;
625
        private System.Windows.Forms.Label labTeszt;
617
        private System.Windows.Forms.Label labTeszt;
626
        private Emgu.CV.UI.HistogramBox histogram;
618
        private Emgu.CV.UI.ImageBox picBoxCannyEdge;
619
        private System.Windows.Forms.GroupBox groupBox6;
620
        private System.Windows.Forms.NumericUpDown numUpDownErodeIter;
621
        private System.Windows.Forms.NumericUpDown numUpDownDilateIter;
622
        private System.Windows.Forms.Label label2;
623
        private System.Windows.Forms.Label label1;
624
        private System.Windows.Forms.NumericUpDown numericUpDown1;
625
        private System.Windows.Forms.Label label3;
626
        private System.Windows.Forms.GroupBox groupBox5;
627
	}
627
	}
628
}
628
}
629
629

Updated trunk/JPS_PuzzleDetectorWithCam/JPS_PuzzleDetectorWithCam/obj/x86/Debug/JPS_PuzzleDetectorWithCam.csproj.FileListAbsolute.txt Download diff

6768
30
D:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\bin\Debug\JPS_PuzzleDetectorWithCam.exe
30
D:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\bin\Debug\JPS_PuzzleDetectorWithCam.exe
31
D:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\bin\Debug\JPS_PuzzleDetectorWithCam.pdb
31
D:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\bin\Debug\JPS_PuzzleDetectorWithCam.pdb
32
D:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\bin\Debug\ZedGraph.dll
32
D:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\bin\Debug\ZedGraph.dll
33
D:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\bin\Debug\Emgu.CV.xml
34
D:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\bin\Debug\Emgu.CV.UI.xml
35
D:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\bin\Debug\Emgu.Util.xml
36
E:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\obj\x86\Debug\JPS_PuzzleDetectorWithCam.HistogramForm.resources
33
E:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\obj\x86\Debug\JPS_PuzzleDetectorWithCam.HistogramForm.resources
37
D:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\obj\x86\Debug\JPS_PuzzleDetectorWithCam.HistogramForm.resources
34
D:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\obj\x86\Debug\JPS_PuzzleDetectorWithCam.HistogramForm.resources
38
D:\svn\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\obj\x86\Debug\JPS_PuzzleDetectorWithCam.exe
35
D:\svn\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\obj\x86\Debug\JPS_PuzzleDetectorWithCam.exe
...
...
101
d:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\bin\Debug\Accord.Statistics.xml
98
d:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\bin\Debug\Accord.Statistics.xml
102
d:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\bin\Debug\Accord.pdb
99
d:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\bin\Debug\Accord.pdb
103
d:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\bin\Debug\Accord.xml
100
d:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\bin\Debug\Accord.xml
101
D:\BMF\JPS\trunk\JPS_PuzzleDetectorWithCam\JPS_PuzzleDetectorWithCam\bin\Debug\ZedGraph.xml

Added trunk/JPS_PuzzleDetectorWithCam/JPS_PuzzleDetectorWithCam/obj/x86/Release/GenerateResource.read.1.tlog

Show contents

Added trunk/JPS_PuzzleDetectorWithCam/JPS_PuzzleDetectorWithCam/obj/x86/Release/GenerateResource.write.1.tlog

Show contents

Added trunk/JPS_PuzzleDetectorWithCam/JPS_PuzzleDetectorWithCam/obj/x86/Release/JPS_PuzzleDetectorWithCam.csproj.FileListAbsolute.txt

Show contents

Updated trunk/JPS_PuzzleDetectorWithCam/JPS_PuzzleDetectorWithCam/PuzzleFunction.cs Download diff

6768
8
using Emgu.CV.CvEnum;
8
using Emgu.CV.CvEnum;
9
using System.IO;
9
using System.IO;
10
using System.Diagnostics;
10
using System.Diagnostics;
11
using System.Threading.Tasks;
11
12
12
namespace JPS_PuzzleDetectorWithCam
13
namespace JPS_PuzzleDetectorWithCam
13
{
14
{
...
...
60
		public static void Cut(Image<Bgr, Byte> srcImage, List<CustomContour> contours)
61
		public static void Cut(Image<Bgr, Byte> srcImage, List<CustomContour> contours)
61
		{
62
		{
62
			ClearPuzzlePieces();
63
			ClearPuzzlePieces();
63
			for (int i = 0; i < contours.Count; i++)
64
            
64
			{
65
            Stopwatch sw = new Stopwatch();
66
            sw.Restart();
67
            for (int i = 0; i < contours.Count; i++)
68
            {
65
                MCvBox2D minAreaRect = contours[i].OriginalContour.GetMinAreaRect();
69
                MCvBox2D minAreaRect = contours[i].OriginalContour.GetMinAreaRect();
66
                minAreaRect.size = new SizeF((int)(minAreaRect.size.Width*1.5), (int)(minAreaRect.size.Height*1.5));
70
                minAreaRect.size = new SizeF((int)(minAreaRect.size.Width * 1.5), (int)(minAreaRect.size.Height * 1.5));
67
71
68
                Image<Bgr, Byte> imgCurrPiece = new Image<Bgr, byte>(
72
                Image<Bgr, Byte> imgCurrPiece = new Image<Bgr, byte>(
69
                    new Size((int)minAreaRect.size.Width, (int)minAreaRect.size.Height)
73
                    new Size((int)minAreaRect.size.Width, (int)minAreaRect.size.Height)
...
...
76
                        new PuzzlePiece(imgCurrPiece, puzzleCounter++.ToString(), contours[i].CenterOfMass)
80
                        new PuzzlePiece(imgCurrPiece, puzzleCounter++.ToString(), contours[i].CenterOfMass)
77
                    );
81
                    );
78
                }
82
                }
79
                catch (Exception)
83
                catch (Exception ex)
80
                {
84
                {
81
                    if (puzzlePieces.Count > 1)
85
                    System.Windows.Forms.MessageBox.Show(ex.Message);
82
                    {
86
                    //if (puzzlePieces.Count > 1)
83
                        puzzlePieces.Remove(puzzlePieces.Last());
87
                    //{
84
                        puzzleCounter--;
88
                    //    puzzlePieces.Remove(puzzlePieces.Last());
85
                    }
89
                    //    puzzleCounter--;
86
                    else
90
                    //}
87
                    {
91
                    //else
88
                        ClearPuzzlePieces();
92
                    //{
89
                    }
93
                    //    ClearPuzzlePieces();
94
                    //}
90
95
91
                    //throw ex;
96
                    //throw ex;
92
                }
97
                }
93
			}
98
            }
94
		}
99
            sw.Stop();
100
        }
95
101
96
        public static List<Point> GetCorners(Image<Bgr, Byte> imgPiece, CustomContour contour)
102
        public static List<Point> GetCorners(Image<Bgr, Byte> imgPiece, CustomContour contour, List<MCvConvexityDefect> realConvexityDefects)
97
		{
103
		{
98
			List<Point> corners = new List<Point>();
104
			List<Point> corners = new List<Point>();
99
            Image<Bgr, Byte> tmpImage = new Image<Bgr, byte>(imgPiece.Bitmap);
105
            Image<Bgr, Byte> tmpImage = new Image<Bgr, byte>(imgPiece.Bitmap);
100
			using (Image<Gray, Byte> imgConvexHull = new Image<Gray, byte>(imgPiece.Size))
106
            MCvBox2D minAreaRect = contour.OriginalContour.GetMinAreaRect();
107
            Stopwatch sw = new Stopwatch();
108
            using (Image<Gray, Byte> imgConvexHull = new Image<Gray, byte>(imgPiece.Size))
101
			{
109
			{
102
				using (MemStorage memStorage = new MemStorage())
110
				using (MemStorage memStorage = new MemStorage())
103
				{
111
				{
104
					imgConvexHull.Draw(contour.OriginalContour.GetConvexHull(ORIENTATION.CV_CLOCKWISE), new Gray(255), 1);
112
                    double minAreaRectArea = minAreaRect.size.Width * minAreaRect.size.Height;
105
					corners = CornersFromConvexityDefects(contour.ConvexityDefects);
113
114
                    int diff = (int)(minAreaRectArea - contour.ConvexHull.Area);
115
116
                    tmpImage = new Image<Bgr, byte>(imgPiece.Size);
117
                    tmpImage.Draw(minAreaRect, new Bgr(System.Drawing.Color.Aqua), -1);
118
                    tmpImage.Draw(contour.OriginalContour.GetConvexHull(ORIENTATION.CV_CLOCKWISE), new Bgr(System.Drawing.Color.Beige), -1);
119
                    tmpImage.Draw(contour.OriginalContour, new Bgr(System.Drawing.Color.Purple), -1);
120
                    sw.Restart();
121
122
                    //SetRealConvexityDefects(contour.ConvexityDefects, contour.CenterOfMass);
123
124
                    if (diff < minAreaRectArea * 0.1)
125
                        corners = CornersFromNonOutboundedPieces(minAreaRect, contour);
126
                    else
127
                        corners = CornersFromConvexityDefects(contour, realConvexityDefects, ImageFunction.Binarize(imgPiece, 152));
128
                    sw.Stop();
129
130
                    Parallel.For(0, corners.Count, i => {
131
                        tmpImage.Draw(new CircleF(corners[i], 3), new Bgr(0, 0, 255), -1);
132
                    });
133
134
                    imgConvexHull.Draw(contour.OriginalContour, new Gray(255), 1); 
106
				}
135
				}
107
136
108
                
137
                
109
                if (corners.Count != 4)
138
                if (corners.Count != 4)
110
				{
139
				{
111
					PointF[][] goodFeatures = imgConvexHull.GoodFeaturesToTrack(10, .1, imgConvexHull.Width / 3, 5);
140
                    sw.Restart();
112
					imgConvexHull.FindCornerSubPix(goodFeatures, new Size(5, 5), new Size(-1, -1), new MCvTermCriteria(100));
141
                    List<Point> minAreaRectCorners = new List<Point>();
142
                    minAreaRectCorners.Add(new Point(
143
                        (int)minAreaRect.center.X - (int)minAreaRect.size.Width / 2,
144
                        (int)minAreaRect.center.Y - (int)minAreaRect.size.Height / 2));
145
                    minAreaRectCorners.Add(new Point(
146
                        (int)minAreaRect.center.X - (int)minAreaRect.size.Width / 2,
147
                        (int)minAreaRect.center.Y + (int)minAreaRect.size.Height / 2));
148
                    minAreaRectCorners.Add(new Point(
149
                        (int)minAreaRect.center.X + (int)minAreaRect.size.Width / 2,
150
                        (int)minAreaRect.center.Y + (int)minAreaRect.size.Height / 2));
151
                    minAreaRectCorners.Add(new Point(
152
                        (int)minAreaRect.center.X + (int)minAreaRect.size.Width / 2,
153
                        (int)minAreaRect.center.Y - (int)minAreaRect.size.Height / 2));
113
154
114
                    List<PointF> usefulGoodFeatures = goodFeatures[0].ToList();
155
                    List<Point> nearestCorners = new List<Point>();
115
156
116
                    for (int i = 0; i < corners.Count; i++)
157
                    Parallel.For(0, corners.Count, i =>
117
                    {
158
                    {
118
                        tmpImage.Draw(new CircleF(corners[i], 3), new Bgr(0,255,255), -1);
159
                        List<int> distOfCorners = new List<int>();
160
                        for (int j = 0; j < minAreaRectCorners.Count; j++)
161
                        {
162
                            distOfCorners.Add(
163
                                (corners[i].X - minAreaRectCorners[j].X) * (corners[i].X - minAreaRectCorners[j].X) +
164
                                (corners[i].Y - minAreaRectCorners[j].Y) * (corners[i].Y - minAreaRectCorners[j].Y)
165
                                );
166
                        }
167
                        nearestCorners.Add(minAreaRectCorners[distOfCorners.IndexOf(distOfCorners.Min())]);
168
                    });
169
170
                    for (int i = 0; i < nearestCorners.Count; i++)
171
                    {
172
                        minAreaRectCorners.Remove(nearestCorners[i]);
119
                    }
173
                    }
120
174
121
                    double range = 5.0;
175
					PointF[][] goodFeatures = imgConvexHull.GoodFeaturesToTrack(30, .1, 10, 5);
176
					//imgConvexHull.FindCornerSubPix(goodFeatures, new Size(5, 5), new Size(-1, -1), new MCvTermCriteria(100));
122
177
123
                    for (int i = 0; i < corners.Count; i++)
178
                    List<PointF> usefulGoodFeatures = goodFeatures[0].ToList();
179
180
                    Parallel.For(0, usefulGoodFeatures.Count, i =>
124
                    {
181
                    {
125
                        for (int j = 0; j < goodFeatures[0].Count(); j++)
182
                        tmpImage.Draw(new CircleF(usefulGoodFeatures[i], 1), new Bgr(0, 255, 0), -1);
126
                        {
183
                    });
127
                            tmpImage.Draw(new CircleF(goodFeatures[0][j], 3), new Bgr(0, 0, 255), -1);
128
                            if (goodFeatures[0][j].X > corners[i].X - range && goodFeatures[0][j].X < corners[i].X + range &&
129
                                goodFeatures[0][j].Y > corners[i].Y - range && goodFeatures[0][j].Y < corners[i].Y + range)
130
                                usefulGoodFeatures.Remove(goodFeatures[0][j]);
131
                        }
132
                    }
133
184
134
                    range = 1.0;
185
                    List<int> distances = new List<int>();
135
                    List<Point> tmpUsefulCorners = new List<Point>();
136
                    List<Point> contourPoints = contour.GetUnsortedContourPoints();
186
                    List<Point> contourPoints = contour.GetUnsortedContourPoints();
187
                    List<Point> nearestContourPoints;
188
                    Point usefulGoodFeature;
189
                    int range = 3;
137
190
138
                    tmpImage = new Image<Bgr, byte>(imgPiece.Bitmap);
191
                    for (int i = 0; i < minAreaRectCorners.Count; i++)
192
                    {
193
                        distances = new List<int>();
194
                        for (int j = 0; j < usefulGoodFeatures.Count; j++)
195
                        {
196
                            distances.Add(
197
                                (minAreaRectCorners[i].X - (int)usefulGoodFeatures[j].X) * (minAreaRectCorners[i].X - (int)usefulGoodFeatures[j].X) +
198
                                (minAreaRectCorners[i].Y - (int)usefulGoodFeatures[j].Y) * (minAreaRectCorners[i].Y - (int)usefulGoodFeatures[j].Y)
199
                                );
200
                        }
139
201
140
                    for (int i = 0; i < usefulGoodFeatures.Count; i++)
202
                        nearestContourPoints = new List<Point>();
141
                    {
203
                        usefulGoodFeature = Point.Round(usefulGoodFeatures[distances.IndexOf(distances.Min())]);
142
                        for (int j = 0; j < contourPoints.Count; j++)
204
                        for (int j = 0; j < contourPoints.Count; j++)
143
                        {
205
                        {
144
                            if (usefulGoodFeatures[i].X > contourPoints[j].X - range && usefulGoodFeatures[i].X < contourPoints[j].X + range &&
206
                            if (usefulGoodFeature.X > contourPoints[j].X - range &&
145
                                usefulGoodFeatures[i].Y > contourPoints[j].Y - range && usefulGoodFeatures[i].Y < contourPoints[j].Y + range)
207
                                usefulGoodFeature.X < contourPoints[j].X + range &&
208
                                usefulGoodFeature.Y > contourPoints[j].Y - range &&
209
                                usefulGoodFeature.Y < contourPoints[j].Y + range)
146
                            {
210
                            {
147
                                tmpUsefulCorners.Add(contourPoints[j]);
211
                                //corners.Add(contourPoints[k]);
148
                                tmpImage.Draw(new CircleF(contourPoints[j], 3), new Bgr(0, 0, 255), 1);
212
                                //tmpImage.Draw(new CircleF(contourPoints[k], 3), new Bgr(System.Drawing.Color.Yellow), 1);
213
                                nearestContourPoints.Add(contourPoints[j]);
149
                            }
214
                            }
150
                        }
215
                        }
151
                    }
152
216
153
                    int currDistance = 0;
217
                        distances = new List<int>();
154
                    List<Point> usefulCorners = new List<Point>();
218
                        for (int j = 0; j < nearestContourPoints.Count; j++)
155
                    usefulCorners.AddRange(tmpUsefulCorners);
156
                    for (int i = 0; i < tmpUsefulCorners.Count - 1; i++)
157
                    {
158
                        currDistance =
159
                            (tmpUsefulCorners[i].X - tmpUsefulCorners[i + 1].X) * (tmpUsefulCorners[i].X - tmpUsefulCorners[i + 1].X) +
160
                            (tmpUsefulCorners[i].Y - tmpUsefulCorners[i + 1].Y) * (tmpUsefulCorners[i].Y - tmpUsefulCorners[i + 1].Y);
161
162
                        if (currDistance < 10)
163
                        {
219
                        {
164
                            usefulCorners.Remove(tmpUsefulCorners[i]);
220
                            distances.Add(
165
                            tmpImage.Draw(new CircleF(tmpUsefulCorners[i + 1], 5), new Bgr(0, 255, 255), 1);
221
                                (nearestContourPoints[i].X - (int)usefulGoodFeature.X) * (nearestContourPoints[i].X - (int)usefulGoodFeature.X) +
222
                                (nearestContourPoints[i].Y - (int)usefulGoodFeature.Y) * (nearestContourPoints[i].Y - (int)usefulGoodFeature.Y)
223
                                );
166
                        }
224
                        }
225
226
                        corners.Add(nearestContourPoints[distances.IndexOf(distances.Min())]);
227
                        tmpImage.Draw(new CircleF(corners.Last(), 3), new Bgr(System.Drawing.Color.Yellow), 1);
167
                    }
228
                    }
168
                    tmpImage.Draw(new CircleF(corners[0], 3), new Bgr(0, 255, 0), 1);
169
                    tmpImage.Draw(new CircleF(corners[1], 3), new Bgr(0, 255, 0), 1);
170
229
171
                    if (usefulCorners.Count > 2)
230
                    //for (int i = 0; i < nearestGoodFeatures.Count; i++)
172
                    {
231
                    //{
173
                        List<int> distances = new List<int>();
232
                    //    tmpImage.Draw(new CircleF(nearestGoodFeatures[i], 1), new Bgr(255, 255, 255), -1);
233
                    //}
234
                    tmpImage.Draw(contour.OriginalContour, new Bgr(System.Drawing.Color.DarkOrange), 1);
235
                    sw.Stop();
174
236
237
                    //double range = 5.0;
175
238
176
                        for (int i = 0; i < usefulCorners.Count; i++)
239
                    //for (int i = 0; i < corners.Count; i++)
177
                        {
240
                    //{
178
                            distances.Add(
241
                    //    for (int j = 0; j < goodFeatures[0].Count(); j++)
179
                                (corners[0].X - usefulCorners[i].X) * (corners[0].X - usefulCorners[i].X) +
242
                    //    {
180
                                (corners[0].Y - usefulCorners[i].Y) * (corners[0].Y - usefulCorners[i].Y));
243
                    //        tmpImage.Draw(new CircleF(goodFeatures[0][j], 3), new Bgr(0, 0, 255), -1);
181
                        }
244
                    //        if (goodFeatures[0][j].X > corners[i].X - range && goodFeatures[0][j].X < corners[i].X + range &&
245
                    //            goodFeatures[0][j].Y > corners[i].Y - range && goodFeatures[0][j].Y < corners[i].Y + range)
246
                    //            usefulGoodFeatures.Remove(goodFeatures[0][j]);
247
                    //    }
248
                    //}
182
249
183
                        while (usefulCorners.Count != 2)
250
                    //range = 1.0;
184
                        {
251
                    //List<Point> tmpUsefulCorners = new List<Point>();
185
                            usefulCorners.RemoveAt(distances.IndexOf(distances.Min()));
252
                    //List<Point> contourPoints = contour.GetUnsortedContourPoints();
186
                            distances.Remove(distances.Min());
187
                        }
188
                    }
189
253
190
                    corners.AddRange(usefulCorners);
254
                    //tmpImage = new Image<Bgr, byte>(imgPiece.Bitmap);
255
256
                    //for (int i = 0; i < usefulGoodFeatures.Count; i++)
257
                    //{
258
                    //    for (int j = 0; j < contourPoints.Count; j++)
259
                    //    {
260
                    //        if (usefulGoodFeatures[i].X > contourPoints[j].X - range && usefulGoodFeatures[i].X < contourPoints[j].X + range &&
261
                    //            usefulGoodFeatures[i].Y > contourPoints[j].Y - range && usefulGoodFeatures[i].Y < contourPoints[j].Y + range)
262
                    //        {
263
                    //            tmpUsefulCorners.Add(contourPoints[j]);
264
                    //            tmpImage.Draw(new CircleF(contourPoints[j], 3), new Bgr(0, 0, 255), 1);
265
                    //        }
266
                    //    }
267
                    //}
268
269
                    //int currDistance = 0;
270
                    //List<Point> usefulCorners = new List<Point>();
271
                    //usefulCorners.AddRange(tmpUsefulCorners);
272
                    //for (int i = 0; i < tmpUsefulCorners.Count - 1; i++)
273
                    //{
274
                    //    currDistance =
275
                    //        (tmpUsefulCorners[i].X - tmpUsefulCorners[i + 1].X) * (tmpUsefulCorners[i].X - tmpUsefulCorners[i + 1].X) +
276
                    //        (tmpUsefulCorners[i].Y - tmpUsefulCorners[i + 1].Y) * (tmpUsefulCorners[i].Y - tmpUsefulCorners[i + 1].Y);
277
278
                    //    if (currDistance < 10)
279
                    //    {
280
                    //        usefulCorners.Remove(tmpUsefulCorners[i]);
281
                    //        tmpImage.Draw(new CircleF(tmpUsefulCorners[i + 1], 5), new Bgr(0, 255, 255), 1);
282
                    //    }
283
                    //}
284
                    //tmpImage.Draw(new CircleF(corners[0], 3), new Bgr(0, 255, 0), 1);
285
                    //tmpImage.Draw(new CircleF(corners[1], 3), new Bgr(0, 255, 0), 1);
286
287
                    //if (usefulCorners.Count > 2)
288
                    //{
289
                    //    List<int> distances = new List<int>();
290
291
292
                    //    for (int i = 0; i < usefulCorners.Count; i++)
293
                    //    {
294
                    //        distances.Add(
295
                    //            (corners[0].X - usefulCorners[i].X) * (corners[0].X - usefulCorners[i].X) +
296
                    //            (corners[0].Y - usefulCorners[i].Y) * (corners[0].Y - usefulCorners[i].Y));
297
                    //    }
298
299
                    //    while (usefulCorners.Count != 2)
300
                    //    {
301
                    //        usefulCorners.RemoveAt(distances.IndexOf(distances.Min()));
302
                    //        distances.Remove(distances.Min());
303
                    //    }
304
                    //}
305
306
                    //corners.AddRange(usefulCorners);
191
				}
307
				}
192
			}
308
			}
193
309
194
			return corners;
310
			return corners;
195
		}
311
		}
196
312
197
        private static List<MCvConvexityDefect> realConvexityDefects = new List<MCvConvexityDefect>();
313
        //private static List<MCvConvexityDefect> realConvexityDefects = new List<MCvConvexityDefect>();
198
		private static List<Point> CornersFromConvexityDefects(List<MCvConvexityDefect> convexivityDefects)
314
        //private static void SetRealConvexityDefects(List<MCvConvexityDefect> convexityDefects, Point centerOfMass)
315
        //{
316
        //    float avgOfDepths = 0;
317
        //    for (int i = 0; i < convexityDefects.Count; i++)
318
        //        avgOfDepths += convexityDefects[i].Depth;
319
        //    avgOfDepths /= convexityDefects.Count;
320
321
        //    realConvexityDefects = new List<MCvConvexityDefect>();
322
323
        //    foreach (MCvConvexityDefect defect in convexityDefects)
324
        //        if (defect.Depth > avgOfDepths)
325
        //            realConvexityDefects.Add(defect);
326
            
327
        //}
328
329
		private static List<Point> CornersFromConvexityDefects(CustomContour contour, List<MCvConvexityDefect> realConvexityDefects, Image<Gray, Byte> currPiece)
199
		{
330
		{
331
            List<MCvConvexityDefect> convexivityDefects = contour.ConvexityDefects;
332
            Point centerOfMass = contour.CenterOfMass;
333
200
			List<Point> cornerPoints = new List<Point>();
334
			List<Point> cornerPoints = new List<Point>();
201
335
202
			float avgOfDepths = 0;
336
            //float avgOfDepths = 0;
203
			for (int i = 0; i < convexivityDefects.Count; i++)
337
            //for (int i = 0; i < convexivityDefects.Count; i++)
204
				avgOfDepths += convexivityDefects[i].Depth;
338
            //    avgOfDepths += convexivityDefects[i].Depth;
205
			avgOfDepths /= convexivityDefects.Count;
339
            //avgOfDepths /= convexivityDefects.Count;
206
340
207
			List<MCvConvexityDefect> goodConvexivityDefects = new List<MCvConvexityDefect>();
341
            //List<MCvConvexityDefect> goodConvexivityDefects = new List<MCvConvexityDefect>();
208
            //Image<Bgr, Byte> tmpImage = new Image<Bgr, byte>(currPiece.ImgThresholdedPiece.Bitmap);
342
            List<Point> possibleCornerPoints = new List<Point>();
209
			foreach (MCvConvexityDefect defect in convexivityDefects)
210
                if (defect.Depth > avgOfDepths)
211
                {
212
                    goodConvexivityDefects.Add(defect);
213
                    //tmpImage.Draw(new CircleF(defect.StartPoint, 3), new Bgr(255, 0, 0), 1);
214
                    //tmpImage.Draw(new CircleF(defect.DepthPoint, 3), new Bgr(0, 255, 0), 1);
215
                    //tmpImage.Draw(new CircleF(defect.EndPoint, 3), new Bgr(0, 0, 255), 1);
216
                }
217
343
218
            realConvexityDefects = goodConvexivityDefects;
344
            Image<Bgr, Byte> tmpImage = new Image<Bgr, byte>(currPiece.Bitmap);
345
            tmpImage.Draw(new Cross2DF(centerOfMass, 5,5), new Bgr(0,255,0), 1);
219
346
220
			avgOfDepths = 0;
347
            List<double> distancesOfCenterToDepths = new List<double>();
221
			for (int i = 0; i < goodConvexivityDefects.Count; i++)
222
				avgOfDepths += goodConvexivityDefects[i].Depth;
223
			avgOfDepths /= goodConvexivityDefects.Count;
224
348
225
            //avgOfDepths += 1;
349
            foreach (MCvConvexityDefect defect in realConvexityDefects)
226
            //avgOfDepths = (float)Math.Ceiling(avgOfDepths);
227
            List<double> avgDevOfDepts = new List<double>();
228
            double currDev = 0;
229
            double avgOfDev = 0;
230
            for (int i = 0; i < goodConvexivityDefects.Count; i++)
231
            {
350
            {
232
                currDev = avgOfDepths - goodConvexivityDefects[i].Depth;
351
                distancesOfCenterToDepths.Add(
233
                avgDevOfDepts.Add(currDev);
352
                    (centerOfMass.X - defect.DepthPoint.X) * (centerOfMass.X - (int)defect.DepthPoint.X) +
234
                avgOfDev += Math.Abs(currDev);
353
                    (centerOfMass.Y - defect.DepthPoint.Y) * (centerOfMass.Y - (int)defect.DepthPoint.Y)
354
                    );
355
                tmpImage.Draw(new CircleF(defect.StartPoint, 3), new Bgr(255, 0, 0), 1);
356
                tmpImage.Draw(new CircleF(defect.DepthPoint, 3), new Bgr(0, 255, 0), 1);
357
                tmpImage.Draw(new CircleF(defect.EndPoint, 3), new Bgr(0, 0, 255), 1);
235
            }
358
            }
236
            avgOfDev /= goodConvexivityDefects.Count;
237
            avgOfDev *= -1;
238
359
239
			List<Point> possibleCornerPoints = new List<Point>();
360
            double avgOfCenterToDepth = distancesOfCenterToDepths.Average() * 0.85;
240
361
241
            //tmpImage = new Image<Bgr, byte>(currPiece.ImgThresholdedPiece.Bitmap);
362
            for (int i = 0; i < realConvexityDefects.Count; i++)
242
            for (int i = 0; i < goodConvexivityDefects.Count; i++)
243
            {
363
            {
244
                if (avgDevOfDepts[i] > avgOfDev && goodConvexivityDefects[i].Depth < avgOfDepths * 1.12)
364
                if (distancesOfCenterToDepths[i] > avgOfCenterToDepth)
245
                {
365
                {
246
                    possibleCornerPoints.Add(goodConvexivityDefects[i].StartPoint);
366
                    //good convexity defects-be kell ezeket betenni!!!
247
                    possibleCornerPoints.Add(goodConvexivityDefects[i].EndPoint);
367
                    //realConvexityDefects.Add(goodConvexivityDefects[i]);
248
368
                    possibleCornerPoints.Add(realConvexityDefects[i].StartPoint);
249
                    //tmpImage.Draw(new CircleF(goodConvexivityDefects[i].StartPoint, 3), new Bgr(255, 0, 0), 1);
369
                    possibleCornerPoints.Add(realConvexityDefects[i].DepthPoint);
250
                    //tmpImage.Draw(new CircleF(goodConvexivityDefects[i].EndPoint, 3), new Bgr(0, 255, 0), 1); 
370
                    possibleCornerPoints.Add(realConvexityDefects[i].EndPoint);
371
                    tmpImage.Draw(new CircleF(realConvexityDefects[i].DepthPoint, 3), new Bgr(0, 255, 0), -1);
251
                }
372
                }
252
            }
373
            }
253
374
254
			List<double> distances = new List<double>();
375
            //goodConvexivityDefects = realConvexityDefects;
255
            for (int i = 0; i < possibleCornerPoints.Count; i++)
376
            ////realConvexityDefects = goodConvexivityDefects;
256
			{
257
                if (i == possibleCornerPoints.Count - 1)
258
                    distances.Add(Math.Floor(Math.Sqrt(
259
                        (possibleCornerPoints[i].X - possibleCornerPoints[0].X) * (possibleCornerPoints[i].X - possibleCornerPoints[0].X) +
260
                        (possibleCornerPoints[i].Y - possibleCornerPoints[0].Y) * (possibleCornerPoints[i].Y - possibleCornerPoints[0].Y))));
261
                else
262
                    distances.Add(Math.Floor(Math.Sqrt(
263
                        (possibleCornerPoints[i + 1].X - possibleCornerPoints[i].X) * (possibleCornerPoints[i + 1].X - possibleCornerPoints[i].X) +
264
                        (possibleCornerPoints[i + 1].Y - possibleCornerPoints[i].Y) * (possibleCornerPoints[i + 1].Y - possibleCornerPoints[i].Y))));
265
			}
266
377
267
			double avgOfDistances = distances.Average();
378
            //avgOfDepths = 0;
379
            //for (int i = 0; i < goodConvexivityDefects.Count; i++)
380
            //    avgOfDepths += goodConvexivityDefects[i].Depth;
381
            //avgOfDepths /= goodConvexivityDefects.Count;
268
382
269
            List<double> avgDevOfDistances = new List<double>();
383
            ////avgOfDepths += 1;
270
            currDev = 0;
384
            ////avgOfDepths = (float)Math.Ceiling(avgOfDepths);
271
            avgOfDev = 0;
385
            //List<double> avgDevOfDepts = new List<double>();
272
            for (int i = 0; i < distances.Count; i++)
386
            //double currDev = 0;
387
            //double avgOfDev = 0;
388
            //for (int i = 0; i < goodConvexivityDefects.Count; i++)
389
            //{
390
            //    currDev = avgOfDepths - goodConvexivityDefects[i].Depth;
391
            //    avgDevOfDepts.Add(currDev);
392
            //    avgOfDev += Math.Abs(currDev);
393
            //}
394
            //avgOfDev /= goodConvexivityDefects.Count;
395
            //avgOfDev *= -1;
396
397
            //List<Point> possibleCornerPoints = new List<Point>();
398
399
            //tmpImage = new Image<Bgr, byte>(currPiece.Bitmap);
400
            //for (int i = 0; i < goodConvexivityDefects.Count; i++)
401
            //{
402
            //    if (avgDevOfDepts[i] > avgOfDev * 1.05 && goodConvexivityDefects[i].Depth < avgOfDepths * 1.12)
403
            //    {
404
            //        possibleCornerPoints.Add(goodConvexivityDefects[i].StartPoint);
405
            //        possibleCornerPoints.Add(goodConvexivityDefects[i].DepthPoint);
406
            //        possibleCornerPoints.Add(goodConvexivityDefects[i].EndPoint);
407
408
            //        tmpImage.Draw(new CircleF(goodConvexivityDefects[i].StartPoint, 3), new Bgr(255, 0, 0), 1);
409
            //        tmpImage.Draw(new CircleF(goodConvexivityDefects[i].DepthPoint, 3), new Bgr(0, 255, 0), 1);
410
            //        tmpImage.Draw(new CircleF(goodConvexivityDefects[i].EndPoint, 3), new Bgr(0, 0, 255), 1);
411
            //    }
412
            //}
413
414
            // !!Uj sarok kivalaszto algoritmus!!
415
            #region sarok kivalasztas
416
            double distA, distB = 0;
417
            Point start, depth, end;
418
            List<Point> goodCornerPoints = new List<Point>();
419
            tmpImage = new Image<Bgr, byte>(currPiece.Bitmap);
420
            for (int i = 0; i < possibleCornerPoints.Count; i += 3)
273
            {
421
            {
274
                currDev = avgOfDistances - distances[i];
275
                avgDevOfDistances.Add(currDev);
276
                avgOfDev += Math.Abs(currDev);
277
            }
278
            avgOfDev /= distances.Count;
279
422
280
            avgOfDev *= -1;
423
                // 3 fo pont felvetele az egyertelmuseg miatt
281
            for (int i = 0; i < distances.Count; i++)
424
                start = possibleCornerPoints[i];
282
            {
425
                depth = possibleCornerPoints[i + 1];
283
                if (avgDevOfDistances[i] < avgOfDev)
426
                end = possibleCornerPoints[i + 2];
427
428
                tmpImage.Draw(new CircleF(start, 3), new Bgr(255, 0, 0), -1);
429
                tmpImage.Draw(new CircleF(depth, 3), new Bgr(0, 255, 0), -1);
430
                tmpImage.Draw(new CircleF(end, 3), new Bgr(0, 0, 255), -1);
431
432
                // start es a depth pont tavolsaga
433
                distA = Math.Sqrt(
434
                    (start.X - depth.X) * (start.X - depth.X) +
435
                    (start.Y - depth.Y) * (start.Y - depth.Y));
436
                // end es a depth pont tavolsaga
437
                distB = Math.Sqrt(
438
                    (end.X - depth.X) * (end.X - depth.X) +
439
                    (end.Y - depth.Y) * (end.Y - depth.Y));
440
441
                tmpImage.Draw(new LineSegment2D(start, depth), new Bgr(System.Drawing.Color.Cyan), 2);
442
                tmpImage.Draw(new LineSegment2D(end, depth), new Bgr(System.Drawing.Color.PaleGreen), 2);
443
444
                // Ha nagyon kozel vannak egymashoz akkor ellenorizni kell, hogy biztos sarok pont-e amit annak hisz.
445
                if (Math.Abs(distA - distB) < distB * 0.2)
284
                {
446
                {
285
                    //tmpImage = new Image<Bgr, byte>(currPiece.ImgThresholdedPiece.Bitmap);
447
                    // Ha a start tavolsaga nagyobb
286
                    cornerPoints.Add(possibleCornerPoints[i]);
448
                    if (distA > distB)
449
                    {
450
                        // Kiszamoljuk az elozo/utolso ponttol valo tavolsagot
451
                        if (i != 0)
452
                        {
453
                            distA = Math.Sqrt(
454
                                (start.X - possibleCornerPoints[i - 1].X) * (start.X - possibleCornerPoints[i - 1].X) +
455
                                (start.Y - possibleCornerPoints[i - 1].Y) * (start.Y - possibleCornerPoints[i - 1].Y));
456
                            tmpImage.Draw(new LineSegment2D(start, possibleCornerPoints[i - 1]), new Bgr(System.Drawing.Color.SkyBlue), 1);
457
                        }
458
                        else
459
                        {
460
                            distA = Math.Sqrt(
461
                                (start.X - possibleCornerPoints.Last().X) * (start.X - possibleCornerPoints.Last().X) +
462
                                (start.Y - possibleCornerPoints.Last().Y) * (start.Y - possibleCornerPoints.Last().Y));
463
                            tmpImage.Draw(new LineSegment2D(start, possibleCornerPoints.Last()), new Bgr(System.Drawing.Color.Navy), 1);
464
                        }
287
465
288
                    //tmpImage.Draw(new CircleF(possibleCornerPoints[i], 3), new Bgr(255, 0, 0), 1);
466
                        // Kezdo es vegpont kozotti tavolsag
467
                        distB = Math.Sqrt(
468
                            (end.X - start.X) * (end.X - start.X) +
469
                            (end.Y - start.Y) * (end.Y - start.Y));
289
470
290
                    if (i == distances.Count - 1)
471
                        tmpImage.Draw(new LineSegment2D(end, start), new Bgr(System.Drawing.Color.Orange), 2);
291
                    {
472
292
                        cornerPoints.Add(possibleCornerPoints[0]);
473
                        // Ha a kiszamolt tavolsag kisebb mint a kezdo es vegpont kozotti tavolsag 10%-a vagy
293
                        //tmpImage.Draw(new CircleF(possibleCornerPoints[0], 3), new Bgr(0, 255, 0), 1);
474
                        // nagyobb, mint a ketszerese akkor a kezdo pont lesz a sarok, kulonben a vegpont
475
                        if (distB * 0.1 > distA || distB * 2 < distA)
476
                            goodCornerPoints.Add(start);
477
                        else
478
                            goodCornerPoints.Add(end);
294
                    }
479
                    }
480
                    // Kulonben
295
                    else
481
                    else
296
                    {
482
                    {
297
                        cornerPoints.Add(possibleCornerPoints[i + 1]);
483
                        // Kiszamoljuk a kovetkezo/elso ponttol valo tavolsagot
298
                        //tmpImage.Draw(new CircleF(possibleCornerPoints[i + 1], 3), new Bgr(0, 255, 0), 1);
484
                        if (i != possibleCornerPoints.Count - 3)
485
                        {
486
                            distA = Math.Sqrt(
487
                                (end.X - possibleCornerPoints[i + 3].X) * (end.X - possibleCornerPoints[i + 3].X) +
488
                                (end.Y - possibleCornerPoints[i + 3].Y) * (end.Y - possibleCornerPoints[i + 3].Y));
489
                            tmpImage.Draw(new LineSegment2D(end, possibleCornerPoints[i + 3]), new Bgr(System.Drawing.Color.Red), 2);
490
                        }
491
                        else
492
                        {
493
                            distA = Math.Sqrt(
494
                                (end.X - possibleCornerPoints[0].X) * (end.X - possibleCornerPoints[0].X) +
495
                                (end.Y - possibleCornerPoints[0].Y) * (end.Y - possibleCornerPoints[0].Y));
496
                            tmpImage.Draw(new LineSegment2D(end, possibleCornerPoints[0]), new Bgr(System.Drawing.Color.Purple), 2);
497
                        }
498
499
                        // Kezdo es vegpont kozotti tavolsag
500
                        distB = Math.Sqrt(
501
                            (end.X - start.X) * (end.X - start.X) +
502
                            (end.Y - start.Y) * (end.Y - start.Y));
503
                        tmpImage.Draw(new LineSegment2D(end, start), new Bgr(System.Drawing.Color.Orange), 2);
504
505
                        // Ha a kiszamolt tavolsag kisebb mint a kezdo es vegpont kozotti tavolsag 10%-a vagy
506
                        // nagyobb, mint a ketszerese akkor a kezdo pont lesz a sarok, kulonben a vegpont
507
                        if (distB * 0.1 > distA || distB * 2 < distA)
508
                            goodCornerPoints.Add(end);
509
                        else
510
                            goodCornerPoints.Add(start);
299
                    }
511
                    }
512
300
                }
513
                }
514
                else
515
                {
516
                    // Ha egyertelmuen eldontheto, hogy melyik a nagyobb akkor a nagyobb a sarok
517
                    if (distA > distB)
518
                        goodCornerPoints.Add(start);
519
                    else
520
                        goodCornerPoints.Add(end);
521
                }
522
523
524
                tmpImage.Draw(new CircleF(goodCornerPoints.Last(), 5), new Bgr(System.Drawing.Color.Cyan), -1);
301
            }
525
            }
526
            #endregion
302
527
303
            //Image<Bgr, Byte> tmpImage = new Image<Bgr, byte>(currPiece.ImgPiece.Bitmap);
528
            // kozeli sarkok szurese
304
529
530
			List<double> distancesOfGoodCorners = new List<double>();
531
532
            for (int i = 0; i < goodCornerPoints.Count(); i++)
533
            {
534
                if (i == goodCornerPoints.Count - 1)
535
                {
536
                    distancesOfGoodCorners.Add(Math.Floor(Math.Sqrt(
537
                        (goodCornerPoints[i].X - goodCornerPoints[0].X) * (goodCornerPoints[i].X - goodCornerPoints[0].X) +
538
                        (goodCornerPoints[i].Y - goodCornerPoints[0].Y) * (goodCornerPoints[i].Y - goodCornerPoints[0].Y))));
539
                    tmpImage.Draw(new LineSegment2D(goodCornerPoints[i], goodCornerPoints[0]), new Bgr(System.Drawing.Color.Beige), 3);
540
                    tmpImage.Draw(new CircleF(goodCornerPoints[i], 5), new Bgr(System.Drawing.Color.Cyan), -1);
541
                    tmpImage.Draw(new CircleF(goodCornerPoints[0], 5), new Bgr(System.Drawing.Color.DarkOliveGreen), -1);
542
                }
543
                else
544
                {
545
                    distancesOfGoodCorners.Add(Math.Floor(Math.Sqrt(
546
                       (goodCornerPoints[i + 1].X - goodCornerPoints[i].X) * (goodCornerPoints[i + 1].X - goodCornerPoints[i].X) +
547
                       (goodCornerPoints[i + 1].Y - goodCornerPoints[i].Y) * (goodCornerPoints[i + 1].Y - goodCornerPoints[i].Y))));
548
                    tmpImage.Draw(new LineSegment2D(goodCornerPoints[i + 1], goodCornerPoints[i]), new Bgr(System.Drawing.Color.Beige), 3);
549
                    tmpImage.Draw(new CircleF(goodCornerPoints[i + 1], 5), new Bgr(System.Drawing.Color.Cyan), -1);
550
                    tmpImage.Draw(new CircleF(goodCornerPoints[i], 5), new Bgr(System.Drawing.Color.DarkOliveGreen), -1);
551
                }
552
            }
553
554
            double distMin = distancesOfGoodCorners.Min();
555
            double distAvg = distancesOfGoodCorners.Average();
556
557
            //tmpImage = new Image<Bgr, byte>(currPiece.Bitmap);
558
            
559
            List<Point> contourPoints = contour.GetUnsortedContourPoints();
560
            
561
            for (int i = 0; i < distancesOfGoodCorners.Count; i++)
562
            {
563
                if (distancesOfGoodCorners.Max() * 0.1 > distancesOfGoodCorners[i])
564
                {
565
                    int falseCorner1Idx = contourPoints.IndexOf(goodCornerPoints[i]);
566
                    int falseCorner2Idx = contourPoints.IndexOf(goodCornerPoints[i + 1]);
567
                    int finalCornerIdx = 0;
568
                    if (falseCorner1Idx != falseCorner2Idx)
569
                        finalCornerIdx = (int)Math.Ceiling((falseCorner1Idx + falseCorner2Idx) / 2.0);
570
                    else
571
                        finalCornerIdx = falseCorner2Idx;
572
573
                    cornerPoints.Add(contourPoints[finalCornerIdx]);
574
                    tmpImage.Draw(new CircleF(cornerPoints.Last(), 3), new Bgr(0, 0, 255), -1);
575
                    i++;
576
                    //tmpImage.Draw(new CircleF(contourPoints[falseCorner1Idx], 1), new Bgr(System.Drawing.Color.HotPink), -1);
577
                    //tmpImage.Draw(new CircleF(contourPoints[falseCorner2Idx], 1), new Bgr(System.Drawing.Color.Aquamarine), -1);
578
                    //tmpImage.Draw(new CircleF(contourPoints[finalCornerIdx], 1), new Bgr(System.Drawing.Color.Brown), -1);
579
                }
580
                else
581
                {
582
                    cornerPoints.Add(goodCornerPoints[i]);
583
                    tmpImage.Draw(new CircleF(cornerPoints.Last(), 3), new Bgr(0, 0, 255), -1);
584
                }
585
            }
586
587
            //for (int i = 0; i < possibleCornerPoints.Count; i++)
588
            //{
589
            //    if (i == possibleCornerPoints.Count - 1)
590
            //    {
591
            //        distancesOfGoodCorners.Add(Math.Floor(Math.Sqrt(
592
            //            (possibleCornerPoints[i].X - possibleCornerPoints[0].X) * (possibleCornerPoints[i].X - possibleCornerPoints[0].X) +
593
            //            (possibleCornerPoints[i].Y - possibleCornerPoints[0].Y) * (possibleCornerPoints[i].Y - possibleCornerPoints[0].Y))));
594
            //        tmpImage.Draw(new LineSegment2D(possibleCornerPoints[i], possibleCornerPoints[0]), new Bgr(System.Drawing.Color.Beige), 3);
595
            //        tmpImage.Draw(new CircleF(possibleCornerPoints[i], 5), new Bgr(System.Drawing.Color.Cyan), -1);
596
            //        tmpImage.Draw(new CircleF(possibleCornerPoints[0], 5), new Bgr(System.Drawing.Color.DarkOliveGreen), -1);
597
            //    }
598
            //    else
599
            //    {
600
            //        distancesOfGoodCorners.Add(Math.Floor(Math.Sqrt(
601
            //           (possibleCornerPoints[i + 1].X - possibleCornerPoints[i].X) * (possibleCornerPoints[i + 1].X - possibleCornerPoints[i].X) +
602
            //           (possibleCornerPoints[i + 1].Y - possibleCornerPoints[i].Y) * (possibleCornerPoints[i + 1].Y - possibleCornerPoints[i].Y))));
603
            //        tmpImage.Draw(new LineSegment2D(possibleCornerPoints[i+1], possibleCornerPoints[i]), new Bgr(System.Drawing.Color.Beige), 3);
604
            //        tmpImage.Draw(new CircleF(possibleCornerPoints[i+1], 5), new Bgr(System.Drawing.Color.Cyan), -1);
605
            //        tmpImage.Draw(new CircleF(possibleCornerPoints[i], 5), new Bgr(System.Drawing.Color.DarkOliveGreen), -1);
606
            //    }
607
            //}
608
609
            //double avgOfDistances = distancesOfGoodCorners.Average();
610
611
            //List<double> avgDevOfDistances = new List<double>();
612
            //currDev = 0;
613
            //avgOfDev = 0;
614
            //for (int i = 0; i < distances.Count; i++)
615
            //{
616
            //    currDev = avgOfDistances - distances[i];
617
            //    avgDevOfDistances.Add(currDev);
618
            //    avgOfDev += Math.Abs(currDev);
619
            //}
620
            //avgOfDev /= distances.Count;
621
622
            //avgOfDev *= -1;
623
            //for (int i = 0; i < distances.Count; i++)
624
            //{
625
            //    if (avgDevOfDistances[i] < avgOfDev)
626
            //    {
627
            //        tmpImage = new Image<Bgr, byte>(currPiece.Bitmap);
628
            //        cornerPoints.Add(possibleCornerPoints[i]);
629
630
            //        tmpImage.Draw(new CircleF(possibleCornerPoints[i], 3), new Bgr(255, 0, 0), 1);
631
632
            //        if (i == distances.Count - 1)
633
            //        {
634
            //            cornerPoints.Add(possibleCornerPoints[0]);
635
            //            tmpImage.Draw(new CircleF(possibleCornerPoints[0], 3), new Bgr(0, 255, 0), 1);
636
            //        }
637
            //        else
638
            //        {
639
            //            cornerPoints.Add(possibleCornerPoints[i + 1]);
640
            //            tmpImage.Draw(new CircleF(possibleCornerPoints[i + 1], 3), new Bgr(0, 255, 0), 1);
641
            //        }
642
            //    }
643
            //}
644
645
            //tmpImage = new Image<Bgr, byte>(currPiece.Bitmap);
646
305
            //for (int i = 0; i < cornerPoints.Count; i++)
647
            //for (int i = 0; i < cornerPoints.Count; i++)
306
            //{
648
            //{
307
            //    tmpImage.Draw(new CircleF(cornerPoints[i], 3), new Bgr(0, 0, 255), -1);
649
            //    tmpImage.Draw(new CircleF(cornerPoints[i], 3), new Bgr(0, 255, 0), -1);
308
            //}
650
            //}
309
            
651
            
310
			return cornerPoints;
652
			return cornerPoints;
311
		}
653
		}
654
        private static List<Point> CornersFromNonOutboundedPieces(MCvBox2D minAreaRect, CustomContour contour)
655
        {
656
            Point a = new Point((int)minAreaRect.center.X - (int)minAreaRect.size.Width / 2, (int)minAreaRect.center.Y - (int)minAreaRect.size.Height / 2);
657
            Point b = new Point((int)minAreaRect.center.X - (int)minAreaRect.size.Width / 2, (int)minAreaRect.center.Y + (int)minAreaRect.size.Height / 2);
658
            Point c = new Point((int)minAreaRect.center.X + (int)minAreaRect.size.Width / 2, (int)minAreaRect.center.Y + (int)minAreaRect.size.Height / 2);
659
            Point d = new Point((int)minAreaRect.center.X + (int)minAreaRect.size.Width / 2, (int)minAreaRect.center.Y - (int)minAreaRect.size.Height / 2);
312
660
313
        public static List<PuzzleSide> GetSides(Contour<Point> contour, List<Point> corners, Image<Bgr, Byte> imgMaskedPiece)
661
            int minOfA, minOfB, minOfC, minOfD;
662
            minOfA = minOfB = minOfC = minOfD = 5000;
663
            int minIdxOfA, minIdxOfB, minIdxOfC, minIdxOfD, currDistOfA, currDistOfB, currDistOfC, currDistOfD;
664
            minIdxOfA = minIdxOfB = minIdxOfC = minIdxOfD = currDistOfA = currDistOfB = currDistOfC = currDistOfD = 0;
665
            double range = minAreaRect.size.Width * 0.3;
666
            Stopwatch sw = new Stopwatch();
667
            sw.Restart();
668
            Point currContourPoint;
669
            Parallel.For(0, contour.OriginalContour.Count(), i =>
670
            {
671
                currContourPoint = contour.OriginalContour[i];
672
                if (a.X + range > currContourPoint.X && a.Y + range > currContourPoint.Y)
673
                {
674
                    currDistOfA = (a.X - currContourPoint.X) * (a.X - currContourPoint.X) + (a.Y - currContourPoint.Y) * (a.Y - currContourPoint.Y);
675
                    if (currDistOfA < minOfA)
676
                    {
677
                        minIdxOfA = i;
678
                        minOfA = currDistOfA;
679
                    }
680
                }
681
                if (b.X + range > currContourPoint.X && b.Y - range < currContourPoint.Y)
682
                {
683
                    currDistOfB = (b.X - currContourPoint.X) * (b.X - currContourPoint.X) + (b.Y - currContourPoint.Y) * (b.Y - currContourPoint.Y);
684
                    if (currDistOfB < minOfB)
685
                    {
686
                        minIdxOfB = i;
687
                        minOfB = currDistOfB;
688
                    }
689
                }
690
691
                if (c.X - range < currContourPoint.X && c.Y - range < currContourPoint.Y)
692
                {
693
                    currDistOfC = (c.X - currContourPoint.X) * (c.X - currContourPoint.X) + (c.Y - currContourPoint.Y) * (c.Y - currContourPoint.Y);
694
                    if (currDistOfC < minOfC)
695
                    {
696
                        minIdxOfC = i;
697
                        minOfC = currDistOfC;
698
                    }
699
                }
700
701
                if (d.X - range < currContourPoint.X && d.Y + range > currContourPoint.Y)
702
                {
703
                    currDistOfD = (d.X - currContourPoint.X) * (d.X - currContourPoint.X) + (d.Y - currContourPoint.Y) * (d.Y - currContourPoint.Y);
704
                    if (currDistOfD < minOfD)
705
                    {
706
                        minIdxOfD = i;
707
                        minOfD = currDistOfD;
708
                    }
709
                }
710
711
            });
712
            sw.Stop();
713
            List<Point> corners = new List<Point>();
714
            
715
            corners.Add(contour.OriginalContour[minIdxOfA]);
716
            corners.Add(contour.OriginalContour[minIdxOfB]);
717
            corners.Add(contour.OriginalContour[minIdxOfC]);
718
            corners.Add(contour.OriginalContour[minIdxOfD]);
719
720
            return corners;
721
        }
722
723
        public static List<PuzzleSide> GetSides(Contour<Point> contour, List<Point> corners, List<MCvConvexityDefect> realConvexityDefects, Image<Bgr, Byte> imgMaskedPiece)
314
        {
724
        {
315
            List<PuzzleSide> sides = new List<PuzzleSide>();
725
            List<PuzzleSide> sides = new List<PuzzleSide>();
316
            List<Point> contourPoints = contour.ToList();
726
            List<Point> contourPoints = contour.ToList();

Updated trunk/JPS_PuzzleDetectorWithCam/JPS_PuzzleDetectorWithCam/PuzzlePiece.cs Download diff

6768
103
            set { position = value; }
103
            set { position = value; }
104
        }
104
        }
105
105
106
		public PuzzlePiece(Image<Bgr, Byte> colourPiece, string puzzleName, Point puzzlePosition)
106
        private List<MCvConvexityDefect> realConvexityDefects = new List<MCvConvexityDefect>();
107
        private void SetRealConvexityDefects(List<MCvConvexityDefect> convexityDefects, Point centerOfMass)
108
        {
109
            float avgOfDepths = 0;
110
            for (int i = 0; i < convexityDefects.Count; i++)
111
                avgOfDepths += convexityDefects[i].Depth;
112
            avgOfDepths /= convexityDefects.Count;
113
114
            realConvexityDefects = new List<MCvConvexityDefect>();
115
116
            foreach (MCvConvexityDefect defect in convexityDefects)
117
                if (defect.Depth > avgOfDepths)
118
                    realConvexityDefects.Add(defect);
119
120
        }
121
122
123
        public PuzzlePiece(Image<Bgr, Byte> colourPiece, string puzzleName, Point puzzlePosition)
107
		{
124
		{
108
            name = puzzleName;
125
            name = puzzleName;
109
            iD = PuzzleFunction.PuzzlePieces.Count();
126
            iD = PuzzleFunction.PuzzlePieces.Count();
...
...
123
140
124
            position = puzzlePosition;
141
            position = puzzlePosition;
125
142
126
            imgThresholdedPiece = ImageFunction.BinarizeHSV(colourPiece, 130);
143
            imgThresholdedPiece = ImageFunction.Binarize(colourPiece, 152);
127
            imgThresholdedPiece = imgThresholdedPiece.Erode(2);
144
            //imgThresholdedPiece = imgThresholdedPiece.Erode(2);
128
            imgThresholdedPiece = imgThresholdedPiece.Dilate(2);
145
            //imgThresholdedPiece = imgThresholdedPiece.Dilate(2);
129
146
130
147
131
            Image<Bgr, Byte> tmp = new Image<Bgr, byte>(imgThresholdedPiece.Bitmap);
148
            Image<Bgr, Byte> tmp = new Image<Bgr, byte>(imgThresholdedPiece.Bitmap);
...
...
135
            if (rawContours.Count != 0)
152
            if (rawContours.Count != 0)
136
            {
153
            {
137
                //CustomContour contour = ImageFunction.GetContours(imgThresholdedPiece, .5)[0];
154
                //CustomContour contour = ImageFunction.GetContours(imgThresholdedPiece, .5)[0];
155
156
                tmp = new Image<Bgr, byte>(imgThresholdedPiece.Bitmap);
157
                tmp.Draw(rawContours[0].OriginalContour, new Bgr(0,255,0), 1);
158
138
                CustomContour contour = rawContours[0];
159
                CustomContour contour = rawContours[0];
139
160
140
                List<Point> corners = SortCorners(PuzzleFunction.GetCorners(imgPiece, contour), contour.GetUnsortedContourPoints());
161
                SetRealConvexityDefects(contour.ConvexityDefects, contour.CenterOfMass);
141
162
142
                sides = PuzzleFunction.GetSides(contour.OriginalContour, corners, imgMaskedPiece);
163
                List<Point> corners = SortCorners(PuzzleFunction.GetCorners(imgPiece, contour, realConvexityDefects), contour.GetUnsortedContourPoints());
143
164
165
                sides = PuzzleFunction.GetSides(contour.OriginalContour, corners, realConvexityDefects, imgMaskedPiece);
166
144
                SetPieceType();
167
                SetPieceType();
145
146
                SortSides();
168
                SortSides();
147
169
170
                
148
                signature = GetSignature(sides, contour.CenterOfMass);
171
                signature = GetSignature(sides, contour.CenterOfMass);
172
149
            }
173
            }
150
            else
174
            else
151
            {
175
            {