Exemplo n.º 1
0
        /// <summary>
        /// 位置检查图比较相似度
        /// </summary>
        /// <param name="dataElem">预先设定好的数据对象</param>
        /// <param name="excsd">期望相似度</param>
        /// <returns></returns>
        private bool RealTimeSynCheckPositionContrast(DataElem dataElem, int excsd = 12)
        {
            var bitmap    = BasicMethodClass.GetWindowCapture(configData.Hwnd);
            var cutbitmap = BasicMethodClass.CutImage(bitmap, dataElem.SynCheckPosition);

            bitmap.Dispose(); bitmap = null;

            int csd = BasicMethodClass.SimilarPhoto.CalcSimilarDegree(cutbitmap, dataElem.SynCheckImage);

            if (dataElem.curComparisonImage1 != null)
            {
                dataElem.curComparisonImage1.Dispose();
                dataElem.curComparisonImage1 = null;
            }
            if (dataElem.curComparisonImage2 != null)
            {
                dataElem.curComparisonImage2.Dispose();
                dataElem.curComparisonImage1 = null;
            }
            dataElem.curComparisonImage1 = cutbitmap;
            dataElem.curComparisonImage2 = new System.Drawing.Bitmap(dataElem.SynCheckImage);
            //  if (bitmap!=null)
            //      bitmap.Dispose();
            //   if (cutbitmap != null)
            //       cutbitmap.Dispose();
            return(csd < excsd);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取一个最具显著性的源区域
        /// </summary>
        /// <param name="FinSourceImage">源图</param>
        /// <returns></returns>
        public Bitmap GCSsimp_getLightRegionFromSource(Bitmap FinSourceImage)
        {
            int        DistWidth  = CutRect.Width;
            int        DistHeight = CutRect.Height;
            BitmapData srcBmData  = CurDestBitmap.LockBits(new Rectangle(0, 0, curDestImageWidth, curDestImageHeight),
                                                           ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
            IntPtr srcScan = srcBmData.Scan0;

            unsafe
            {
                srcP = (byte *)srcScan;
                int index = 0;
                if (fx == null)
                {
                    FindArea(srcBmData);
                }
                // if (MaxAreaArrValue == 0) throw new ArgumentException("Tolerance过低");
                int x_start = curDestImageWidth, x_end = 0, y_start = curDestImageHeight, y_end = 0;
                for (int y = 1; y < curDestImageHeight - 1; y++)
                {
                    index = y * srcBmData.Stride;
                    for (int x = 1; x < curDestImageWidth - 1; x++)
                    {
                        int Sx = fx[index].AreaNum;
                        //  if (Sx != 0) throw new Exception();
                        if (Sx == MAXAreaArrNumbler)
                        {
                            if (x_start > fx[index].point.X)
                            {
                                x_start = fx[index].point.X;
                            }
                            if (x_end < fx[index].point.X)
                            {
                                x_end = fx[index].point.X;
                            }
                            if (y_start > fx[index].point.Y)
                            {
                                y_start = fx[index].point.Y;
                            }
                            if (y_end < fx[index].point.Y)
                            {
                                y_end = fx[index].point.Y;
                            }
                        }
                        index++;
                    }
                }
                double _xm = (x_end + x_start) / 2.0;
                double _ym = (y_end + y_start) / 2.0;
                double _xs, _ys, _xe, _ye;
                double FinWidth = FinSourceImage.Width, FinHeight = FinSourceImage.Height;
                //projection by ratio
                _xm = _xm * FinWidth / curDestImageWidth;
                _ym = _ym * FinHeight / curDestImageHeight;
                //get rect of objective
                _xs = _xm - DistWidth / 2.0;
                _xe = _xm + DistWidth / 2.0;
                _ys = _ym - DistHeight / 2.0;
                _ye = _ym + DistHeight / 2.0;
                //cliping by rect
                if (_xs < 0)
                {
                    _xe += -_xs;
                    _xs  = 0;
                    if (_xe > FinWidth + 0.01)
                    {
                        throw new ArgumentException("cutting size is larger than source map");
                    }
                }
                else if (_xe > FinWidth)
                {
                    _xs -= _xe - FinWidth;
                    _xe  = FinWidth;
                    if (_xs < -0.01)
                    {
                        throw new ArgumentException("cutting size is larger than source map");
                    }
                }

                if (_ys < 0)
                {
                    _ye += -_ys;
                    _ys  = 0;
                    if (_ye > FinHeight + 0.01)
                    {
                        throw new ArgumentException("cutting size is larger than source map");
                    }
                }
                else if (_ye > FinHeight)
                {
                    _ys -= _ye - FinHeight;
                    _ye  = FinHeight;
                    if (_ys < -0.01)
                    {
                        throw new ArgumentException("cutting size is larger than source map");
                    }
                }

                CurDestBitmap.UnlockBits(srcBmData);
                CurDestBitmap.Dispose();
                CurDestBitmap = BasicMethodClass.CutImage(FinSourceImage, (int)_xs, (int)_ys, (int)_xe - (int)_xs, (int)_ye - (int)_ys);
            }
            return(CurDestBitmap);
        }