public void ConvertThread() { if (String.IsNullOrEmpty(SourcePath)) { return; } //準備資料 string JsonSourcePath = this.SourcePath; string BackupPath = System.IO.Path.Combine(JsonSourcePath, "BackUp"); Func.CheckDirExist(BackupPath); string SourceFilePatten = "*.json"; List <string> JsonFilePathSet = Func.GetFilesFromDir(JsonSourcePath, SourceFilePatten, true); ProcessBarPage.SetMaxAndMin(0, JsonFilePathSet.Count); ProcessBarPage.SetProgressValue(0); DcmNotExistPath = new List <string>(); #region 開始轉換 #endregion for (int i = 0; i < JsonFilePathSet.Count; i++) { ProcessBarPage.SetProgressValue(i); string JsonFilePath = JsonFilePathSet[i]; string ImageFileNameWithOutExt = System.IO.Path.GetFileNameWithoutExtension(JsonFilePath); string DcmFilePath = JsonFilePath.Substring(0, JsonFilePath.Length - 5) + ".dcm"; DcmInfo TempDcmInfo; if (Func.CheckFileExist(DcmFilePath)) { TempDcmInfo = Image_Func.DcmDetailData(DcmFilePath); } else { //如果Json路徑下沒有dcm檔案則跳過此次轉換 DcmNotExistPath.Add(JsonFilePath); continue; } #region 備份檔案到備份路徑 string V1LogStr = Func.ReadText(JsonFilePath); string BackUpPath = System.IO.Path.Combine(BackupPath, ImageFileNameWithOutExt + ".json"); Func.WriteText(BackUpPath, V1LogStr); #endregion //讀取V1檔案 if (SaveResultV2.IsVersion2(V1LogStr)) { //如果是V2版本則免轉換跳過 continue; } SaveResultV1 V1Log = SaveResultV1.ReadFile(JsonFilePath); //轉V2 SaveResultV2 V2Log = SaveResultV2.Convert(V1Log, TempDcmInfo); //複寫V1版本 SaveResultV2.SaveFile(V2Log, JsonFilePath); } ProcessBarPage.CloseWindows(); OK(); }
private void cvImageBox_MouseClick(object sender, MouseEventArgs e) { if (cvImageBox.Image != null) { //抓出影像中的點 Point ImageLocation = Image_Func.GetImagePointFromImageBox(cvImageBox, e.Location); switch (RightNowMode) { case ProgramAction.Point: AddPoint(ImageLocation); break; case ProgramAction.Drag: break; default: break; } } }
/// <summary> /// 要改變圖片就用這個 /// </summary> private void ImageProc() { int B_Level = trbImageBrightness.Value; int C_Level = trbImageContrast.Value; List <Nullable <Point> > KeyPoints = LabelLog.KeyPoints; Image <Bgr, Byte> Img = OriginalImage.Copy(); //調亮度跟對比度 Img = Image_Func.BrightnessAndContrast(Img, B_Level, C_Level); //畫點劃線 if (cbShowKeyPoint.Checked) { Img = ImageLabelDataReLoad(Img, KeyPoints); } cvImageBox.Image = Img; //載入資料表 GridViewDataReLoad(); //防止記憶體爆炸 GC.Collect(); }
/// <summary> /// 將Label的紀錄讀取回去 /// </summary> private Image <Bgr, Byte> ImageLabelDataReLoad(Image <Bgr, Byte> Source, List <Nullable <Point> > KeyPoint) { Image <Bgr, Byte> Img = Source.Copy(); #region 先畫點 foreach (Nullable <Point> Point in KeyPoint) { if (Point != null) { Img = Image_Func.DrawPoint(ref Img, Point.Value, Color_Blue); } } #endregion #region 畫塑膠氣管 for (int i = 1; i < 4; i++) { if (KeyPoint[i] != null && KeyPoint[i - 1] != null) { if (KeyPoint[i] != null && KeyPoint[i - 1] != null) { Img = Image_Func.DrawLine(ref Img, KeyPoint[i - 1].Value, KeyPoint[i].Value, Color_Red); } } } #endregion #region 畫肺部分岔 for (int i = 5; i < 13; i++) { if (KeyPoint[i] != null && KeyPoint[i - 1] != null && (i % 3) != 1) { if (KeyPoint[i] != null && KeyPoint[i - 1] != null) { Img = Image_Func.DrawLine(ref Img, KeyPoint[i - 1].Value, KeyPoint[i].Value, Color_Red); } } } #endregion return(Img); }
private void cvImageBox_MouseDraged(object sender, Point StartPoint, Point EndPoint) { if (OriginalImage != null && RightNowMode == ProgramAction.Drag) { Point StartPointInImage = Image_Func.GetImagePointFromImageBox(cvImageBox, StartPoint); Point EndPointInImage = Image_Func.GetImagePointFromImageBox(cvImageBox, EndPoint); for (int i = 0; i < LabelLog.KeyPoints.Count; i++) { Point?KeyPoint = LabelLog.KeyPoints[i]; if (KeyPoint != null) { if (Image_Func.GetDistance(KeyPoint.Value, StartPointInImage) <= NearThreadHold) { //代表這個點要改 LabelLog.KeyPoints[i] = EndPointInImage; //修改完後要更新影像 ImageProc(); } } } } }
private void tbOpenFile_Click(object sender, EventArgs e) { if (OriginalImage != null) { //if (MessageBox.Show("是否要對上一次的操作結果儲存?", "確認", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) //{ // SaveLabelFile(); //} SaveLabelFile(); } using (OpenFileDialog dialog = new OpenFileDialog()) { dialog.Filter = "*.dcm|*.dcm|All File(*.*)|*.*"; if (dialog.ShowDialog() == DialogResult.OK) { ImagePath_Dcm = dialog.FileName; string dcmFileName = System.IO.Path.GetFileNameWithoutExtension(ImagePath_Dcm); string targetFileName = dcmFileName + ".jpg"; //檢查存檔路徑是否跟讀取影像有相同的影像,如果有則直接載入影像,如果沒有則轉檔載入 string targetFilePath = Path.Combine(SettingObj.SavePath, targetFileName); RightNowInfo = Image_Func.DcmDetailData(ImagePath_Dcm); if (!Func.CheckFileExist(targetFilePath)) { //檔案不存在 string jpgFilePath = Image_Func.DcmToJPG(ImagePath_Dcm, SettingObj.SavePath); targetFilePath = jpgFilePath; } ImagePath_Jpg = targetFilePath; //顯示在ImageBox Bitmap image = (Bitmap)Bitmap.FromFile(ImagePath_Jpg); Image <Bgr, Byte> img = new Image <Bgr, Byte>(image); SettingImage(img); LoadingLabelFile(ImagePath_Dcm, ImagePath_Jpg); AdjustmentInit(true); ImageProc(); } } }
private bool IsNearPoint(Point MousePoint) { bool Result = false; if (LabelLog.KeyPoints.Count > 0) { Point MouseInImagePoint = Image_Func.GetImagePointFromImageBox(cvImageBox, MousePoint); for (int i = 0; i < LabelLog.KeyPoints.Count; i++) { Point?P = LabelLog.KeyPoints[i]; if (P != null) { double Distance = Image_Func.GetDistance(MouseInImagePoint, P.Value); if (Distance <= NearThreadHold) { Result = true; break; } } } } return(Result); }