diff --git a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Class1.cs b/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Class1.cs deleted file mode 100644 index 6f076f3..0000000 --- a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Class1.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace newcamera_deeplearning -{ - public static class checkclass - { - public static int check5 = 0; - } -} diff --git a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_Display.Designer.cs b/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_Display.Designer.cs index f9001ec..cf9f50c 100644 --- a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_Display.Designer.cs +++ b/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_Display.Designer.cs @@ -28,7 +28,6 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel(); this.textBox5 = new System.Windows.Forms.TextBox(); this.textBox4 = new System.Windows.Forms.TextBox(); @@ -50,7 +49,6 @@ this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.tabPage2 = new System.Windows.Forms.TabPage(); - this.timer1 = new System.Windows.Forms.Timer(this.components); this.tableLayoutPanel2.SuspendLayout(); this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit(); @@ -345,10 +343,6 @@ this.tabPage2.Text = "Diagnostic results"; this.tabPage2.UseVisualStyleBackColor = true; // - // timer1 - // - this.timer1.Tick += new System.EventHandler(this.timer1_Tick); - // // Form_Display // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; @@ -357,7 +351,6 @@ this.Name = "Form_Display"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "TIAS User Interface"; - this.Load += new System.EventHandler(this.Form_Display_Load); this.tableLayoutPanel2.ResumeLayout(false); this.tableLayoutPanel2.PerformLayout(); this.panel1.ResumeLayout(false); @@ -392,7 +385,6 @@ public System.Windows.Forms.TextBox ShootingGuideBox; public System.Windows.Forms.TableLayoutPanel tableLayoutPanel2; public System.Windows.Forms.TableLayoutPanel tableLayoutPanel3; - private System.Windows.Forms.Timer timer1; private System.Windows.Forms.TabControl tabControl1; private System.Windows.Forms.TabPage tabPage1; private System.Windows.Forms.TabPage tabPage2; diff --git a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_Display.cs b/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_Display.cs index d68c772..88f46d3 100644 --- a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_Display.cs +++ b/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_Display.cs @@ -132,21 +132,5 @@ } } } - - private void timer1_Tick(object sender, EventArgs e) - { - if (newcamera_deeplearning.checkclass.check5 == 1) - { - System.Threading.Thread.Sleep(100); - tabControl1.SelectedTab = tabControl1.TabPages[1]; - //player6.Play(); - timer1.Stop(); - } - } - - private void Form_Display_Load(object sender, EventArgs e) - { - timer1.Start(); - } } } diff --git a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_Display.resx b/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_Display.resx index 1f666f2..1af7de1 100644 --- a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_Display.resx +++ b/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_Display.resx @@ -117,7 +117,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 17, 17 - \ No newline at end of file diff --git a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_TIASAutomaticShootingSystem.Designer.cs b/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_TIASAutomaticShootingSystem.Designer.cs index 6a18068..ab9f8d6 100644 --- a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_TIASAutomaticShootingSystem.Designer.cs +++ b/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_TIASAutomaticShootingSystem.Designer.cs @@ -30,6 +30,8 @@ { this.components = new System.ComponentModel.Container(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.textBox5 = new System.Windows.Forms.TextBox(); + this.textBox1 = new System.Windows.Forms.TextBox(); this.panel7 = new System.Windows.Forms.Panel(); this.pictureBox4 = new System.Windows.Forms.PictureBox(); this.panel6 = new System.Windows.Forms.Panel(); @@ -58,8 +60,6 @@ this.panel4 = new System.Windows.Forms.Panel(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.serialPort1 = new System.IO.Ports.SerialPort(this.components); - this.textBox1 = new System.Windows.Forms.TextBox(); - this.textBox5 = new System.Windows.Forms.TextBox(); this.tableLayoutPanel1.SuspendLayout(); this.panel7.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox4)).BeginInit(); @@ -127,6 +127,31 @@ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); this.tableLayoutPanel1.Size = new System.Drawing.Size(834, 561); this.tableLayoutPanel1.TabIndex = 0; + this.tableLayoutPanel1.Paint += new System.Windows.Forms.PaintEventHandler(this.tableLayoutPanel1_Paint); + // + // textBox5 + // + this.textBox5.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox5.Font = new System.Drawing.Font("Arial", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel); + this.textBox5.Location = new System.Drawing.Point(211, 336); + this.textBox5.Multiline = true; + this.textBox5.Name = "textBox5"; + this.textBox5.Size = new System.Drawing.Size(202, 31); + this.textBox5.TabIndex = 33; + this.textBox5.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.textBox5.TextChanged += new System.EventHandler(this.textBox5_TextChanged); + // + // textBox1 + // + this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.textBox1.Font = new System.Drawing.Font("Arial", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel); + this.textBox1.Location = new System.Drawing.Point(3, 336); + this.textBox1.Multiline = true; + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(202, 31); + this.textBox1.TabIndex = 32; + this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); // // panel7 // @@ -137,6 +162,7 @@ this.tableLayoutPanel1.SetRowSpan(this.panel7, 5); this.panel7.Size = new System.Drawing.Size(204, 179); this.panel7.TabIndex = 31; + this.panel7.Paint += new System.Windows.Forms.PaintEventHandler(this.panel7_Paint); // // pictureBox4 // @@ -148,6 +174,7 @@ this.pictureBox4.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.pictureBox4.TabIndex = 2; this.pictureBox4.TabStop = false; + this.pictureBox4.Click += new System.EventHandler(this.pictureBox4_Click); // // panel6 // @@ -158,6 +185,7 @@ this.tableLayoutPanel1.SetRowSpan(this.panel6, 5); this.panel6.Size = new System.Drawing.Size(202, 179); this.panel6.TabIndex = 30; + this.panel6.Paint += new System.Windows.Forms.PaintEventHandler(this.panel6_Paint); // // pictureBox3 // @@ -169,6 +197,7 @@ this.pictureBox3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.pictureBox3.TabIndex = 1; this.pictureBox3.TabStop = false; + this.pictureBox3.Click += new System.EventHandler(this.pictureBox3_Click); // // panel5 // @@ -179,6 +208,7 @@ this.tableLayoutPanel1.SetRowSpan(this.panel5, 5); this.panel5.Size = new System.Drawing.Size(204, 179); this.panel5.TabIndex = 29; + this.panel5.Paint += new System.Windows.Forms.PaintEventHandler(this.panel5_Paint); // // pictureBox2 // @@ -190,6 +220,7 @@ this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.pictureBox2.TabIndex = 0; this.pictureBox2.TabStop = false; + this.pictureBox2.Click += new System.EventHandler(this.pictureBox2_Click); // // label10 // @@ -201,6 +232,7 @@ this.label10.TabIndex = 25; this.label10.Text = "Detection"; this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label10.Click += new System.EventHandler(this.label10_Click); // // label9 // @@ -212,6 +244,7 @@ this.label9.TabIndex = 24; this.label9.Text = "Real Time"; this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label9.Click += new System.EventHandler(this.label9_Click); // // panel3 // @@ -222,6 +255,7 @@ this.panel3.Name = "panel3"; this.panel3.Size = new System.Drawing.Size(828, 37); this.panel3.TabIndex = 23; + this.panel3.Paint += new System.Windows.Forms.PaintEventHandler(this.panel3_Paint); // // ShootingGuideBox // @@ -234,6 +268,7 @@ this.ShootingGuideBox.Size = new System.Drawing.Size(828, 37); this.ShootingGuideBox.TabIndex = 24; this.ShootingGuideBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.ShootingGuideBox.TextChanged += new System.EventHandler(this.ShootingGuideBox_TextChanged); // // label1 // @@ -246,6 +281,7 @@ this.label1.TabIndex = 0; this.label1.Text = "Tongue Image Analyzing System"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label1.Click += new System.EventHandler(this.label1_Click); // // panel1 // @@ -257,6 +293,7 @@ this.tableLayoutPanel1.SetRowSpan(this.panel1, 2); this.panel1.Size = new System.Drawing.Size(410, 68); this.panel1.TabIndex = 7; + this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); // // button_ConnectTIAS // @@ -280,6 +317,7 @@ this.label7.TabIndex = 14; this.label7.Text = "RGB"; this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label7.Click += new System.EventHandler(this.label7_Click); // // label8 // @@ -291,6 +329,7 @@ this.label8.TabIndex = 15; this.label8.Text = "L*a*b*"; this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label8.Click += new System.EventHandler(this.label8_Click); // // textBox2 // @@ -302,6 +341,7 @@ this.textBox2.Size = new System.Drawing.Size(202, 31); this.textBox2.TabIndex = 16; this.textBox2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged); // // textBox3 // @@ -313,6 +353,7 @@ this.textBox3.Size = new System.Drawing.Size(202, 31); this.textBox3.TabIndex = 17; this.textBox3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.textBox3.TextChanged += new System.EventHandler(this.textBox3_TextChanged); // // textBox4 // @@ -324,6 +365,7 @@ this.textBox4.Size = new System.Drawing.Size(202, 31); this.textBox4.TabIndex = 18; this.textBox4.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.textBox4.TextChanged += new System.EventHandler(this.textBox4_TextChanged); // // textBox6 // @@ -335,6 +377,7 @@ this.textBox6.Size = new System.Drawing.Size(202, 31); this.textBox6.TabIndex = 19; this.textBox6.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.textBox6.TextChanged += new System.EventHandler(this.textBox6_TextChanged); // // textBox7 // @@ -346,6 +389,7 @@ this.textBox7.Size = new System.Drawing.Size(202, 31); this.textBox7.TabIndex = 20; this.textBox7.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.textBox7.TextChanged += new System.EventHandler(this.textBox7_TextChanged); // // textBox8 // @@ -357,6 +401,7 @@ this.textBox8.Size = new System.Drawing.Size(202, 31); this.textBox8.TabIndex = 21; this.textBox8.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.textBox8.TextChanged += new System.EventHandler(this.textBox8_TextChanged); // // panel2 // @@ -367,6 +412,7 @@ this.panel2.Name = "panel2"; this.panel2.Size = new System.Drawing.Size(828, 31); this.panel2.TabIndex = 22; + this.panel2.Paint += new System.Windows.Forms.PaintEventHandler(this.panel2_Paint); // // GuideBox // @@ -379,6 +425,7 @@ this.GuideBox.Size = new System.Drawing.Size(828, 31); this.GuideBox.TabIndex = 0; this.GuideBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.GuideBox.TextChanged += new System.EventHandler(this.GuideBox_TextChanged); // // label11 // @@ -390,6 +437,7 @@ this.label11.TabIndex = 26; this.label11.Text = "Segmentation"; this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label11.Click += new System.EventHandler(this.label11_Click); // // label12 // @@ -401,6 +449,7 @@ this.label12.TabIndex = 27; this.label12.Text = "Selection Region"; this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label12.Click += new System.EventHandler(this.label12_Click); // // panel4 // @@ -411,6 +460,7 @@ this.tableLayoutPanel1.SetRowSpan(this.panel4, 5); this.panel4.Size = new System.Drawing.Size(202, 179); this.panel4.TabIndex = 28; + this.panel4.Paint += new System.Windows.Forms.PaintEventHandler(this.panel4_Paint); // // pictureBox1 // @@ -422,28 +472,7 @@ this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; - // - // textBox1 - // - this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill; - this.textBox1.Font = new System.Drawing.Font("Arial", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel); - this.textBox1.Location = new System.Drawing.Point(3, 336); - this.textBox1.Multiline = true; - this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(202, 31); - this.textBox1.TabIndex = 32; - this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; - // - // textBox5 - // - this.textBox5.Dock = System.Windows.Forms.DockStyle.Fill; - this.textBox5.Font = new System.Drawing.Font("Arial", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel); - this.textBox5.Location = new System.Drawing.Point(211, 336); - this.textBox5.Multiline = true; - this.textBox5.Name = "textBox5"; - this.textBox5.Size = new System.Drawing.Size(202, 31); - this.textBox5.TabIndex = 33; - this.textBox5.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); // // Form_TIASAutomaticShootingSystem // diff --git a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_TIASAutomaticShootingSystem.cs b/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_TIASAutomaticShootingSystem.cs index 3b53503..16436f0 100644 --- a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_TIASAutomaticShootingSystem.cs +++ b/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/Form_TIASAutomaticShootingSystem.cs @@ -1,15 +1,10 @@ -using System; -using System.Windows.Forms; -using System.IO; -using System.Drawing; -using System.Drawing.Imaging; -using System.Management; -using OpenCvSharp; -using OpenCvSharp.ML; +using OpenCvSharp; +using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.InteropServices; +using System.Drawing; +using System.IO; using System.Linq; +using System.Windows.Forms; namespace OperateCamera { @@ -60,7 +55,7 @@ { // Process_DeepTIAS() var path_mask = @"data_lab\d\Shot0001_mask.bmp"; - Mat mat_finalMask = Cv2.ImRead(path_mask, ImreadModes.GrayScale); + Mat mat_finalMask = Cv2.ImRead(path_mask, ImreadModes.Grayscale); Cv2.Threshold(mat_finalMask, mat_finalMask, 128, 255, ThresholdTypes.Binary); // マスクされた舌領域画像の作成 @@ -70,11 +65,11 @@ // 5点クリック法(2010石川) List list_5points = Get5points(mat_finalMask); - /* // 8領域の取得 List list_8area = Get8area(list_5points); Show8area(mat_oriImg.Clone(), list_8area); + /* // 色抽出 List list_8Bgr = Get8colors(mat_maskedImg, list_8area); @@ -85,10 +80,8 @@ Show8colors(list_8Bgr, list_8Lab); // 保存 - Write8colors(list_8Bgr, list_8Lab); + // Write8colors(list_8Bgr, list_8Lab); */ - - // 廃棄 @@ -122,30 +115,45 @@ list_Y.Add(y); } + /// method1 // 端っこを探索(ラスタ左上から) var p_top = mat_nonZeroCoordinates.At(list_Y.IndexOf(list_Y.Min())); var p_bottom = mat_nonZeroCoordinates.At(list_Y.IndexOf(list_Y.Max())); var p_left = mat_nonZeroCoordinates.At(list_X.IndexOf(list_X.Min())); var p_right = mat_nonZeroCoordinates.At(list_X.IndexOf(list_X.Max())); - // 重心計算 + // 舌尖領域を示すy座標を取得(割合を今回は決め打ち) + var y_apex = (int)(p_top.Y + ((p_bottom.Y - p_top.Y) * 0.8)); + var p_apex_left = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_apex).Min()); + var p_apex_right = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_apex).Max()); + + // 表示してみる + //Cv2.Circle(mat_dst, p_top, 20, new Scalar(255, 255, 0), -1); + Cv2.Circle(mat_dst, p_bottom, 20, new Scalar(255, 255, 0), -1); + //Cv2.Circle(mat_dst, p_left, 20, new Scalar(255, 255, 0), -1); + //Cv2.Circle(mat_dst, p_right, 20, new Scalar(255, 255, 0), -1); + //Cv2.Circle(mat_dst, p_apex_left, 20, new Scalar(255, 255, 0), -1); + //Cv2.Circle(mat_dst, p_apex_right, 20, new Scalar(255, 255, 0), -1); + + /// method2 + // 重心(CoG)計算 var moments = Cv2.Moments(mat_finalMask, true); var moment_x = moments.M10 / moments.M00; var moment_y = moments.M01 / moments.M00; - Console.WriteLine("moments: {0}, {1}", moment_x, moment_y); // 輪郭座標 OpenCvSharp.Point[][] contours; HierarchyIndex[] hierarchy; Cv2.FindContours(mat_finalMask, out contours, out hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple); - // 重心からの輪郭の距離 + // 重心-輪郭の距離 double maxDistance_lefttop = 0.0; double maxDistance_righttop = 0.0; double maxDistance_bottom = 0.0; - var p_lefttop_ = new OpenCvSharp.Point(); - var p_righttop_ = new OpenCvSharp.Point(); - var p_bottom_ = new OpenCvSharp.Point(); + var p_left_2 = new OpenCvSharp.Point(); + var p_right_2 = new OpenCvSharp.Point(); + var p_bottom_2 = new OpenCvSharp.Point(); + // 距離が最も遠いものを採択 for (int i = 0; i < contours[0].Length; i++) { // 重心より上側 @@ -158,7 +166,7 @@ if (distance > maxDistance_lefttop) { maxDistance_lefttop = distance; - p_lefttop_ = contours[0][i]; + p_left_2 = contours[0][i]; } } @@ -169,7 +177,7 @@ if (distance > maxDistance_righttop) { maxDistance_righttop = distance; - p_righttop_ = contours[0][i]; + p_right_2 = contours[0][i]; } } } @@ -179,61 +187,79 @@ if (distance > maxDistance_bottom) { maxDistance_bottom = distance; - p_bottom_ = contours[0][i]; + p_bottom_2 = contours[0][i]; } } } // 舌尖領域を示すy座標を取得(割合を今回は決め打ち) - var y_apex_ = (int)(p_top.Y + ((p_bottom.Y - p_top.Y) * 0.53)); - var p_apex_left_ = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_apex).Min()); - var p_apex_right_ = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_apex).Max()); + var y_top_avg_ = (p_left_2.Y + p_right_2.Y) / 2.0; + var y_apex_2 = (int)(y_top_avg_ + ((p_bottom_2.Y - y_top_avg_) * 0.53)); + var p_apex_left_2 = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_apex_2).Min()); + var p_apex_right_2 = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_apex_2).Max()); + + // 表示 + //Cv2.Circle(mat_dst, p_left_2, 20, new Scalar(255, 0, 0), -1); + //Cv2.Circle(mat_dst, p_right_2, 20, new Scalar(255, 0, 0), -1); + Cv2.Circle(mat_dst, p_bottom_2, 20, new Scalar(255, 0, 0), -1); + //Cv2.Circle(mat_dst, p_apex_left_2, 20, new Scalar(255, 0, 0), -1); + //Cv2.Circle(mat_dst, p_apex_right_2, 20, new Scalar(255, 0, 0), -1); + Cv2.Circle(mat_dst, new OpenCvSharp.Point(moment_x, moment_y), 10, new Scalar(200, 60, 200), -1); //重心 + //Cv2.DrawContours(mat_dst, contours, 0, new Scalar(0, 255, 255), 4); // 輪郭 - // 舌尖領域を示すy座標を取得(割合を今回は決め打ち) - var y_apex = (int)(p_top.Y + ((p_bottom.Y - p_top.Y) * 0.8)); - var p_apex_left = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_apex).Min()); - var p_apex_right = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_apex).Max()); + /// method3 + // 重心とtopの中点を算出する + var y_topToCoG = (int)(moment_y + p_top.Y) / 2; + var p_topToCoG_left = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_topToCoG).Min()); + var p_topToCoG_right = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_topToCoG).Max()); + var p_topToCoG_center = new OpenCvSharp.Point((int)((p_topToCoG_left.X + p_topToCoG_right.X) / 2), y_topToCoG); + // 重心とbottomの中点を算出する + var y_bottomToCoG = (int)(moment_y + p_bottom.Y) / 2; + var p_bottomToCoG_left = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_bottomToCoG).Min()); + var p_bottomToCoG_right = mat_nonZeroCoordinates.At(IndexOfAll(list_Y, y_bottomToCoG).Max()); + var p_bottomToCoG_center = new OpenCvSharp.Point((int)((p_bottomToCoG_left.X + p_bottomToCoG_right.X) / 2), y_bottomToCoG); + // 直線フィッティング + var line = Cv2.FitLine(new OpenCvSharp.Point[2] { p_topToCoG_center, p_bottomToCoG_center }, DistanceTypes.L2, 0, 0.01, 0.0); + var lefty = (int)((-line.X1 * line.Vy / line.Vx) + line.Y1); + var righty = (int)(((mat_finalMask.Cols - line.X1) * line.Vy / line.Vx) + line.Y1); + // 直線上の輪郭点 + var mat_centerline = new Mat(mat_finalMask.Size(), MatType.CV_8UC1, 0); + var mat_contour = new Mat(mat_finalMask.Size(), MatType.CV_8UC1, 0); + var mat_and = new Mat(mat_finalMask.Size(), MatType.CV_8UC1, 0); + Cv2.Line(mat_centerline, new OpenCvSharp.Point(0, lefty), new OpenCvSharp.Point(mat_finalMask.Cols - 1, righty), 3); + Cv2.DrawContours(mat_contour, contours, 0, 3); + Cv2.BitwiseAnd(mat_centerline, mat_contour, mat_and); + Cv2.FindNonZero(mat_and, mat_and); + var bottom_y_3 = 0; + var bottom_x_3 = 0; + for (int i = 0; i < mat_and.Total(); i++) + { + var x = mat_and.At(i).X; + var y = mat_and.At(i).Y; + if (bottom_y_3 < y) + { + bottom_y_3 = y; + bottom_x_3 = x; + } + } + var p_bottom_3 = new OpenCvSharp.Point(bottom_x_3, bottom_y_3); - // 表示してみる - Cv2.Circle(mat_dst, p_top, 20, new Scalar(255, 255, 0), -1); - Cv2.Circle(mat_dst, p_bottom, 20, new Scalar(255, 255, 0), -1); - Cv2.Circle(mat_dst, p_left, 20, new Scalar(255, 255, 0), -1); - Cv2.Circle(mat_dst, p_right, 20, new Scalar(255, 255, 0), -1); - Cv2.Circle(mat_dst, p_apex_left, 20, new Scalar(255, 255, 0), -1); - Cv2.Circle(mat_dst, p_apex_right, 20, new Scalar(255, 255, 0), -1); - - // 重心と輪郭 - //Cv2.Circle(mat_dst, new OpenCvSharp.Point(moment_x, moment_y), 20, new Scalar(0, 255, 255), -1); - //Cv2.DrawContours(mat_dst, contours, 0, new Scalar(0, 255, 255), 4); - - // new strategy - Cv2.Circle(mat_dst, p_lefttop_, 20, new Scalar(255, 0, 0), -1); - Cv2.Circle(mat_dst, p_righttop_, 20, new Scalar(255, 0, 0), -1); - Cv2.Circle(mat_dst, p_bottom, 20, new Scalar(255, 0, 0), -1); + //Cv2.Circle(mat_dst, p_topToCoG_left, 20, new Scalar(0, 100, 255), -1); + //Cv2.Circle(mat_dst, p_topToCoG_right, 20, new Scalar(0, 100, 255), -1); + //Cv2.Circle(mat_dst, p_topToCoG_center, 20, new Scalar(0, 0, 255), -1); + //Cv2.Circle(mat_dst, p_bottomToCoG_left, 20, new Scalar(0, 100, 255), -1); + //Cv2.Circle(mat_dst, p_bottomToCoG_right, 20, new Scalar(0, 100, 255), -1); + //Cv2.Circle(mat_dst, p_bottomToCoG_center, 20, new Scalar(0, 0, 255), -1); + //Cv2.Line(mat_dst, new OpenCvSharp.Point(0, lefty), new OpenCvSharp.Point(mat_finalMask.Cols - 1, righty), new Scalar(0, 100, 255)); //近似直線 + Cv2.Circle(mat_dst, p_bottom_3, 20, new Scalar(0, 0, 255), -1); // DEBUG Cv2.NamedWindow("dst", WindowMode.KeepRatio ^ WindowMode.AutoSize); Cv2.ImShow("dst", mat_dst.Resize(new OpenCvSharp.Size((int)mat_dst.Width * 0.5, (int)mat_dst.Height * 0.5))); - li_dst = new List { p_left, p_apex_left, p_bottom, p_apex_right, p_right }; - // DEBUG 保存 - bool debug = false; - if (debug) - { - string CSVfilename = "contour.csv"; - FileStream CSV_file = File.Open(CSVfilename, FileMode.OpenOrCreate, FileAccess.Write); - CSV_file.Seek(0, SeekOrigin.Begin); - CSV_file.SetLength(0); - CSV_file.Close(); - StreamWriter CSV_data = new StreamWriter(CSVfilename); - string s = ""; - for (int i = 0; i < contours[0].Length; i++) - { - s = contours[0][i].X.ToString() + "," + contours[0][i].Y.ToString() + ","; - CSV_data.WriteLine(s); - } - CSV_data.Close(); - } + // 出力 + // li_dst = new List { p_left, p_apex_left, p_bottom, p_apex_right, p_right }; + li_dst = new List { p_left_2, p_apex_left_2, p_bottom_2, p_apex_right_2, p_right_2 }; // 破棄 mat_dst.Dispose(); @@ -403,13 +429,9 @@ float r = Convert.ToSingle(aryLine[1]); float g = Convert.ToSingle(aryLine[2]); float b = Convert.ToSingle(aryLine[3]); - m_BforLab[i] = b * 1.2; - m_GforLab[i] = g * 0.8; - m_RforLab[i] = r * 0.8; - // DEBUG - Console.WriteLine(r); - Console.WriteLine(g); - Console.WriteLine(b); + m_BforLab[i] = b; + m_GforLab[i] = g; + m_RforLab[i] = r; i++; } sr3.Close(); @@ -470,10 +492,6 @@ // 変換行列の生成 Mat translation = new Mat(); var canSolve = Cv2.Solve(RGBmat, XYZmat, translation, DecompTypes.SVD); - // Debug - Console.WriteLine(RGBmat.At(0, 0)); - Console.WriteLine(XYZmat.At(0, 0)); - Console.WriteLine(translation.At(1, 1)); // 保存 string CSVfilename = "translateMatrix.csv"; @@ -644,7 +662,6 @@ { Console.WriteLine("{0}は見つかりませんでした", target); } - Console.WriteLine(li_num); return li_num; } @@ -730,5 +747,150 @@ { Form_Display.Show(); } + + private void textBox5_TextChanged(object sender, EventArgs e) + { + + } + + private void textBox1_TextChanged(object sender, EventArgs e) + { + + } + + private void panel7_Paint(object sender, PaintEventArgs e) + { + + } + + private void pictureBox4_Click(object sender, EventArgs e) + { + + } + + private void panel6_Paint(object sender, PaintEventArgs e) + { + + } + + private void pictureBox3_Click(object sender, EventArgs e) + { + + } + + private void panel5_Paint(object sender, PaintEventArgs e) + { + + } + + private void pictureBox2_Click(object sender, EventArgs e) + { + + } + + private void label10_Click(object sender, EventArgs e) + { + + } + + private void label9_Click(object sender, EventArgs e) + { + + } + + private void panel3_Paint(object sender, PaintEventArgs e) + { + + } + + private void ShootingGuideBox_TextChanged(object sender, EventArgs e) + { + + } + + private void label1_Click(object sender, EventArgs e) + { + + } + + private void panel1_Paint(object sender, PaintEventArgs e) + { + + } + + private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e) + { + + } + + private void label7_Click(object sender, EventArgs e) + { + + } + + private void label8_Click(object sender, EventArgs e) + { + + } + + private void textBox2_TextChanged(object sender, EventArgs e) + { + + } + + private void textBox3_TextChanged(object sender, EventArgs e) + { + + } + + private void textBox4_TextChanged(object sender, EventArgs e) + { + + } + + private void textBox6_TextChanged(object sender, EventArgs e) + { + + } + + private void textBox7_TextChanged(object sender, EventArgs e) + { + + } + + private void textBox8_TextChanged(object sender, EventArgs e) + { + + } + + private void panel2_Paint(object sender, PaintEventArgs e) + { + + } + + private void GuideBox_TextChanged(object sender, EventArgs e) + { + + } + + private void label11_Click(object sender, EventArgs e) + { + + } + + private void label12_Click(object sender, EventArgs e) + { + + } + + private void panel4_Paint(object sender, PaintEventArgs e) + { + + } + + private void pictureBox1_Click(object sender, EventArgs e) + { + + } } } \ No newline at end of file diff --git a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/ImgProc.cs b/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/ImgProc.cs new file mode 100644 index 0000000..2f2677a --- /dev/null +++ b/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/ImgProc.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using OpenCvSharp; +using OpenCvSharp.XImgProc; + +namespace deepTIAS_feature_labColor +{ + class ImgProc + { + private void ThinningIte(ref Mat img, int pattern) + { + Mat del_marker = img.Clone(); + + int x, y; + int[] v = new int[9]; + + for (y = 1; y < img.Rows - 1; ++y) + { + + for (x = 1; x < img.Cols - 1; ++x) + { + v[8] = 0; v[1] = 0; v[2] = 0; + v[7] = 0; v[0] = 0; v[3] = 0; + v[6] = 0; v[5] = 0; v[4] = 0; + + unsafe + { + v[0] = img.DataPointer[(y * img.Step() + x * img.ElemSize())]; + v[1] = img.DataPointer[(y - 1) * img.Step() + x * img.ElemSize()]; + v[2] = img.DataPointer[(y - 1) * img.Step() + (x + 1) * img.ElemSize()]; + v[3] = img.DataPointer[y * img.Step() + (x + 1) * img.ElemSize()]; + v[4] = img.DataPointer[(y + 1) * img.Step() + (x + 1) * img.ElemSize()]; + v[5] = img.DataPointer[(y + 1) * img.Step() + x * img.ElemSize()]; + v[6] = img.DataPointer[(y + 1) * img.Step() + (x - 1) * img.ElemSize()]; + v[7] = img.DataPointer[y * img.Step() + (x - 1) * img.ElemSize()]; + v[8] = img.DataPointer[(y - 1) * img.Step() + (x - 1) * img.ElemSize()]; + + } + int S = 0; + if (v[2] == 0 && v[3] == 1) S++; + if (v[3] == 0 && v[4] == 1) S++; + if (v[4] == 0 && v[5] == 1) S++; + if (v[5] == 0 && v[6] == 1) S++; + if (v[6] == 0 && v[7] == 1) S++; + if (v[7] == 0 && v[8] == 1) S++; + if (v[8] == 0 && v[1] == 1) S++; + if (v[1] == 0 && v[2] == 1) S++; + + int N = v[1] + v[2] + v[3] + v[4] + v[5] + v[6] + v[7] + v[8]; + + int m1 = 0, m2 = 0; + + if (pattern == 0) m1 = (v[1] * v[3] * v[5]); + if (pattern == 1) m1 = (v[1] * v[3] * v[7]); + + if (pattern == 0) m2 = (v[3] * v[5] * v[7]); + if (pattern == 1) m2 = (v[1] * v[5] * v[7]); + + if (S == 1 && (N >= 2 && N <= 6) && m1 == 0 && m2 == 0) + { + unsafe + { + del_marker.DataPointer[y * del_marker.Step() + x * del_marker.ElemSize()] = 0; + } + } + } + } + img &= del_marker; + } + + public Mat Thinning(Mat src) + { + Mat dst = src.Clone(); + dst /= 255; // 0は0 , 1以上は1に変換される + Mat prev = Mat.Zeros(dst.Size(), MatType.CV_8UC1); + Mat diff = new Mat(); + do + { + ThinningIte(ref dst, 0); + ThinningIte(ref dst, 1); + Cv2.Absdiff(dst, prev, diff); + dst.CopyTo(prev); + + Cv2.ImShow("thinning", dst * 255); + Cv2.WaitKey(100); + System.Threading.Thread.Sleep(100); + + } while (Cv2.CountNonZero(diff) > 0); + dst *= 255; + return dst; + } + } +} diff --git a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/deepTIAS_feature_labColor.csproj b/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/deepTIAS_feature_labColor.csproj index 436a790..54fbaff 100644 --- a/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/deepTIAS_feature_labColor.csproj +++ b/DeepTongue_feature_LabColor/feature_labColor/newcamera_deeplearning/deepTIAS_feature_labColor.csproj @@ -1,6 +1,6 @@  - + Debug @@ -60,6 +60,7 @@ prompt MinimumRecommendedRules.ruleset true + true bin\x64\Release\ @@ -70,9 +71,9 @@ prompt MinimumRecommendedRules.ruleset true + true - Form @@ -87,6 +88,7 @@ + Form_Display.cs @@ -152,17 +154,17 @@ - - ..\..\..\..\packages\OpenCvSharp3-AnyCPU.3.2.0.20170107\lib\net40\OpenCvSharp.dll + + ..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net461\OpenCvSharp.dll - - ..\..\..\..\packages\OpenCvSharp3-AnyCPU.3.2.0.20170107\lib\net40\OpenCvSharp.Blob.dll + + ..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net461\OpenCvSharp.Blob.dll - - ..\..\..\..\packages\OpenCvSharp3-AnyCPU.3.2.0.20170107\lib\net40\OpenCvSharp.Extensions.dll + + ..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net461\OpenCvSharp.Extensions.dll - - ..\..\..\..\packages\OpenCvSharp3-AnyCPU.3.2.0.20170107\lib\net40\OpenCvSharp.UserInterface.dll + + ..\packages\OpenCvSharp3-AnyCPU.4.0.0.20181129\lib\net461\OpenCvSharp.UserInterface.dll @@ -179,8 +181,8 @@ このプロジェクトは、このコンピューター上にない NuGet パッケージを参照しています。それらのパッケージをダウンロードするには、[NuGet パッケージの復元] を使用します。詳細については、http://go.microsoft.com/fwlink/?LinkID=322105 を参照してください。見つからないファイルは {0} です。 - +