diff --git a/Tongue extraction_cropresizemethod/Tongue extraction/DeepTongue1.6.csproj b/Tongue extraction_cropresizemethod/Tongue extraction/DeepTongue1.6.csproj index b069c3c..c54de64 100644 --- a/Tongue extraction_cropresizemethod/Tongue extraction/DeepTongue1.6.csproj +++ b/Tongue extraction_cropresizemethod/Tongue extraction/DeepTongue1.6.csproj @@ -106,9 +106,13 @@ + + + Always + @@ -123,17 +127,21 @@ - - ..\..\..\..\..\..\system\sdk\OpenCVsharp\net461\OpenCvSharp.dll + + False + ..\..\..\packages\OpenCvSharp3-AnyCPU.3.2.0.20170107\lib\net40\OpenCvSharp.dll - - ..\..\..\..\..\..\system\sdk\OpenCVsharp\net461\OpenCvSharp.Blob.dll + + False + ..\..\..\packages\OpenCvSharp3-AnyCPU.3.2.0.20170107\lib\net40\OpenCvSharp.Blob.dll - - ..\..\..\..\..\..\system\sdk\OpenCVsharp\net461\OpenCvSharp.Extensions.dll + + False + ..\..\..\packages\OpenCvSharp3-AnyCPU.3.2.0.20170107\lib\net40\OpenCvSharp.Extensions.dll - - ..\..\..\..\..\..\system\sdk\OpenCVsharp\net461\OpenCvSharp.UserInterface.dll + + False + ..\..\..\packages\OpenCvSharp3-AnyCPU.3.2.0.20170107\lib\net40\OpenCvSharp.UserInterface.dll C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.1\System.dll diff --git a/Tongue extraction_cropresizemethod/Tongue extraction/Form1.cs b/Tongue extraction_cropresizemethod/Tongue extraction/Form1.cs index d9e4657..227758c 100644 --- a/Tongue extraction_cropresizemethod/Tongue extraction/Form1.cs +++ b/Tongue extraction_cropresizemethod/Tongue extraction/Form1.cs @@ -17,9 +17,9 @@ [DllImport(@"RemoveSmallRegionDLL.dll", EntryPoint = "RemoveSmallRegion", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] extern static void RemoveSmallRegion(string name, string name2, int AreaLimit, int CheckMode, int NeihborMode); - Mat mat_input = new Mat(1024, 1280, MatType.CV_8UC3, 1); Mat mat_drawBox = new Mat(1024, 1280, MatType.CV_8UC3, 1); Mat mat_roi = new Mat(1024, 1280, MatType.CV_8UC3, 1); + Mat mat_input = new Mat(1024, 1280, MatType.CV_8UC3, 1); Mat mat_roi256 = new Mat(256, 256, MatType.CV_8UC3, 1); Mat mat_roisize = new Mat(1024, 1280, MatType.CV_8UC3, 1); Mat mat_output = new Mat(1024, 1280, MatType.CV_8UC1, 1); @@ -60,6 +60,9 @@ private ManualResetEvent manualReset = new ManualResetEvent(true); + // 20200421 + delegate bool testDele(); + public Form1() { InitializeComponent(); @@ -254,7 +257,7 @@ private static string DownloadDefaultModel(string dir) { - var modelFile = Path.Combine(dir, "AREinProcess_step12800.pb"); + var modelFile = Path.Combine(dir, "2120_256_64_42999_enhancment_L1loss0.03435.pb"); return modelFile; } @@ -322,18 +325,28 @@ ii = 0; basepath = Directory.GetCurrentDirectory(); imageFile = System.Text.RegularExpressions.Regex.Replace(path[a], "data", ""); - label_processingFileName.Text = "Processing File: " + imageFile; - count = a + 1; - label_totalProgress.Text = "Total Progress: " + count + "/" + path.Length; + Invoke((MethodInvoker)delegate + { + label_processingFileName.Text = "Processing File: " + imageFile; + count = a + 1; + label_totalProgress.Text = "Total Progress: " + count + "/" + path.Length; + }); + mat_input = Cv2.ImRead(basepath + "\\data" + imageFile); bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_input); pictureBox_input.Image = bitmap_bitch; - pictureBox_input.Refresh(); + Invoke((MethodInvoker)delegate + { + pictureBox_input.Refresh(); + + }); + label8.BackColor = Color.White; label1.BackColor = Color.Red; mat_drawBox = mat_input.Clone(); mat_cropped = new Mat(mat_input.Size(), MatType.CV_8UC3, 1); byte_inputDetection = Bitmap2Byte(bitmap_bitch); + using (var graph = new TFGraph()) { var model = File.ReadAllBytes(Directory.GetCurrentDirectory() + "/Detection_Normal.pb"); @@ -386,8 +399,12 @@ { mat_drawBox.SaveImage(basepath + "\\detection" + imageFile); bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_drawBox); - pictureBox_detection.Image = bitmap_bitch; - pictureBox_detection.Refresh(); + Invoke((MethodInvoker)delegate + { + pictureBox_detection.Image = bitmap_bitch; + pictureBox_detection.Refresh(); + }); + label1.BackColor = Color.White; label2.BackColor = Color.Red; } @@ -468,7 +485,7 @@ MessageBox.Show("Error: Unable to reprocess! Please check is there [RemoveSmallRegionDLL.dll] file in floder?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } - mat_outputSRGNoBox = new Mat(basepath + "\\output_changed2" + imageFile, ImreadModes.Grayscale); + 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(); @@ -486,7 +503,7 @@ MessageBox.Show("Error: Unable to reprocess! Please check is there [RemoveSmallRegionDLL.dll] file in floder?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } - mat_maskSRG = new Mat(basepath + "\\mask_changed2" + imageFile, ImreadModes.Grayscale); + 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; @@ -545,8 +562,12 @@ Cv2.Resize(mat_roisize, mat_roi, mat_roi256.Size()); mat_roi.SaveImage(basepath + "\\cropresized" + imageFile); bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_roi); - pictureBox_cropResized.Image = bitmap_bitch; - pictureBox_cropResized.Refresh(); + Invoke((MethodInvoker)delegate + { + pictureBox_cropResized.Image = bitmap_bitch; + pictureBox_cropResized.Refresh(); + }); + label2.BackColor = Color.White; label3.BackColor = Color.Red; byte_inputSegmentation = Bitmap2Byte(bitmap_bitch); @@ -593,8 +614,12 @@ bitmap_bitch = ToGrayBitmap(mask, 256, 256); mat_output = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmap_bitch); bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_output); - pictureBox_output.Image = bitmap_bitch; - pictureBox_output.Refresh(); + Invoke((MethodInvoker)delegate + { + pictureBox_output.Image = bitmap_bitch; + pictureBox_output.Refresh(); + }); + label3.BackColor = Color.White; label4.BackColor = Color.Red; mat_output.SaveImage(basepath + "\\output256" + imageFile); @@ -608,10 +633,14 @@ MessageBox.Show("Error: Unable to reprocess! Please check is there [RemoveSmallRegionDLL.dll] file in floder?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } - mat_outputSRG = new Mat(basepath + "\\output_changed2" + imageFile, ImreadModes.Grayscale); + mat_outputSRG = new Mat(basepath + "\\output_changed2" + imageFile, ImreadModes.GrayScale); bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_outputSRG); - pictureBox_outputSRG.Image = bitmap_bitch; - pictureBox_outputSRG.Refresh(); + Invoke((MethodInvoker)delegate + { + pictureBox_outputSRG.Image = bitmap_bitch; + pictureBox_outputSRG.Refresh(); + }); + label4.BackColor = Color.White; label5.BackColor = Color.Red; Cv2.Resize(mat_outputSRG, mat_outputChanged, mat_roisize.Size()); @@ -641,13 +670,21 @@ MessageBox.Show("Error: Unable to reprocess! Please check is there [RemoveSmallRegionDLL.dll] file in floder?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } - mat_maskSRG = new Mat(basepath + "\\mask_changed2" + imageFile, ImreadModes.Grayscale); + + //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); - pictureBox_maskSRG.Image = bitmap_bitch; - pictureBox_maskSRG.Refresh(); + Invoke((MethodInvoker)delegate + { + pictureBox_maskSRG.Image = bitmap_bitch; + pictureBox_maskSRG.Refresh(); + }); + label5.BackColor = Color.White; label6.BackColor = Color.Red; + mat_extraction = mat_input.Clone(); for (int i = 0; i < mat_input.Height; i++) { @@ -672,22 +709,34 @@ } mat_extraction.SaveImage(basepath + "\\extraction" + imageFile); bitmap_bitch = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat_extraction); - pictureBox_extraction.Image = bitmap_bitch; - pictureBox_extraction.Refresh(); + 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(); + Invoke((MethodInvoker)delegate + { + pictureBox_contract.Image = bitmap_bitch; + pictureBox_contract.Refresh(); + }); + label7.BackColor = Color.White; label8.BackColor = Color.Red; time = DateTime.Now.ToLocalTime().ToString(); File.AppendAllText("Log.txt ", time + " " + imageFile + " Done!\n"); } MessageBox.Show("Finished!"); - button_start.Enabled = true; - button_pause.Enabled = false; - label_processingFileName.Text = "Processing File: None"; + + Invoke((MethodInvoker)delegate + { + button_start.Enabled = true; + button_pause.Enabled = false; + label_processingFileName.Text = "Processing File: None"; + }); } }