public void Copy(HandRegion region)
 {
     this.rect = region.rect;
        this.innerRect = region.innerRect;
        this.colorEnergy = region.colorEnergy;
        this.motionEnergy = region.motionEnergy;
 }
示例#2
0
        private int addNewHandRegion(HandRegion newRegion, List<HandRegion> regionList)
        {
            if( newRegion.GetEnergy() < 0 )
                return -1;
            if (regionList.Count < 1)
            {
                regionList.Add(newRegion);
                return -1;
            }

            if (regionList.Count >= 3 && newRegion.GetEnergy() < regionList[0].GetEnergy())
                return -1;
            for(int i = 0; i < regionList.Count; ++i)
            {
                if(newRegion.rect.IntersectsWith(regionList[i].rect))
                {
                    Rectangle intersectRec = Rectangle.Intersect(newRegion.rect, regionList[i].rect);
                    int AreaInter = intersectRec.Width * intersectRec.Height;
                    int AreaNew = newRegion.rect.Width * newRegion.rect.Height;
                    int AreaList = regionList[i].rect.Width * regionList[i].rect.Height;
                    if(AreaInter > 0.5 * AreaNew || AreaInter > 0.5 * AreaList)
                    {
                        if (newRegion.GetEnergy() > regionList[i].GetEnergy())
                            return i;
                        else
                            return -1;
                    }

                }
            }
            if(regionList.Count < 3)
            {
                regionList.Add(newRegion);
                return -1;
            }

            return 0;
        }
示例#3
0
        private List<HandRegion> getHandRect(Image<Gray,double> colProb, Image<Gray,double> motionProb)
        {
            List<HandRegion> handRegions = new List<HandRegion>();
            for (int i = 0; i < 3; ++i)
            {
                HandRegion region = new HandRegion(new Rectangle(0, 0, 0, 0), new Rectangle(0, 0, 0, 0), 0, 0);
                handRegions.Add(region);
            }

            double colorRatio = 1 / 2.0;
            double motionRatio = 1 / 2.0;
            int largestSize = regionSize[0] / 4;
            HandRegion biggest = null;
            double sum = 0;
            for (int row = largestSize; row < colProb.Height - largestSize; ++row)
                for (int col = largestSize; col < colProb.Width - largestSize; ++col)
                {
                    for (int i = 0; i < regionSize.Length; ++i)
                    {
                        int size = regionSize[i];
                        int innerColorSize = (int)(size * colorRatio);
                        int innerMotionSize = (int)(size * motionRatio);
                        Rectangle innerColorRect = new Rectangle(col - innerColorSize / 2, row - innerColorSize / 2, innerColorSize, innerColorSize);
                        Rectangle innerMotionRect = new Rectangle(col - innerMotionSize / 2, row - innerMotionSize / 2, innerMotionSize, innerMotionSize);
                        double innerColorSum = getSum(colProb, innerColorRect);
                        double innerMotionSum = getSum(motionProb, innerMotionRect);

                        Rectangle rect = new Rectangle(col - size / 2, row - size / 2, size, size);
                        double outColorSum = getSum(colProb, rect);
                        double outMotionSum = getSum(motionProb, rect);
                        double colorEnergy = 2 * innerColorSum - outColorSum;
                        double motionEnergy = 2 * innerMotionSum - outMotionSum;

                        if(colorEnergy + motionEnergy > handRegions[0].GetEnergy())
                        {
                            handRegions[0].Copy(new HandRegion(rect, innerColorRect, colorEnergy, motionEnergy));
                            handRegions.Sort();
                        }

                        //test
                       // if(colorEnergy > 0 && motionEnergy > 0)
                        //{
                        //    double energy = colorEnergy + motionEnergy;

                        //    HandRegion newRegion = new HandRegion(rect, innerColorRect, 2 * innerColorSum - outColorSum, 2 * innerMotionSum - outMotionSum);
                        //    int index = this.addNewHandRegion2(newRegion, handRegions);
                        //    if (index != -1)
                        //        handRegions[index].Copy(newRegion);
                        //    handRegions.Sort();
                        //}
                        //end of test

                    }
                }
            return handRegions;
        }