diff --git a/.gitignore b/.gitignore index 5b008b2..365d1f6 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,4 @@ *.config *.pb *.jpg +*.png diff --git a/Tongue extraction_cropresizemethod/Tongue extraction/Form1.cs b/Tongue extraction_cropresizemethod/Tongue extraction/Form1.cs index 4982f02..a1b36bf 100644 --- a/Tongue extraction_cropresizemethod/Tongue extraction/Form1.cs +++ b/Tongue extraction_cropresizemethod/Tongue extraction/Form1.cs @@ -60,7 +60,7 @@ private ManualResetEvent manualReset = new ManualResetEvent(true); - string fileName_info = "tongue_info_" + DateTime.Now.ToLocalTime().ToString("yyyyMMddss") + ".csv"; + string fileName_info = Directory.GetCurrentDirectory() + "//info//" + DateTime.Now.ToLocalTime().ToString("yyyyMMddhhmmss") + ".csv"; StreamWriter sw; public Form1() @@ -68,7 +68,11 @@ InitializeComponent(); // boundingboxなどのinfo出力用 - sw = new StreamWriter(fileName_info, false); + sw = new StreamWriter(fileName_info, false, System.Text.Encoding.GetEncoding("shift_jis")); + sw.WriteLine( + "image" + "," + + "top left X" + "," + "top left Y" + "," + "bottom right X" + "," + "bottom right Y" + "," + + "Width" + "," + "Height" + "," + "Area"); } private void Button_start_Click(object sender, EventArgs e) @@ -395,15 +399,6 @@ check_detection = 1; } } - Invoke((MethodInvoker)delegate - { - textBox1.Text = P1.ToString() + ", "; - textBox1.Text += P2.ToString() + ", "; - textBox1.Text += max_score.ToString() + ", "; - sw.WriteLine("," + "image" + "," + "p1" + "," + "p2" + ","); - sw.WriteLine(imageFile.Substring(1) + "," + P1.ToString() + "," + P2.ToString() + ","); - }); - } } if (check_detection == 1) @@ -414,30 +409,33 @@ { pictureBox_detection.Image = bitmap_bitch; pictureBox_detection.Refresh(); - }); - + }); label1.BackColor = Color.White; label2.BackColor = Color.Red; } - else + else // 舌が検出されなかった場合 { - MessageBox.Show("Error: Sorry can not detect any tongue in this image. Press [OK] to skip preprocessing.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Error: Sorry can not detect any tongue in this image.\nPress [OK] to skip preprocessing.", + "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); time = DateTime.Now.ToLocalTime().ToString(); File.AppendAllText("DetectionFailedLog.txt ", time + " " + imageFile + "\n"); - pictureBox_detection.Image = null; - pictureBox_detection.Refresh(); - pictureBox_cropResized.Image = null; - pictureBox_cropResized.Refresh(); - pictureBox_output.Image = null; - pictureBox_output.Refresh(); - pictureBox_outputSRG.Image = null; - pictureBox_outputSRG.Refresh(); - pictureBox_maskSRG.Image = null; - pictureBox_maskSRG.Refresh(); - pictureBox_extraction.Image = null; - pictureBox_extraction.Refresh(); - pictureBox_contract.Image = null; - pictureBox_contract.Refresh(); + Invoke((MethodInvoker)delegate + { + pictureBox_detection.Image = null; + pictureBox_detection.Refresh(); + pictureBox_cropResized.Image = null; + pictureBox_cropResized.Refresh(); + pictureBox_output.Image = null; + pictureBox_output.Refresh(); + pictureBox_outputSRG.Image = null; + pictureBox_outputSRG.Refresh(); + pictureBox_maskSRG.Image = null; + pictureBox_maskSRG.Refresh(); + pictureBox_extraction.Image = null; + pictureBox_extraction.Refresh(); + pictureBox_contract.Image = null; + pictureBox_contract.Refresh(); + }); bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_input); byte_inputSegmentation = Bitmap2Byte(bitmap_bitch); @@ -481,10 +479,14 @@ bitmap_bitch = ToGrayBitmap(mask, 256, 256); mat_outputNoBox = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap_bitch); bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_outputNoBox); - pictureBox_output.Image = bitmap_bitch; - pictureBox_output.Refresh(); - label1.BackColor = Color.White; - label4.BackColor = Color.Red; + Invoke((MethodInvoker)delegate + { + pictureBox_output.Image = bitmap_bitch; + pictureBox_output.Refresh(); + label1.BackColor = Color.White; + label4.BackColor = Color.Red; + }); + mat_outputNoBox.SaveImage(basepath + "\\output256" + imageFile); try { @@ -498,10 +500,13 @@ } mat_outputSRGNoBox = new Mat(basepath + "\\output_changed2" + imageFile, ImreadModes.GrayScale); bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_outputSRGNoBox); - pictureBox_outputSRG.Image = bitmap_bitch; - pictureBox_outputSRG.Refresh(); - label4.BackColor = Color.White; - label5.BackColor = Color.Red; + Invoke((MethodInvoker)delegate + { + pictureBox_outputSRG.Image = bitmap_bitch; + pictureBox_outputSRG.Refresh(); + label4.BackColor = Color.White; + label5.BackColor = Color.Red; + }); Cv2.Resize(mat_outputSRGNoBox, mat_mask, mat_input.Size()); mat_mask.SaveImage(basepath + "\\mask" + imageFile); try @@ -517,11 +522,15 @@ mat_maskSRG = new Mat(basepath + "\\mask_changed2" + imageFile, ImreadModes.GrayScale); Cv2.Threshold(mat_maskSRG, mat_maskSRG, 128, 255, ThresholdTypes.Binary); bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_maskSRG); - pictureBox_maskSRG.Image = bitmap_bitch; - pictureBox_maskSRG.Refresh(); - label5.BackColor = Color.White; - label6.BackColor = Color.Red; + Invoke((MethodInvoker)delegate + { + pictureBox_maskSRG.Image = bitmap_bitch; + pictureBox_maskSRG.Refresh(); + label5.BackColor = Color.White; + label6.BackColor = Color.Red; + }); mat_extraction = mat_input.Clone(); + int areaCount_noDetection = 0; for (int i = 0; i < mat_input.Height; i++) { for (int j = 0; j < mat_input.Width; j++) @@ -540,20 +549,36 @@ pix[1] = (byte)(mat_extraction.At(i, j).Item1); pix[2] = (byte)(mat_extraction.At(i, j).Item2); mat_extraction.Set(i, j, pix); + areaCount_noDetection++; } } } mat_extraction.SaveImage(basepath + "\\extraction" + imageFile); bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_extraction); - pictureBox_extraction.Image = bitmap_bitch; - pictureBox_extraction.Refresh(); - label6.BackColor = Color.White; - label7.BackColor = Color.Red; + Invoke((MethodInvoker)delegate + { + pictureBox_extraction.Image = bitmap_bitch; + pictureBox_extraction.Refresh(); + label6.BackColor = Color.White; + label7.BackColor = Color.Red; + }); bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_input); - pictureBox_contract.Image = bitmap_bitch; - pictureBox_contract.Refresh(); - label7.BackColor = Color.White; - label8.BackColor = Color.Red; + Invoke((MethodInvoker)delegate + { + pictureBox_contract.Image = bitmap_bitch; + pictureBox_contract.Refresh(); + label7.BackColor = Color.White; + label8.BackColor = Color.Red; + }); + + //csvにboundingbox情報を保存 + sw.WriteLine( + imageFile.Substring(1) + "," + + "None" + "," + "None" + "," + + "None" + "," + "None" + "," + + "None" + "," + "None" + "," + areaCount_noDetection.ToString() + ); + continue; } for (int i = P1.Y; i < P2.Y; i++) @@ -681,9 +706,6 @@ MessageBox.Show("Error: Unable to reprocess! Please check is there [RemoveSmallRegionDLL.dll] file in floder?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } - - //RemoveSmallRegion(basepath + "\\output256" + imageFile, basepath + "\\mask_changed1" + imageFile, 2000, 1, 1); - //RemoveSmallRegion(basepath + "\\mask_changed1" + imageFile, basepath + "\\mask_changed2" + imageFile, 2000, 0, 0); mat_maskSRG = new Mat(basepath + "\\mask_changed2" + imageFile, ImreadModes.GrayScale); Cv2.Threshold(mat_maskSRG, mat_maskSRG, 128, 255, ThresholdTypes.Binary); bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_maskSRG); @@ -697,6 +719,7 @@ label6.BackColor = Color.Red; mat_extraction = mat_input.Clone(); + int areaCount = 0; for (int i = 0; i < mat_input.Height; i++) { for (int j = 0; j < mat_input.Width; j++) @@ -715,6 +738,7 @@ pix[1] = (byte)(mat_extraction.At(i, j).Item1); pix[2] = (byte)(mat_extraction.At(i, j).Item2); mat_extraction.Set(i, j, pix); + areaCount++; } } } @@ -740,7 +764,17 @@ time = DateTime.Now.ToLocalTime().ToString(); File.AppendAllText("Log.txt ", time + " " + imageFile + " Done!\n"); - + + //csvにboundingbox情報を保存 + sw.WriteLine( + imageFile.Substring(1) + "," + + P1.X.ToString() + "," + P1.Y.ToString() + "," + + P2.X.ToString() + "," + P2.Y.ToString() + "," + + Math.Abs(P1.X - P2.X).ToString() + "," + Math.Abs(P1.Y - P2.Y).ToString() + "," + + areaCount.ToString() + ); + + } MessageBox.Show("Finished!"); diff --git a/Tongue extraction_cropresizemethod/Tongue extraction/bin/x64/Debug/mask/20180419045627.jpg b/Tongue extraction_cropresizemethod/Tongue extraction/bin/x64/Debug/mask/20180419045627.jpg index 12b28af..f7797a1 100644 --- a/Tongue extraction_cropresizemethod/Tongue extraction/bin/x64/Debug/mask/20180419045627.jpg +++ b/Tongue extraction_cropresizemethod/Tongue extraction/bin/x64/Debug/mask/20180419045627.jpg Binary files differ diff --git a/Tongue extraction_cropresizemethod/Tongue extraction/bin/x64/Debug/mask_changed2/20180419045627.jpg b/Tongue extraction_cropresizemethod/Tongue extraction/bin/x64/Debug/mask_changed2/20180419045627.jpg index e7e8d9c..4145513 100644 --- a/Tongue extraction_cropresizemethod/Tongue extraction/bin/x64/Debug/mask_changed2/20180419045627.jpg +++ b/Tongue extraction_cropresizemethod/Tongue extraction/bin/x64/Debug/mask_changed2/20180419045627.jpg Binary files differ