示例#1
0
    private static bool GetForegroundAlphaFrame(SensorData sensorData, ref byte[] fgAlphaFrame)
    {
        if (sensorData == null || sensorData.bodyIndexImage == null)
        {
            return(false);
        }

        CvMat cvAlphaMap = new CvMat(sensorData.depthImageHeight, sensorData.depthImageWidth, MatrixType.U8C1);

        System.IntPtr rawPtrAlpha;
        cvAlphaMap.GetRawData(out rawPtrAlpha);

        if (sensorData.selectedBodyIndex != 255)
        {
            // copy body-index selectively
            byte btSelBI          = sensorData.selectedBodyIndex;
            int  iBodyIndexLength = sensorData.bodyIndexImage.Length;

            for (int i = 0; i < iBodyIndexLength; i++)
            {
                byte btBufBI = sensorData.bodyIndexImage[i];

                if (btBufBI == btSelBI)
                {
                    cvAlphaMap.Set1D(i, btBufBI);
                }
                else
                {
                    cvAlphaMap.Set1D(i, 255);
                }
            }
        }
        else
        {
            // copy the entire body-index buffer
            Marshal.Copy(sensorData.bodyIndexImage, 0, rawPtrAlpha, sensorData.bodyIndexImage.Length);
        }

        // make the image b&w
        cvAlphaMap.Threshold(cvAlphaMap, 254, 255, ThresholdType.BinaryInv);

        // apply erode, dilate and blur
        cvAlphaMap.Erode(cvAlphaMap);
        cvAlphaMap.Dilate(cvAlphaMap);
        cvAlphaMap.Smooth(cvAlphaMap, SmoothType.Blur, 5, 5);
        //cvAlphaMap.Smooth(cvAlphaMap, SmoothType.Median, 7);

        // get the foreground image
        Marshal.Copy(rawPtrAlpha, fgAlphaFrame, 0, fgAlphaFrame.Length);

        return(true);
    }
    private static bool GetForegroundAlphaFrame(SensorData sensorData, ref byte[] fgAlphaFrame)
    {
        if (sensorData == null || sensorData.bodyIndexImage == null)
        {
            return(false);
        }

        CvMat cvAlphaMap = new CvMat(sensorData.depthImageHeight, sensorData.depthImageWidth, MatrixType.U8C1);

        System.IntPtr rawPtrAlpha;
        cvAlphaMap.GetRawData(out rawPtrAlpha);

        Marshal.Copy(sensorData.bodyIndexImage, 0, rawPtrAlpha, sensorData.bodyIndexImage.Length);
        cvAlphaMap.Threshold(cvAlphaMap, 254, 255, ThresholdType.BinaryInv);

        //cvAlphaMap.Erode(cvAlphaMap);
        cvAlphaMap.Smooth(cvAlphaMap, SmoothType.Blur, 10, 10);
        cvAlphaMap.Smooth(cvAlphaMap, SmoothType.Median, 7);
        //cvAlphaMap.Smooth(cvAlphaMap, SmoothType.Blur, 5, 5);

        Marshal.Copy(rawPtrAlpha, fgAlphaFrame, 0, fgAlphaFrame.Length);

        return(true);
    }
示例#3
0
        private static bool GetForegroundAlphaFrame(SensorData sensorData, bool bLimitedUsers, ICollection<int> alTrackedIndexes, ref byte[] fgAlphaFrame)
        {
            if (sensorData == null || sensorData.bodyIndexImage == null)
                return false;

            CvMat cvAlphaMap = new CvMat(sensorData.depthImageHeight, sensorData.depthImageWidth, MatrixType.U8C1);

            System.IntPtr rawPtrAlpha;
            cvAlphaMap.GetRawData(out rawPtrAlpha);

            if (sensorData.selectedBodyIndex != 255 || bLimitedUsers)
            {
                // copy body-index selectively
                byte btSelBI = sensorData.selectedBodyIndex;
                int iBodyIndexLength = sensorData.bodyIndexImage.Length;

                for (int i = 0; i < iBodyIndexLength; i++)
                {
                    byte btBufBI = sensorData.bodyIndexImage[i];

                    bool bUserTracked = btSelBI != 255 ? btSelBI == btBufBI :
                        (btBufBI != 255 ? alTrackedIndexes.Contains((int)btBufBI) : false);

                    if (bUserTracked)
                    {
                        cvAlphaMap.Set1D(i, btBufBI);
                    }
                    else
                    {
                        cvAlphaMap.Set1D(i, 255);
                    }
                }
            }
            else
            {
                // copy the entire body-index buffer
                Marshal.Copy(sensorData.bodyIndexImage, 0, rawPtrAlpha, sensorData.bodyIndexImage.Length);
            }

            // make the image b&w
            cvAlphaMap.Threshold(cvAlphaMap, 254, 255, ThresholdType.BinaryInv);

            // apply erode, dilate and blur
            cvAlphaMap.Erode(cvAlphaMap);
            cvAlphaMap.Dilate(cvAlphaMap);
            cvAlphaMap.Smooth(cvAlphaMap, SmoothType.Blur, 5, 5);
            //cvAlphaMap.Smooth(cvAlphaMap, SmoothType.Median, 7);

            // get the foreground image
            Marshal.Copy(rawPtrAlpha, fgAlphaFrame, 0, fgAlphaFrame.Length);

            return true;
        }
示例#4
0
    private static bool GetForegroundAlphaFrame(SensorData sensorData, ref byte[] fgAlphaFrame)
    {
        if(sensorData == null || sensorData.bodyIndexImage == null)
            return false;

        CvMat cvAlphaMap = new CvMat(sensorData.depthImageHeight, sensorData.depthImageWidth, MatrixType.U8C1);

        System.IntPtr rawPtrAlpha;
        cvAlphaMap.GetRawData(out rawPtrAlpha);

        Marshal.Copy(sensorData.bodyIndexImage, 0, rawPtrAlpha, sensorData.bodyIndexImage.Length);
        cvAlphaMap.Threshold(cvAlphaMap, 254, 255, ThresholdType.BinaryInv);

        cvAlphaMap.Erode(cvAlphaMap);
        cvAlphaMap.Dilate(cvAlphaMap);
        cvAlphaMap.Smooth(cvAlphaMap, SmoothType.Blur, 5, 5);
        //cvAlphaMap.Smooth(cvAlphaMap, SmoothType.Median, 7);

        Marshal.Copy(rawPtrAlpha, fgAlphaFrame, 0, fgAlphaFrame.Length);

        return true;
    }
        /** 所属国認識2
         * @param image 所属国アイコン部分カラー画像
        */
        static 所属国 recognizeNationality2( CvMat image )
        {
            // 閾値130.0で2値化した画像を基にする
            CvMat bin = new CvMat( image.Rows, image.Cols, MatrixType.U8C1);
            image.CvtColor( bin, ColorConversion.BgrToGray );
            bin.Threshold( bin, 130.0, 255.0, ThresholdType.Binary );

            // iel: 7
            // net: 23
            // http://twitpic.com/azbzjh
            int count = bin.GetRows( 2, bin.Rows ).CountNonZero();
            if ( count > 15 )
                return 所属国.ネツァワル;

            if ( count > 3 )
                return 所属国.エルソード;

            return 所属国.不明;
        }
示例#6
0
        // スコア表画像を2値化
        static CvMat scoreTable2Binary(CvMat scoreTable)
        {
            CvMat bin = new CvMat( scoreTable.Rows, scoreTable.Cols, MatrixType.U8C1);
            // グレイスケール化
            scoreTable.CvtColor( bin, ColorConversion.BgrToGray );
            // 2値化
            bin.Threshold ( bin, 150.0, 255.0, ThresholdType.Binary );
            // 孤立輝点除去
            bin = removeNoize ( bin );

            return bin;
        }