Exemplo n.º 1
0
        /// <summary>
        /// 计算是否需要单独多设置一个线程处理尾数.
        /// </summary>
        /// <param name="nSetThread"></param>
        /// <param name="nPiPeiSize"></param>
        /// <returns></returns>
        private int GetThreadNum(int nSetThread, MatrixCiCui nPiPeiSize)
        {
            int nRtn = 0;

            int nTotal = nPiPeiSize.horSize * nPiPeiSize.verSize;

            if (0 != (nTotal % nSetThread))
            {
                nRtn = nSetThread + 1;
            }
            else
            {
                nRtn = nSetThread;
            }

            return(nRtn);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 根据小图和大图的尺寸 计算匹配的次数
        /// 用于为各个线程分配
        /// </summary>
        /// <param name="PicMatch"></param>
        /// <param name="PicBase"></param>
        /// <returns></returns>
        private MatrixCiCui GetPiPeiTime(double[,] PicMatch, double[,] PicBase)
        {
            MatrixCiCui nRtn = new MatrixCiCui();

            int BaseHor  = GetHorLength(PicBase);
            int MatchHor = GetHorLength(PicMatch);

            nRtn.horSize = BaseHor - MatchHor + 1;


            int BaseVer  = GetVerLength(PicBase);
            int MatchVer = GetVerLength(PicMatch);

            nRtn.verSize = BaseVer - MatchVer + 1;



            return(nRtn);
        }
Exemplo n.º 3
0
        public void Run()
        {
            // Console.WriteLine("Hello World!");

            int nSetThread = 7;

            // 先完成一个配置项
            // 一个BasePic和一个目录=》 txt匹配结果

            //String strBasePic = "";
            //String StrDir = "";

            // 先完成单个基础匹配策略.
            // 一个BasePic和一个MatchPic => txt匹配结果

            //String strBase = "../../../BasePics/ccd.tif";
            //String strMatch = "../../../IR_Report/IR_256_256_20/Pic/ir_256_256_0_0.tif";

            String strBase  = "../../../BasePics/ccd3.tif";
            String strMatch = "../../../IR3_Report/IR3_256_256_20/Pic/ir3_256_256_0_0.tif";

            // 提取文件的Row和Col组合
            String fileLocation = GetLocationForm(strMatch);

            // 按照层次位置读取文件.
            mySize BaseSize = GetPicSize(strBase);

            double[,] PicBase = new double[BaseSize.ROW, BaseSize.COL];

            mySize matchSize = GetPicSize(strMatch);

            double[,] PicMatch = new double[matchSize.ROW, matchSize.COL];

            // 把图片数字设置到分配的内存里
            SetPicData(strBase, PicBase);
            SetPicData(strMatch, PicMatch);

            // 计算移动一个像素点时 需要匹配的次数.
            MatrixCiCui nPiPeiSize = GetPiPeiTime(PicMatch, PicBase);


            // 为每个线程对象分配 区域匹配任务.
            // 计算是否单独多设置一个线程
            int HandleUnitNUM           = GetThreadNum(nSetThread, nPiPeiSize);
            List <HandleUnit> HUnitList = new List <HandleUnit>();

            for (int i = 0; i < HandleUnitNUM; i++)
            {
                HandleUnit hu = new HandleUnit();
                HUnitList.Add(hu);
            }

            // 为每一个处理单元分配区域. 这里的值只是个数,从0计数
            int TotalNum = nPiPeiSize.horSize * nPiPeiSize.verSize;
            int baseTask = TotalNum / nSetThread;

            for (int i = 0; i < HandleUnitNUM; i++)
            {
                HandleUnit each = HUnitList[i];
                each.nStart = i * baseTask;
                each.nEnd   = each.nStart + baseTask - 1;
                // 设置最后一个特殊值.
                if (each.nEnd > (TotalNum - 1))
                {
                    each.nEnd = TotalNum - 1;
                }


                each.mBasePic   = PicBase;
                each.mMatchPic  = PicMatch;
                each.mPiPeiSize = nPiPeiSize;
            }


            //设置线程.
            List <Thread> threadList = new List <Thread>();

            for (int i = 0; i < HandleUnitNUM; i++)
            {
                Thread HandleThread;          // 发送数据的线程对象.

                HandleUnit each = HUnitList[i];

                HandleThread = new Thread(new ThreadStart(each.Matching));

                threadList.Add(HandleThread);
            }



            // 同时启动线程
            for (int i = 0; i < HandleUnitNUM; i++)
            {
                Thread each = threadList[i];
                each.Start();
            }

            Console.WriteLine("Here");

            bool bExit = false;

            while (false == bExit)
            {
                bExit = CheckStop(threadList);
            }

            // 在分线程全部做完操作后 还可以整合资源

            // 从HUnitList里找出最大的值 并输出文件结果

            // 组合集合.

            Hashtable TotalHT = GetTotalHT(HUnitList);

            Location lResult = GetLocation(TotalHT);

            // Console.WriteLine("{0},{1}",lResult.row,lResult.column);

            // 写文件.
            String strLog = "TestLog.txt";


            //WriteLog(lResult, strMatch, strLog);


            Console.ReadLine();
        }
Exemplo n.º 4
0
        public String myRun(String strBase,
                            String strMatch,
                            int nSetThread)
        {
            String strRtn = string.Empty;

            // 提取文件的Row和Col组合
            String fileLocation = GetLocationForm(strMatch);

            // 按照层次位置读取文件.
            mySize BaseSize = GetPicSize(strBase);

            double[,] PicBase = new double[BaseSize.ROW, BaseSize.COL];

            mySize matchSize = GetPicSize(strMatch);

            double[,] PicMatch = new double[matchSize.ROW, matchSize.COL];

            // 把图片数字设置到分配的内存里
            SetPicData(strBase, PicBase);
            SetPicData(strMatch, PicMatch);

            // 计算移动一个像素点时 需要匹配的次数.
            MatrixCiCui nPiPeiSize = GetPiPeiTime(PicMatch, PicBase);


            // 为每个线程对象分配 区域匹配任务.
            // 计算是否单独多设置一个线程
            int HandleUnitNUM           = GetThreadNum(nSetThread, nPiPeiSize);
            List <HandleUnit> HUnitList = new List <HandleUnit>();

            for (int i = 0; i < HandleUnitNUM; i++)
            {
                HandleUnit hu = new HandleUnit();
                HUnitList.Add(hu);
            }

            // 为每一个处理单元分配区域. 这里的值只是个数,从0计数
            int TotalNum = nPiPeiSize.horSize * nPiPeiSize.verSize;
            int baseTask = TotalNum / nSetThread;

            for (int i = 0; i < HandleUnitNUM; i++)
            {
                HandleUnit each = HUnitList[i];
                each.nStart = i * baseTask;
                each.nEnd   = each.nStart + baseTask - 1;
                // 设置最后一个特殊值.
                if (each.nEnd > (TotalNum - 1))
                {
                    each.nEnd = TotalNum - 1;
                }


                each.mBasePic   = PicBase;
                each.mMatchPic  = PicMatch;
                each.mPiPeiSize = nPiPeiSize;
            }


            //设置线程.
            List <Thread> threadList = new List <Thread>();

            for (int i = 0; i < HandleUnitNUM; i++)
            {
                Thread HandleThread;          // 发送数据的线程对象.

                HandleUnit each = HUnitList[i];

                HandleThread = new Thread(new ThreadStart(each.Matching));

                threadList.Add(HandleThread);
            }



            // 同时启动线程
            for (int i = 0; i < HandleUnitNUM; i++)
            {
                Thread each = threadList[i];
                each.Start();
            }

            Console.WriteLine("Here");

            bool bExit = false;

            while (false == bExit)
            {
                bExit = CheckStop(threadList);
            }

            // 在分线程全部做完操作后 还可以整合资源

            // 从HUnitList里找出最大的值 并输出文件结果

            // 组合集合.

            Hashtable TotalHT = GetTotalHT(HUnitList);

            Location lResult = GetLocation(TotalHT);

            String strLo = string.Format("{0},{1}", lResult.row, lResult.column);

            // 写文件. 文件内容.
            strRtn = string.Format("{0} {1}", fileLocation, strLo);

            // 文件名字 大图+小图+小图位置.
            String StrLogName = GetLogName(strBase, strMatch, fileLocation);

            WriteLog(strRtn, StrLogName);

            return(strRtn);
        }