Sfoglia il codice sorgente

合并天宇颗粒融合

cxs 1 anno fa
parent
commit
e4db8b4bb0

+ 1 - 1
OTSCommon/ReportModel/ResultFile.cs

@@ -246,7 +246,7 @@ public    enum OTS_Y_AXIS_DIRECTION
         /// <summary>
         /// ResuitInfo
         /// </summary>       
-        private Dictionary<string, object> ResultInfo
+        public Dictionary<string, object> ResultInfo
         {
             get;
             set;

+ 499 - 0
OTSIncAMeasureApp/ServiceCenter/CImageHandler.cs

@@ -625,5 +625,504 @@ namespace OTSModelSharp.ServiceCenter
             return points;
         }
 
+        #region 合并天宇颗粒融合新增函数
+        public Mat CombinImageX(Mat[] list_mats, int OverlapParam, int type)
+        {
+            List<Mat> matStitch = new List<Mat>();//拼接
+            List<Mat> matCombin = new List<Mat>();//合并
+            for (int i = 0; i < list_mats.Count(); i++)
+            {
+                if (i == 0)//首张
+                {
+                    matCombin.Add(new Mat(list_mats[i], new OpenCvSharp.Rect(0, 0, list_mats[i].Width - OverlapParam - 100, list_mats[i].Height)));
+                    matStitch.Add(new Mat(list_mats[i], new OpenCvSharp.Rect(list_mats[i].Width - OverlapParam - 100, 0, OverlapParam + 100, list_mats[i].Height)));
+                }
+                else if (i == list_mats.Count() - 1)//末张
+                {
+                    matStitch.Add(new Mat(list_mats[i], new OpenCvSharp.Rect(0, 0, OverlapParam + 100, list_mats[i].Height)));
+                    matCombin.Add(new Mat(list_mats[i], new OpenCvSharp.Rect(OverlapParam + 100, 0, list_mats[i].Width - OverlapParam - 100, list_mats[i].Height)));
+                }
+                else
+                {
+                    matStitch.Add(new Mat(list_mats[i], new OpenCvSharp.Rect(0, 0, OverlapParam + 100, list_mats[i].Height)));
+                    matCombin.Add(new Mat(list_mats[i], new OpenCvSharp.Rect(OverlapParam + 100, 0, list_mats[i].Width - (OverlapParam + 100) * 2, list_mats[i].Height)));
+                    matStitch.Add(new Mat(list_mats[i], new OpenCvSharp.Rect(list_mats[i].Width - OverlapParam - 100, 0, OverlapParam + 100, list_mats[i].Height)));
+                }
+            }
+
+            for (int i = 0; i < matStitch.Count; i += 2)
+            {
+                if (matStitch.Count == 1)
+                {
+                    matCombin.Insert(i + 1, matStitch[i]);
+                }
+                else
+                {
+                    matCombin.Insert(i + 1, StitchImageX((int)(OverlapParam / 2 * 1.2), type, matStitch[i], matStitch[i + 1]));
+                }
+            }
+
+            Mat pano = new OpenCvSharp.Mat();
+            Cv2.HConcat(matCombin.ToArray(), pano);
+
+            return pano;
+        }
+
+        public Mat CombinImageY(Mat[] list_mats, int OverlapParam, int type)
+        {
+            List<Mat> matStitch = new List<Mat>();//拼接
+            List<Mat> matCombin = new List<Mat>();//合并
+            for (int i = 0; i < list_mats.Count(); i++)
+            {
+                if (i == 0)//首张
+                {
+                    matCombin.Add(new Mat(list_mats[i], new OpenCvSharp.Rect(0, 0, list_mats[i].Width, list_mats[i].Height - OverlapParam - 100)));
+                    matStitch.Add(new Mat(list_mats[i], new OpenCvSharp.Rect(0, list_mats[i].Height - OverlapParam - 100, list_mats[i].Width, OverlapParam + 100)));
+                }
+                else if (i == list_mats.Count() - 1)//末张
+                {
+                    matStitch.Add(new Mat(list_mats[i], new OpenCvSharp.Rect(0, 0, list_mats[i].Width, OverlapParam + 100)));
+                    matCombin.Add(new Mat(list_mats[i], new OpenCvSharp.Rect(0, OverlapParam + 100, list_mats[i].Width, list_mats[i].Height - OverlapParam - 100)));
+                }
+                else
+                {
+                    matStitch.Add(new Mat(list_mats[i], new OpenCvSharp.Rect(0, 0, list_mats[i].Width, OverlapParam + 100)));
+                    matCombin.Add(new Mat(list_mats[i], new OpenCvSharp.Rect(0, OverlapParam + 100, list_mats[i].Width, list_mats[i].Height - (OverlapParam + 100) * 2)));
+                    matStitch.Add(new Mat(list_mats[i], new OpenCvSharp.Rect(0, list_mats[i].Height - OverlapParam - 100, list_mats[i].Width, OverlapParam + 100)));
+                }
+            }
+
+            for (int i = 0; i < matStitch.Count; i += 2)
+            {
+                if (matStitch.Count == 1)
+                {
+                    matCombin.Insert(i + 1, matStitch[i]);
+                }
+                else
+                {
+                    matCombin.Insert(i + 1, StitchImageY(OverlapParam, type, matStitch[i], matStitch[i + 1]));
+                }
+            }
+
+            Mat pano = new OpenCvSharp.Mat();
+            Cv2.VConcat(matCombin.ToArray(), pano);
+
+            return pano;
+        }
+
+        public struct MStitch
+        {
+            public int Pwidth;//单幅图像的宽度
+            public int Pheight;//单幅图像的高度
+            public int W_min;//最小的重叠区域宽度
+            public int W_max;//最大的重叠区域宽度
+            public int H_min;//最小的重叠区域高度
+            public double minval;//块过滤阈值
+            public Mat im;//图像信息
+        }
+        public struct ImageParam
+        {
+            public int W_box;//宽度信息
+            public int H_box;//高度信息
+            public int bdown;//上下信息
+            public MStitch mStitch; //参数结构
+            public Mat im;//图像信息
+        }
+
+        /// <summary>
+        /// 横向拼图
+        /// </summary>
+        public Mat StitchImageXGrid(int min_w, int type, Mat newImg1, Mat newImg2)
+        {
+            MStitch mStitch = new MStitch();
+            mStitch.Pwidth = newImg1.Width;
+            mStitch.Pheight = newImg1.Height;
+            mStitch.W_min = min_w - 50;
+            mStitch.W_max = min_w + 50;
+            mStitch.H_min = newImg1.Height;
+            mStitch.minval = 255;
+            mStitch.im = newImg1;
+
+            ImageParam imageParam = Fun_Match(newImg2, mStitch);
+            imageParam.im = newImg2;
+
+            if (type == 2)
+            {
+                return Fun_Stitch(imageParam);
+            }
+            else
+            {
+                return Fun_StitchRGB(imageParam);
+            }
+        }
+
+
+        /// <summary>
+        /// 纵向拼图
+        /// </summary>
+        public Mat StitchImageYGrid(int min_w, int type, Mat newImg1, Mat newImg2)
+        {
+            Cv2.Transpose(newImg1, newImg1);
+            Cv2.Flip(newImg1, newImg1, FlipMode.X);
+
+            Cv2.Transpose(newImg2, newImg2);
+            Cv2.Flip(newImg2, newImg2, FlipMode.X);
+
+            MStitch mStitch = new MStitch();
+            mStitch.Pwidth = newImg1.Width;
+            mStitch.Pheight = newImg1.Height;
+            mStitch.W_min = min_w - 50;
+            mStitch.W_max = min_w + 50;
+            mStitch.H_min = newImg1.Height;
+            mStitch.minval = 255;
+            mStitch.im = newImg1;
+
+            ImageParam imageParam = Fun_Match(newImg2, mStitch);
+            imageParam.im = newImg2;
+
+            Mat result = type == 2 ? Fun_Stitch(imageParam) : Fun_StitchRGB(imageParam);
+
+            Cv2.Transpose(result, result);
+            Cv2.Flip(result, result, FlipMode.Y);
+
+            return result;
+        }
+
+        /// <summary>
+        /// 横向拼图
+        /// </summary>
+        public Mat StitchImageX(int min_w, int type, Mat newImg1, Mat newImg2)
+        {
+            MStitch mStitch = new MStitch();
+            mStitch.Pwidth = newImg1.Width;
+            mStitch.Pheight = newImg1.Height;
+            mStitch.W_min = min_w;
+            mStitch.W_max = min_w;
+            mStitch.H_min = newImg1.Height;
+            mStitch.minval = 255;
+            mStitch.im = newImg1;
+
+            ImageParam imageParam = Fun_Match(newImg2, mStitch);
+            imageParam.im = newImg2;
+
+            if (type == 2)
+            {
+                return Fun_Stitch(imageParam);
+            }
+            else
+            {
+                return Fun_StitchRGB(imageParam);
+            }
+        }
+
+        /// <summary>
+        /// 纵向拼图
+        /// </summary>
+        public Mat StitchImageY(int min_w, int type, Mat newImg1, Mat newImg2)
+        {
+            Cv2.Transpose(newImg1, newImg1);
+            Cv2.Flip(newImg1, newImg1, FlipMode.X);
+
+            Cv2.Transpose(newImg2, newImg2);
+            Cv2.Flip(newImg2, newImg2, FlipMode.X);
+
+            MStitch mStitch = new MStitch();
+            mStitch.Pwidth = newImg1.Width;
+            mStitch.Pheight = newImg1.Height;
+            mStitch.W_min = min_w - 50;
+            mStitch.W_max = min_w - 50;
+            mStitch.H_min = newImg1.Height - 20;
+            mStitch.minval = 255;
+            mStitch.im = newImg1;
+
+            ImageParam imageParam = Fun_Match(newImg2, mStitch);
+            imageParam.im = newImg2;
+
+            Mat result = type == 2 ? Fun_Stitch(imageParam) : Fun_StitchRGB(imageParam);
+
+            Cv2.Transpose(result, result);
+            Cv2.Flip(result, result, FlipMode.Y);
+
+            return result;
+        }
+
+        public static ImageParam Fun_Match(Mat im2, MStitch mStitch)
+        {
+            ImageParam imageParam = new ImageParam();
+            double imsum = 0;
+            int x1 = 0;
+            int y1 = 0;
+            int x2 = 0;
+            int y2 = 0;
+            int w_ind = 0;
+            int h_ind = 0;                                        //        
+            for (int w = mStitch.W_min; w <= mStitch.W_max; w++)
+            {
+                for (int h = mStitch.H_min; h <= mStitch.Pheight; h++)
+                {
+                    imsum = 0;//块差分集初始化 
+                    x2 = 1;
+                    for (x1 = mStitch.Pwidth - w; x1 <= mStitch.Pwidth; x1 += 5)
+                    {
+                        y2 = 1;
+                        for (y1 = mStitch.Pheight - h + 1; y1 <= mStitch.Pheight; y1 += 5)
+                        {
+                            //块差分集计算
+                            CheckRC(ref x1, ref y1, mStitch.im);
+                            CheckRC(ref x2, ref y2, im2);
+                            imsum = imsum + Math.Abs(mStitch.im.At<Vec3b>(y1, x1).Item0 - im2.At<Vec3b>(y2, x2).Item0);
+                            y2 = y2 + 5;
+                        }
+                        x2 = x2 + 5;
+                    }
+                    //阈值更新
+                    if (imsum * 5 * 5 <= mStitch.minval * w * h)
+                    {
+                        mStitch.minval = imsum * 5 * 5 / (w * h);
+                        w_ind = w;
+                        h_ind = h;
+                    }
+                }
+            }
+
+            imageParam.W_box = w_ind;
+            imageParam.H_box = h_ind;
+            imageParam.bdown = 1;
+
+            //在下窗口所有匹配块内进行搜索
+            Parallel.For(mStitch.W_min, mStitch.W_max, w =>
+            {
+                Parallel.For(mStitch.H_min, mStitch.Pheight, h =>
+                {
+                    imsum = 0;//块差分集初始化
+                    x2 = 1;
+                    for (x1 = mStitch.Pwidth - w; x1 <= mStitch.Pwidth; x1 += 5)
+                    {
+                        y1 = 1;
+                        for (y2 = mStitch.Pheight - h + 1; y2 <= mStitch.Pheight; y2 += 5)
+                        {
+                            //块差分集计算
+                            CheckRC(ref x1, ref y1, mStitch.im);
+                            CheckRC(ref x2, ref y2, im2);
+                            imsum = imsum + Math.Abs(mStitch.im.At<Vec3b>(y1, x1).Item0 - im2.At<Vec3b>(y2, x2).Item0);
+                            y1 = y1 + 5;
+                        }
+                        x2 = x2 + 5;
+                    }
+                    //阈值更新
+                    if (imsum * 5 * 5 <= mStitch.minval * w * h)
+                    {
+                        mStitch.minval = imsum * 5 * 5 / (w * h);
+                        w_ind = w;
+                        h_ind = h;
+                        imageParam.bdown = 0;
+                    }
+                });
+            });
+
+            imageParam.mStitch = mStitch;
+
+            return imageParam;
+        }
+
+        public static void CheckRC(ref int x, ref int y, Mat im)
+        {
+            //图像矩阵访问有效性检测
+            // 输入参数:
+            // x——列
+            // y——行
+            // im——图像矩阵
+            // 输出参数:
+            // x——列
+            // y——行
+            y = Math.Max(y, 1);
+            y = Math.Min(y, im.Height - 1);
+            x = Math.Max(x, 1);
+            x = Math.Min(x, im.Width - 1);
+        }
+
+        public Mat Fun_Stitch(ImageParam imageParam)
+        {
+            //图像融合
+            //输入参数:
+            //im2——待融合图像
+            //W_box——宽度信息
+            //H_box——高度信息
+            //bdown——上下信息
+            //MStitch——参数结构
+            //输出参数:
+            //MStitch——参数结构
+            //im——融合图像
+
+            Mat img = imageParam.im;
+            int x1 = 0;
+            int y1 = 0;
+            int x2 = 0;
+            int y2 = 0;
+            double w = 0.5; //融合权值
+
+            if (imageParam.bdown == 1)
+            {
+                //下区域重叠
+                x2 = 1;
+                //融合重叠区域
+                for (x1 = imageParam.mStitch.Pwidth - imageParam.W_box; x1 < imageParam.mStitch.Pwidth; x1++)
+                {
+                    y2 = 1;
+                    for (y1 = imageParam.mStitch.Pheight - imageParam.H_box + 1; y1 < imageParam.mStitch.Pheight; y1++)
+                    {
+                        //安全性检测
+                        CheckRC(ref x1, ref y1, imageParam.mStitch.im);
+                        CheckRC(ref x2, ref y2, imageParam.im);
+                        //融合权值
+                        w = (double)x2 / (double)imageParam.W_box;
+                        //加权融合
+                        double ColorRGB = imageParam.mStitch.im.At<Vec3b>(y1, x1).Item0 * (1.0 - w) + imageParam.im.At<Vec3b>(y2, x2).Item0 * w;
+                        imageParam.mStitch.im.Set<Vec3b>(y1, x1, new Vec3b((byte)ColorRGB, (byte)ColorRGB, (byte)ColorRGB));
+                        y2 = y2 + 1;
+                    }
+                    x2 = x2 + 1;
+                }
+            }
+            else
+            {
+                //上区域重叠
+                x2 = 1;
+                //融合重叠区域
+                for (x1 = imageParam.mStitch.Pwidth - imageParam.W_box; x1 < imageParam.mStitch.Pwidth; x1++)
+                {
+                    y2 = 1;
+                    for (y1 = imageParam.mStitch.Pheight - imageParam.H_box + 1; y1 < imageParam.mStitch.Pheight; y1++)
+                    {
+                        //安全性检测
+                        CheckRC(ref x1, ref y1, imageParam.mStitch.im);
+                        CheckRC(ref x2, ref y2, imageParam.im);
+                        //融合权值
+                        w = (double)x2 / (double)imageParam.W_box;
+                        //加权融合
+                        double ColorRGB = imageParam.mStitch.im.At<Vec3b>(y1, x1).Item0 * (1.0 - w) + imageParam.im.At<Vec3b>(y2, x2).Item0 * w;
+                        imageParam.mStitch.im.Set<Vec3b>(y1, x1, new Vec3b((byte)ColorRGB, (byte)ColorRGB, (byte)ColorRGB));
+
+                        y2 = y2 + 1;
+                    }
+                    x2 = x2 + 1;
+                }
+            }
+
+            //最终图
+            img = new Mat(imageParam.mStitch.Pheight, imageParam.mStitch.Pwidth + imageParam.im.Width - x2 + 1, MatType.CV_8UC3);
+
+            //分离出重叠区域
+            OpenCvSharp.Rect m_select = new OpenCvSharp.Rect(x2 - 1, 0, imageParam.im.Width - x2 + 1, imageParam.mStitch.Pheight);
+            Mat imgSwitch = new Mat(imageParam.im, m_select);
+            Cv2.HConcat(imageParam.mStitch.im, imgSwitch, img);
+
+            return img;
+        }
+
+        public Mat Fun_StitchRGB(ImageParam imageParam)
+        {
+            //图像融合
+            //输入参数:
+            //im2——待融合图像
+            //W_box——宽度信息
+            //H_box——高度信息
+            //bdown——上下信息
+            //MStitch——参数结构
+            //输出参数:
+            //MStitch——参数结构
+            //im——融合图像
+
+            Mat img = imageParam.im;
+            int x1 = 0;
+            int y1 = 0;
+            int x2 = 0;
+            int y2 = 0;
+            double w = 0.5; //融合权值
+
+            if (imageParam.bdown == 1)
+            {
+                //下区域重叠
+                x2 = 1;
+                //融合重叠区域
+                for (x1 = imageParam.mStitch.Pwidth - imageParam.W_box; x1 < imageParam.mStitch.Pwidth; x1++)
+                {
+                    y2 = 1;
+                    for (y1 = imageParam.mStitch.Pheight - imageParam.H_box + 1; y1 < imageParam.mStitch.Pheight; y1++)
+                    {
+                        //安全性检测
+                        CheckRC(ref x1, ref y1, imageParam.mStitch.im);
+                        CheckRC(ref x2, ref y2, imageParam.im);
+                        //融合权值
+                        w = (double)x2 / (double)imageParam.W_box;
+                        //加权融合
+                        double ColorR = imageParam.mStitch.im.At<Vec3b>(y1, x1).Item0 * (1.0 - w) + imageParam.im.At<Vec3b>(y2, x2).Item0 * w;
+                        double ColorG = imageParam.mStitch.im.At<Vec3b>(y1, x1).Item1 * (1.0 - w) + imageParam.im.At<Vec3b>(y2, x2).Item1 * w;
+                        double ColorB = imageParam.mStitch.im.At<Vec3b>(y1, x1).Item2 * (1.0 - w) + imageParam.im.At<Vec3b>(y2, x2).Item2 * w;
+                        if (imageParam.mStitch.im.At<Vec3b>(y1, x1).Item0 == imageParam.mStitch.im.At<Vec3b>(y1, x1).Item1 &&
+                            imageParam.mStitch.im.At<Vec3b>(y1, x1).Item1 == imageParam.mStitch.im.At<Vec3b>(y1, x1).Item2 &&
+                            imageParam.im.At<Vec3b>(y2, x2).Item0 == imageParam.im.At<Vec3b>(y2, x2).Item1 &&
+                            imageParam.im.At<Vec3b>(y2, x2).Item1 == imageParam.im.At<Vec3b>(y2, x2).Item2)
+                        {
+                            imageParam.mStitch.im.Set<Vec3b>(y1, x1, new Vec3b((byte)ColorR, (byte)ColorG, (byte)ColorB));
+                        }
+                        else
+                        {
+
+                        }
+
+                        y2 = y2 + 1;
+                    }
+                    x2 = x2 + 1;
+                }
+            }
+            else
+            {
+                //上区域重叠
+                x2 = 1;
+                //融合重叠区域
+                for (x1 = imageParam.mStitch.Pwidth - imageParam.W_box; x1 < imageParam.mStitch.Pwidth; x1++)
+                {
+                    y2 = 1;
+                    for (y1 = imageParam.mStitch.Pheight - imageParam.H_box + 1; y1 < imageParam.mStitch.Pheight; y1++)
+                    {
+                        //安全性检测
+                        CheckRC(ref x1, ref y1, imageParam.mStitch.im);
+                        CheckRC(ref x2, ref y2, imageParam.im);
+                        //融合权值
+                        w = (double)x2 / (double)imageParam.W_box;
+                        //加权融合
+                        double ColorR = imageParam.mStitch.im.At<Vec3b>(y1, x1).Item0 * (1.0 - w) + imageParam.im.At<Vec3b>(y2, x2).Item0 * w;
+                        double ColorG = imageParam.mStitch.im.At<Vec3b>(y1, x1).Item1 * (1.0 - w) + imageParam.im.At<Vec3b>(y2, x2).Item1 * w;
+                        double ColorB = imageParam.mStitch.im.At<Vec3b>(y1, x1).Item2 * (1.0 - w) + imageParam.im.At<Vec3b>(y2, x2).Item2 * w;
+                        if (imageParam.mStitch.im.At<Vec3b>(y1, x1).Item0 == imageParam.mStitch.im.At<Vec3b>(y1, x1).Item1 &&
+                            imageParam.mStitch.im.At<Vec3b>(y1, x1).Item1 == imageParam.mStitch.im.At<Vec3b>(y1, x1).Item2 &&
+                            imageParam.im.At<Vec3b>(y2, x2).Item0 == imageParam.im.At<Vec3b>(y2, x2).Item1 &&
+                            imageParam.im.At<Vec3b>(y2, x2).Item1 == imageParam.im.At<Vec3b>(y2, x2).Item2)
+                        {
+                            imageParam.mStitch.im.Set<Vec3b>(y1, x1, new Vec3b((byte)ColorR, (byte)ColorG, (byte)ColorB));
+                        }
+                        else
+                        {
+
+                        }
+
+                        y2 = y2 + 1;
+                    }
+                    x2 = x2 + 1;
+                }
+            }
+
+            //最终图
+            img = new Mat(imageParam.mStitch.Pheight, imageParam.mStitch.Pwidth + imageParam.im.Width - x2 + 1, MatType.CV_8UC3);
+
+            //分离出重叠区域
+            OpenCvSharp.Rect m_select = new OpenCvSharp.Rect(x2 - 1, 0, imageParam.im.Width - x2 + 1, imageParam.mStitch.Pheight);
+            Mat imgSwitch = new Mat(imageParam.im, m_select);
+            Cv2.HConcat(imageParam.mStitch.im, imgSwitch, img);
+
+            return img;
+        }
+        #endregion
     }
 }

+ 4 - 22
OTSIncAReportApp/1-UI/Control_Graph/Controls/Control_DrawDistrbutionImageAndBSE.cs

@@ -59,6 +59,7 @@ namespace OTSIncAReportGraph.Controls
     {
         pic=0,
         Render_pic=1,
+        noBackground_pic = 2,
         Combin,
         Render_Combin
     }
@@ -2240,7 +2241,7 @@ namespace OTSIncAReportGraph.Controls
                 outpic.m_list_allDfield = m_list_allDfield;
                 outpic.resultFile = resultFile;
                 outpic.sfd = sfd;
-                outpic.type = (int)Outpic_enum.Combin;
+                outpic.type = (int)Outpic_enum.noBackground_pic;
                 outpic.m_ReportApp = m_ReportApp;
                 Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic));
 
@@ -2280,7 +2281,7 @@ namespace OTSIncAReportGraph.Controls
                 outpic.resultFile = resultFile;
                 outpic.sfd = sfd;
                 outpic.type = (int)Outpic_enum.Render_Combin;
-                Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic));
+                Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic2));
                 bThread.IsBackground = true;
                 bThread.Start();
             }
@@ -2299,26 +2300,7 @@ namespace OTSIncAReportGraph.Controls
                 outpic.resultFile = resultFile;
                 outpic.sfd = sfd;
                 outpic.type = (int)Outpic_enum.Combin;
-                Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic));
-                bThread.IsBackground = true;
-                bThread.Start();
-            }
-        }
-
-        private void toolStripMenuItem_combinClass_Click_1(object sender, EventArgs e)
-        {
-            SaveFileDialog sfd = new SaveFileDialog();
-            //|ALL Files(*.*)|*.*
-            //BMP Files(*.bmp)| *.bmp |
-            sfd.Filter = "png Files(*.png)| *.png |BMP Files(*.bmp)| *.bmp |JPG Files(*.jpg)|*.jpg;*.jpeg";
-            if (sfd.ShowDialog() == DialogResult.OK)
-            {
-                OutPIC outpic = new OutPIC();
-                outpic.m_list_allDfield = m_list_allDfield;
-                outpic.resultFile = resultFile;
-                outpic.sfd = sfd;
-                outpic.type = (int)Outpic_enum.Render_Combin;
-                Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic));
+                Thread bThread = new Thread(new ThreadStart(outpic.opencv_outpic2));
                 bThread.IsBackground = true;
                 bThread.Start();
             }

+ 12 - 10
OTSIncAReportApp/1-UI/Control_Graph/Controls/Control_DrawDistrbutionImageAndBSE.designer.cs

@@ -43,12 +43,12 @@
             this.aSTMToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
             this.显示所有帧ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
             this.清除ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+            this.toolStripMenuItem_combin = new System.Windows.Forms.ToolStripMenuItem();
             this.toolStripMenuItem_combinClass = new System.Windows.Forms.ToolStripMenuItem();
             this.contextMenuStrip_Particle = new System.Windows.Forms.ContextMenuStrip(this.components);
             this.ToolStripMenuItem_movesempoint = new System.Windows.Forms.ToolStripMenuItem();
             this.toolStripMenuItem_DeleteParticles = new System.Windows.Forms.ToolStripMenuItem();
             this.toolStripMenuItem_Segmentation = new System.Windows.Forms.ToolStripMenuItem();
-            this.toolStripMenuItem_combin = new System.Windows.Forms.ToolStripMenuItem();
             this.CMenuStrip.SuspendLayout();
             this.contextMenuStrip_Particle.SuspendLayout();
             this.SuspendLayout();
@@ -64,7 +64,7 @@
             this.toolStripMenuItem_combin,
             this.toolStripMenuItem_combinClass});
             this.CMenuStrip.Name = "contextMenuStrip1";
-            this.CMenuStrip.Size = new System.Drawing.Size(185, 158);
+            this.CMenuStrip.Size = new System.Drawing.Size(185, 136);
             // 
             // ToolStripMenuItem_ParticleSplicing
             // 
@@ -172,12 +172,21 @@
             this.清除ToolStripMenuItem.Text = "清除";
             this.清除ToolStripMenuItem.Click += new System.EventHandler(this.清除ToolStripMenuItem_Click);
             // 
+            // toolStripMenuItem_combin
+            // 
+            this.toolStripMenuItem_combin.Name = "toolStripMenuItem_combin";
+            this.toolStripMenuItem_combin.Size = new System.Drawing.Size(184, 22);
+            this.toolStripMenuItem_combin.Text = "导出原图融合图";
+            this.toolStripMenuItem_combin.Visible = false;
+            this.toolStripMenuItem_combin.Click += new System.EventHandler(this.toolStripMenuItem_combin_Click);
+            // 
             // toolStripMenuItem_combinClass
             // 
             this.toolStripMenuItem_combinClass.Name = "toolStripMenuItem_combinClass";
             this.toolStripMenuItem_combinClass.Size = new System.Drawing.Size(184, 22);
             this.toolStripMenuItem_combinClass.Text = "导出原图融合分类图";
-            this.toolStripMenuItem_combinClass.Click += new System.EventHandler(this.toolStripMenuItem_combinClass_Click_1);
+            this.toolStripMenuItem_combinClass.Visible = false;
+            this.toolStripMenuItem_combinClass.Click += new System.EventHandler(this.toolStripMenuItem_combinClass_Click);
             // 
             // contextMenuStrip_Particle
             // 
@@ -210,13 +219,6 @@
             this.toolStripMenuItem_Segmentation.Text = "分割颗粒";
             this.toolStripMenuItem_Segmentation.Click += new System.EventHandler(this.toolStripMenuItem_Segmentation_Click);
             // 
-            // toolStripMenuItem_combin
-            // 
-            this.toolStripMenuItem_combin.Name = "toolStripMenuItem_combin";
-            this.toolStripMenuItem_combin.Size = new System.Drawing.Size(184, 22);
-            this.toolStripMenuItem_combin.Text = "导出原图融合图";
-            this.toolStripMenuItem_combin.Click += new System.EventHandler(this.toolStripMenuItem_combin_Click);
-            // 
             // Control_DrawDistrbutionImageAndBSE
             // 
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;

+ 254 - 1
OTSIncAReportApp/1-UI/Control_Graph/Controls/OutPIC.cs

@@ -2,6 +2,7 @@
 using OTSIncAReportGraph;
 using OTSIncAReportGraph.Class;
 using OTSIncAReportGraph.Controls;
+using OTSModelSharp.ServiceCenter;
 using System;
 using System.Collections.Generic;
 using System.Data;
@@ -566,10 +567,262 @@ namespace OTSIncAReportApp._3_ServiceCenter
 
             return list_dt_picdata;
         }
+        #region 合并天宇颗粒融合新增函数
+        public void opencv_outpic2(/*int type*/)
+        {
+            List<DataTable> list_dt_picdata = new List<DataTable>();
+            if (type == (int)Outpic_enum.pic || type == (int)Outpic_enum.Combin)
+            {
+                list_dt_picdata = opencv_piclist2();
+            }
+            else if (type == (int)Outpic_enum.Render_pic || type == (int)Outpic_enum.Render_Combin)
+            {
+                list_dt_picdata = opencv_piclist_Render2();
+            }
+            OpenCvSharp.Mat save_pano = new OpenCvSharp.Mat();
+            OpenCvSharp.Mat[] list_mats = new OpenCvSharp.Mat[list_dt_picdata.Count];
+
+            if (type == (int)Outpic_enum.Combin || type == (int)Outpic_enum.Render_Combin)
+            {
+                CImageHandler cImageHandler = new CImageHandler();
+                Dictionary<string, object> sampleMembers = ((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["Sample"])["Members"]);
+                Dictionary<string, object> imageProcessParam = (Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)sampleMembers["MsrParams"])["Members"])["ImageProcessParam"];
+                object strOverlapParam = "";
+                imageProcessParam.TryGetValue("OverlapParam", out strOverlapParam);
+                if (strOverlapParam == null)
+                {
+                    NLog.LogManager.GetCurrentClassLogger().Info("There are no overlapping dimensions");
+                    return;
+                }
+                int OverlapParam = int.Parse(strOverlapParam.ToString());
+                List<OpenCvSharp.Mat> maxXList = new List<OpenCvSharp.Mat>();
+                for (int i = 0; i < list_dt_picdata.Count; i++)
+                {
+                    OpenCvSharp.Mat[] mats = new OpenCvSharp.Mat[list_dt_picdata[i].Rows.Count];
+                    for (int a = 0; a < list_dt_picdata[i].Rows.Count; a++)
+                    {
+                        mats[a] = OpenCvSharp.Extensions.BitmapConverter.ToMat((Bitmap)list_dt_picdata[i].Rows[a]["mat"]);
+                    }
+                    //横向拼接
+                    maxXList.Add(cImageHandler.CombinImageX(mats, OverlapParam, type));
+                }
+                save_pano = cImageHandler.CombinImageY(maxXList.ToArray(), OverlapParam, type);
+                OpenCvSharp.Cv2.ImWrite(sfd.FileName, save_pano);
+                NLog.LogManager.GetCurrentClassLogger().Info("Save complete.");
+            }
+            else
+            {
+                NLog.LogManager.GetCurrentClassLogger().Info("Organize and splice all pictures......");
+                for (int i = 0; i < list_dt_picdata.Count; i++)
+                {
+                    OpenCvSharp.Mat[] mats = new OpenCvSharp.Mat[list_dt_picdata[i].Rows.Count];
+                    for (int a = 0; a < list_dt_picdata[i].Rows.Count; a++)
+                    {
+                        mats[a] = OpenCvSharp.Extensions.BitmapConverter.ToMat((Bitmap)list_dt_picdata[i].Rows[a]["mat"]);
+                    }
+                    OpenCvSharp.Mat pano = new OpenCvSharp.Mat();
+                    OpenCvSharp.Cv2.HConcat(mats, pano);
+                    list_mats[i] = pano;
+
+                }
+                NLog.LogManager.GetCurrentClassLogger().Info("Picture splicing completed.");
+                NLog.LogManager.GetCurrentClassLogger().Info("Save to disk......");
+
+                OpenCvSharp.Cv2.VConcat(list_mats, save_pano);
+                OpenCvSharp.Cv2.ImWrite(sfd.FileName, save_pano);
+                NLog.LogManager.GetCurrentClassLogger().Info("Save complete.");
+            }
+        }
+
+        private List<DataTable> opencv_piclist_Render2()
+        {
+            List<DataTable> list_dt_picdata = new List<DataTable>();
+            DataTable picDatat = new DataTable();
+            List<Field> fieldlist = resultFile.List_OTSField;
+            picDatat.Columns.Add("X", typeof(double));
+            picDatat.Columns.Add("Y", typeof(double));
+            foreach (var f in m_list_allDfield)
+            {
+                DataRow dr = picDatat.NewRow();
+                dr["X"] = f.GetShowRect().X;
+                dr["Y"] = f.GetShowRect().Y;
+                picDatat.Rows.Add(dr);
+            }
+            int y_max = Convert.ToInt32(picDatat.Compute("Max(Y)", "true"));
+            int y_min = Convert.ToInt32(picDatat.Compute("Min(Y)", "true"));
+            DataTable total_dt_X = picDatat.Copy();
+            DataView dv_x = total_dt_X.DefaultView;
+            DataView dv_x_2 = dv_x.ToTable(true, "X").DefaultView;
+            dv_x_2.Sort = "X ASC";
+            total_dt_X = dv_x_2.ToTable();
+
+
+            DataTable total_dt_Y = picDatat.Copy();
+            DataView dv_Y = total_dt_Y.DefaultView;
+            DataView dv_Y_2 = dv_Y.ToTable(true, "Y").DefaultView;
+            dv_Y_2.Sort = "Y ASC";
+            total_dt_Y = dv_Y_2.ToTable();
+
+
+            for (int i = 0; i < total_dt_Y.Rows.Count; i++)
+            {
+                NLog.LogManager.GetCurrentClassLogger().Info("Splice line" + i + 1.ToString() + "of" + total_dt_Y.Rows.Count.ToString() + ".....");
+
+                DataTable data = new DataTable();
+                data.Columns.Add("mat", typeof(Bitmap));
+                data.Columns.Add("X", typeof(double));
+                for (int a = 0; a < total_dt_X.Rows.Count; a++)
+                {
+                    DataRow dr2 = data.NewRow();
+                    Bitmap bitmap = new Bitmap((int)m_list_allDfield[0].GetShowRect().Width, (int)m_list_allDfield[0].GetShowRect().Height);
+                    Graphics g = Graphics.FromImage(bitmap);
+                    g.Clear(Color.White);
+                    g.Dispose();
+                    dr2["mat"] = bitmap;
+                    dr2["X"] = total_dt_X.Rows[a]["X"];
+                    data.Rows.Add(dr2);
+                }
+                foreach (var f in m_list_allDfield)
+                {
+                    if (total_dt_Y.Rows[i]["Y"].ToString() == f.GetShowRect().Y.ToString())
+                    {
+                        for (int c = 0; c < data.Rows.Count; c++)
+                        {
+                            if (data.Rows[c]["X"].ToString() == f.GetShowRect().X.ToString())
+                            {
+                                Bitmap image = new Bitmap(f.OriginalImage.Width, f.OriginalImage.Height);
+                                Graphics g2 = Graphics.FromImage(image);
+                                g2.DrawImage(f.OriginalImage, 0, 0, f.OriginalImage.Width, f.OriginalImage.Height);
+                                Graphics graph_2 = Graphics.FromImage(image);
+
+                                for (int a = 0; a < fieldlist.Count; a++)
+                                {
+                                    if (fieldlist[a].FieldID.ToString() == f.FieldID.ToString())
+                                    {
+                                        //先获取该Field中的所有Particle
+                                        List<Particle> list_particle;
+                                        list_particle = fieldlist[a].ParticleList;
+                                        //再循环计算所有的Particle对象
+                                        foreach (Particle particle in list_particle)
+                                        {
+                                            //创建DParticle颗粒
+                                            DisplayParticle dp = new DisplayParticle(particle);
+                                            List<Segment> list_seg;
+                                            list_seg = particle.SegmentList;
+                                            //创建颗粒分布图对应的类对象
+                                            List<DisplaySegment> list_dsegment = new List<DisplaySegment>();
+                                            //再循环取出里面所有的segment
+                                            foreach (Segment seg in list_seg)
+                                            {
+                                                #region 创建DSegment对象,并将STD分析出的化合物颜色保存到DSegment对象中
+
+                                                Point on_p = new Point() { X = seg.Start, Y = seg.Height };
+                                                Point off_p = new Point() { X = seg.Start + seg.Length, Y = seg.Height };
+                                                Pen npen = new Pen(dp.Color);
+                                                graph_2.DrawLine(npen, on_p, off_p);
+
+                                                #endregion
+                                            }
+                                        }
+                                    }
+                                }
+                                data.Rows[c]["mat"] = image;
+                                data.Rows[c]["X"] = f.GetShowRect().X; 
+                            }
+                        }
+                    }
+
+                }
+
+                DataView dataView1 = data.DefaultView;
+                dataView1.Sort = "X ASC";
+                data = dataView1.ToTable();
+                list_dt_picdata.Add(data);
+            }
+
+            return list_dt_picdata;
+        }
+        /// <summary>
+        /// 获取每行图片的位置配合opencv方法使用
+        /// </summary>
+        /// <returns></returns>
+        private List<DataTable> opencv_piclist2()
+        {
+            List<DataTable> list_dt_picdata = new List<DataTable>();
+            DataTable picDatat = new DataTable();
+            picDatat.Columns.Add("X", typeof(double));
+            picDatat.Columns.Add("Y", typeof(double));
+            foreach (var f in m_list_allDfield)
+            {
+                DataRow dr = picDatat.NewRow();
+                dr["X"] = f.GetShowRect().X;
+                dr["Y"] = f.GetShowRect().Y;
+                picDatat.Rows.Add(dr);
+            }
+            int y_max = Convert.ToInt32(picDatat.Compute("Max(Y)", "true"));
+            int y_min = Convert.ToInt32(picDatat.Compute("Min(Y)", "true"));
+            DataTable total_dt_X = picDatat.Copy();
+            DataView dv_x = total_dt_X.DefaultView;
+            DataView dv_x_2 = dv_x.ToTable(true, "X").DefaultView;
+            dv_x_2.Sort = "X ASC";
+            total_dt_X = dv_x_2.ToTable();
+
+
+            DataTable total_dt_Y = picDatat.Copy();
+            DataView dv_Y = total_dt_Y.DefaultView;
+            DataView dv_Y_2 = dv_Y.ToTable(true, "Y").DefaultView;
+            dv_Y_2.Sort = "Y ASC";
+            total_dt_Y = dv_Y_2.ToTable();
+
+
+            for (int i = 0; i < total_dt_Y.Rows.Count; i++)
+            {
+                NLog.LogManager.GetCurrentClassLogger().Info("Splice line" + i + 1.ToString() + "of" + total_dt_Y.Rows.Count.ToString() + ".....");
+                DataTable data = new DataTable();
+                data.Columns.Add("mat", typeof(Bitmap));
+                data.Columns.Add("X", typeof(double));
+                for (int a = 0; a < total_dt_X.Rows.Count; a++)
+                {
+                    DataRow dr2 = data.NewRow();
+                    Bitmap bitmap = new Bitmap((int)m_list_allDfield[0].GetShowRect().Width, (int)m_list_allDfield[0].GetShowRect().Height);
+                    Graphics g = Graphics.FromImage(bitmap);
+                    g.Clear(Color.White);
+                    g.Dispose();
+                    dr2["mat"] = bitmap;
+                    dr2["X"] = total_dt_X.Rows[a]["X"];
+                    data.Rows.Add(dr2);
+                }
+                foreach (var f in m_list_allDfield)
+                {
+                    if (total_dt_Y.Rows[i]["Y"].ToString() == f.GetShowRect().Y.ToString())
+                    {
+                        for (int c = 0; c < data.Rows.Count; c++)
+                        {
+                            if (data.Rows[c]["X"].ToString() == f.GetShowRect().X.ToString())
+                            {
+                                data.Rows[c]["mat"] = f.OriginalImage;
+                                data.Rows[c]["X"] = f.GetShowRect().X;
+                            }
+                        }
+
+                    }
+                }
+
+
+                DataView dataView1 = data.DefaultView;
+                dataView1.Sort = "X ASC";
+                data = dataView1.ToTable();
+
+
+                list_dt_picdata.Add(data);
+            }
+
+            return list_dt_picdata;
+        }
+        #endregion
 
 
 
-       
         public delegate void MyEntrust();
         public event MyEntrust MyEvent;
        

+ 94 - 4
OTSIncAReportApp/2-CommonFunction/CommonClass/DisplayParticle.cs

@@ -131,7 +131,13 @@ namespace OTSIncAReportGraph
         {
             m_id = System.Guid.NewGuid();
         }
+        public DisplayParticle(Particle part)
+        {
+            m_id = System.Guid.NewGuid();
+            objParticleData = part;
+            this.Color = GetColorBySTDTypeIDForBSEAndSorImage(part.TypeColor, part.TypeId);
 
+        }
         public DisplayParticle(Particle particle,Point screenPos,Bitmap originalFieldImage,Bitmap fieldParticleImage)
         {
          
@@ -902,11 +908,95 @@ namespace OTSIncAReportGraph
 
             return rect;
         }
-    }
-
-
+        public Color GetColorBySTDTypeIDForBSEAndSorImage(string in_partcolor, int in_stdtypeid)
+        {
+            Color ret_c = new Color();
 
-   
 
+            if (in_stdtypeid < 1000)
+            {
 
+                ret_c = GetColorByEnum(in_stdtypeid);
+            }
+            else if (in_stdtypeid >= 1000)
+            {
+                //大于等于1000,并且小于10000时,使用用户标准库来分析夹杂物名称
+                if (!in_partcolor.Contains("#"))
+                {
+                    ret_c = DrawFunction.colorHx16toRGB("#" + in_partcolor);//接收必须是#000000的格式
+                }
+                else
+                {
+                    ret_c = DrawFunction.colorHx16toRGB(in_partcolor);//接收必须是#000000的格式
+                }
+            }
+            return ret_c;
+        }
+        public Color GetColorByEnum(int STDID)
+        {
+            Color ret_c = new Color();
+            switch (STDID)
+            {
+                case -1:
+                    //INVALID = -1,
+                    //stdName = "无效颗粒";
+                    ret_c = Color.Black;
+                    break;
+                case 0:
+                    //small = 0;
+                    //stdName = "过小颗粒";
+                    ret_c = Color.Black;
+                    break;
+                case 1:
+                    //OVERSIZE = 1,
+                    //stdName = "过大颗粒";
+                    ret_c = Color.Black;
+                    break;
+                case 2:
+                    //AVE_GRAY_NOT_INRANRE = 2, 
+                    //stdName = "亮度不在分析范围内的颗粒";
+                    ret_c = Color.Black;
+                    break;
+                case 3:
+                    //SEARCH_X_RAY = 3,
+                    //stdName = "不进行搜索x-ray分析的颗粒";
+                    ret_c = Color.Black;
+                    break;
+                case 4:
+                    //LOW_COUNT = 4, 
+                    //stdName = "低x-ray计数颗粒";
+                    ret_c = Color.Black;
+                    break;
+                case 5:
+                    //NO_INTEREST_ELEMENTS = 5,
+                    //stdName = "不含分析元素的颗粒";
+                    ret_c = Color.Black;
+                    break;
+                case 6:
+                    //ALAYSIS_X_RAY = 6,
+                    //stdName = "不进行x-ray分析的颗粒";
+                    ret_c = Color.Black;
+                    break;
+                case 7:
+                    //NOT_IDENTIFIED = 7,
+                    //stdName = "未识别颗粒";
+                    ret_c = Color.Black;
+                    break;
+                case 8:
+                    //NOT_IDENTIFIED = 8,
+                    //stdName = "未识别颗粒";
+                    ret_c = Color.Black;
+                    break;
+                case 9:
+                    //NOT_IDENTIFIED = 9,
+                    //stdName = "未识别颗粒";
+                    ret_c = Color.Black;
+                    break;
+                default:
+                    ret_c = Color.Black;
+                    break;
+            }
+            return ret_c;
+        }
+    }
 }