示例#1
0
        private void compareBlock(MyFilterData search, BitmapData refData, MyPlayer RefPlayer, int x, int y, matchRatePair dataRecord)
        {// compare the (x , y) similar rate && flash dataRecord & view
            if (!RefPlayer.flashIgnore)
            {
                RefPlayer.OnPlay(new MyPlayer.PlayEventArgs(-1, MyPlayer.PlayState.KEEP, x, y, compressKernelSize, compressKernelSize));
            }
            MyFilterData refKernelGet = new MyFilterData();

            refKernelGet.fill(refData, x, y, MyFilter.BorderMethod.ZERO, CompressKernel);
            double distance = MyFilterData.compare(search, refKernelGet, criteria);

            if (dataRecord > distance)
            {// find min distance
                dataRecord.rate = distance;
                dataRecord.x    = x;
                dataRecord.y    = y;
                if (!RefPlayer.flashIgnore)
                {
                    MyDeal.tryDraw(MatchViewer, refKernelGet.transToBitmap());
                }
            }
            Thread.Sleep(sleepTime);
        }
示例#2
0
        public double findMatchNormal(MyFilterData search, BitmapData refData, MyPlayer RefPlayer, ref int targetX, ref int targetY)
        {                                                     // 2D loorer methd if x,y < 0 ? all seach : local primary
            matchRatePair dataRecord    = new matchRatePair(Double.PositiveInfinity, 0, 0);
            MyFilterData  refKernelGet  = new MyFilterData(); // the data copy from ref frame of kernel size
            int           farDistance2  = 128;                //define half of this is mean the distance value from target is far
            int           nearDistance2 = 32;                 //define half of this is mean the distance value from target is near
            int           farJumpStap   = compressKernelSize; // define search pixel jump step lenth when seach in far area

            if ((targetX < 0) || (targetY < 0))
            {// search all pixels
                for (int y = 0 + compressKernelSize / 2; y < refData.Height; y += 1)
                {
                    for (int x = 0 + compressKernelSize / 2; x < refData.Width; x += 1)
                    {
                        if ((!RefPlayer.flashIgnore) && (x % 3 == 0))// reduce the reflash view frequence
                        {
                            RefPlayer.OnPlay(new MyPlayer.PlayEventArgs(-1, MyPlayer.PlayState.KEEP, x, y, compressKernelSize, compressKernelSize));
                        }
                        refKernelGet.fill(refData, x, y, MyFilter.BorderMethod.ZERO, CompressKernel);
                        double distance = MyFilterData.compare(search, refKernelGet, criteria);
                        if (dataRecord > distance)
                        {// find min distance
                            dataRecord.rate = distance;
                            dataRecord.x    = x;
                            dataRecord.y    = y;
                            if (!RefPlayer.flashIgnore)
                            {
                                MyDeal.tryDraw(MatchViewer, refKernelGet.transToBitmap());
                            }
                        }
                        Thread.Sleep(sleepTime);
                    }
                }
                targetX = dataRecord.x;
                targetY = dataRecord.y;
                return(dataRecord.rate);
            }
            else
            {//local primary
                // the far area  left & top posion
                int fx = targetX - farDistance2 / 2;
                int fy = targetY - farDistance2 / 2;
                // the near area posion
                int nl = targetX - nearDistance2 / 2;
                int nt = targetY - nearDistance2 / 2;
                int nr = targetX + nearDistance2 / 2;
                int nb = targetY + nearDistance2 / 2;

                int jumpStap = farJumpStap;
                for (int y = (fy < (0 + compressKernelSize / 2) ? (0 + compressKernelSize / 2) : fy); (y < refData.Height) && (y < fy + farDistance2); y += jumpStap)
                {
                    for (int x = (fx < (0 + compressKernelSize / 2) ? (0 + compressKernelSize / 2) : fx); (x < refData.Width) && (x < fx + farDistance2); x += jumpStap)
                    {
                        if ((x >= nl) && (x < nr) && (y >= nt) && (y < nb))
                        {// in near
                            jumpStap = 1;
                        }
                        else
                        {//in far
                            jumpStap = farJumpStap;
                        }
                        compareBlock(search, refData, RefPlayer, x, y, dataRecord);
                    }
                }
                targetX = dataRecord.x;
                targetY = dataRecord.y;
                return(dataRecord.rate);
            }
        }
示例#3
0
        protected void blockBaseMethod()
        {
            compressFile.type = MyCompressTiffDefine.TYPE.BLOCKBASE;
            if (RefPlayer != null)
            {
                Rectangle    cutRect      = new Rectangle(0, 0, compressKernelSize, compressKernelSize);
                MyFilterData CurKernelGet = new MyFilterData();// the data copy from cur frame of kernel
                MyFilterData RefKernelGet = new MyFilterData();
                for (int i = 0; i < RefPlayer.Tiff.Size; i++)
                {                                                                                 //run frames
                 //Debug.Print("in frame " + i);
                    trackBar.Invoke(new threadHandler2(progressTrack), i);                        // reflash progress view

                    RefPlayer.OnPlay(new MyPlayer.PlayEventArgs(i - 1, MyPlayer.PlayState.KEEP)); //flash ref frame view
                    CurPlayer.OnPlay(RefPlayer.NextView, new MyPlayer.PlayEventArgs(0));          //flash current frame view

                    //clear motion view
                    Bitmap motionBlock = null;
                    while (true)
                    {
                        try
                        {
                            motionBlock = new Bitmap(RefPlayer.NextView.Width, RefPlayer.NextView.Height);
                        }
                        catch (InvalidOperationException)
                        {
                            Thread.Sleep(29);
                            continue;
                        }
                        break;
                    }
                    MyDeal.tryDrawBack(MotionViewer, motionBlock);
                    Graphics graphicMotionBlock = Graphics.FromImage(motionBlock);
                    Brush    redPen             = new SolidBrush(Color.Red);

                    if (i == 0)
                    {                                                               //uncompress frame number
                        compressFile.baseImg.Add((Image)RefPlayer.Tiff[i].Clone()); // add ref imge
                        compressFile.motionTiff.Add(null);
                        continue;
                    }

                    Bitmap refBitmapCp; // the copy Bitmap for ref frame
                    Bitmap curBitmapCp; // the copy Bitmap for cur frame
                    while (true)
                    {
                        try
                        {
                            refBitmapCp = new Bitmap((Image)RefPlayer.PredictView.Clone());// the copy Bitmap for ref frame
                        }
                        catch (InvalidOperationException)
                        {
                            Thread.Sleep(33);
                            continue;
                        }
                        break;
                    }
                    while (true)
                    {
                        try
                        {
                            curBitmapCp = new Bitmap((Image)RefPlayer.NextView.Clone());// the copy Bitmap for cur frame
                        }
                        catch (InvalidOperationException)
                        {
                            Thread.Sleep(33);
                            continue;
                        }
                        break;
                    }
                    BitmapData refData = refBitmapCp.LockBits(MyDeal.boundB(refBitmapCp), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                    BitmapData curData = curBitmapCp.LockBits(MyDeal.boundB(curBitmapCp), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

                    for (int y = 0 + compressKernelSizeHalf; y < curBitmapCp.Height; y += compressKernelSize)
                    {
                        for (int x = 0 + compressKernelSizeHalf; x < curBitmapCp.Width; x += compressKernelSize)
                        {
                            if (activeFrom != null)
                            {
                                if (activeFrom.IsDisposed)//form be dispose
                                {
                                    return;
                                }
                            }
                            //draw target
                            if (!CurrentPlayer.flashIgnore)
                            {
                                CurPlayer.OnPlay(RefPlayer.NextView, new MyPlayer.PlayEventArgs(0, MyPlayer.PlayState.KEEP, x, y, compressKernelSize, compressKernelSize));
                            }
                            if (!RefPlayer.flashIgnore)
                            {
                                RefPlayer.OnPlay(new MyPlayer.PlayEventArgs(-1, MyPlayer.PlayState.KEEP, x, y, compressKernelSize, compressKernelSize));
                            }

                            CurKernelGet.fill(curData, x, y, MyFilter.BorderMethod.ZERO, CompressKernel);
                            RefKernelGet.fill(refData, x, y, MyFilter.BorderMethod.ZERO, CompressKernel);
                            switch (criteria)
                            {
                            case MyFilterData.CRITERIA_METHOD.ABSOLUTE:
                                if (_BBthreshold < MyFilterData.compare(CurKernelGet, RefKernelGet, criteria))
                                {
                                    graphicMotionBlock.DrawImage(CurKernelGet.transToBitmap(), x - compressKernelSizeHalf, y - compressKernelSizeHalf);
                                    //graphicMotionBlock.DrawImage(curBitmapCp, cutRect, x - compressKernelSizeHalf, y - compressKernelSizeHalf, compressKernelSize, compressKernelSize, GraphicsUnit.Pixel);
                                }
                                else
                                {
                                    graphicMotionBlock.FillRectangle(redPen, x - compressKernelSizeHalf, y - compressKernelSizeHalf, MyCompresser.compressKernelSize, MyCompresser.compressKernelSize);
                                }
                                break;

                            case MyFilterData.CRITERIA_METHOD.SQUARE:
                                if (_BBthresholdSQ < MyFilterData.compare(CurKernelGet, RefKernelGet, criteria))
                                {
                                    graphicMotionBlock.DrawImage(CurKernelGet.transToBitmap(), x - compressKernelSizeHalf, y - compressKernelSizeHalf);
                                    //graphicMotionBlock.DrawImage(curBitmapCp, cutRect, x - compressKernelSizeHalf, y - compressKernelSizeHalf, compressKernelSize, compressKernelSize, GraphicsUnit.Pixel);
                                }
                                else
                                {
                                    graphicMotionBlock.FillRectangle(redPen, x - compressKernelSizeHalf, y - compressKernelSizeHalf, MyCompresser.compressKernelSize, MyCompresser.compressKernelSize);
                                }
                                break;
                            }


                            if (!this.RefPlayer.flashIgnore)
                            {
                                MyDeal.tryDraw(MatchViewer, RefKernelGet.transToBitmap());
                            }
                            if (!this.CurrentPlayer.flashIgnore)
                            {
                                MyDeal.tryDraw(featureViewer, CurKernelGet.transToBitmap());
                                //draw motion
                                MotionViewer.Invalidate();
                            }
                            Thread.Sleep(sleepTime);
                            //Debug.Print("in frame " + i + " in " + x + " , "+ y + "find target " + targetX + " , " + targetY);
                        }
                    }

                    compressFile.baseImg.Add(motionBlock);// add ref imge
                    compressFile.motionTiff.Add(null);

                    refBitmapCp.UnlockBits(refData);
                    curBitmapCp.UnlockBits(curData);
                }

                if (activeFrom != null)
                {
                    activeFrom.Invoke(new threadHandler(saveFile));// save the result
                }
            }
        }