user3867449
user3867449

Reputation: 21

Kinect V2 how to extract player/user from background with original resolution 1920x1080

In Kinect V2 as we know depth and color resolutions are different. With mapping API available in SDK it is easy to get color value from color frame and put in on depth frame as shown by many posts on the internet. That will give final image of the size 512x414.

But I wanted to extract player/user in original color frame so that final image is of resolution 1920x1080.

I can think of using the mapping API and mark color frame with User/PLayer pixel. Then apply some heuristic and expose RGB value neighboring pixels and complete the User/Player image.

Does any one has better suggestion on how best we can do that ?

Upvotes: 2

Views: 444

Answers (1)

cryax dsa
cryax dsa

Reputation: 13

Hi instead of mapping from depth to color try mapping your color frame to depthspace and set your output Image's size equal color Image's size.

coordinateMapper.MapColorFrameToDepthSpace(depthData, depthPoints);

for (int colorIndex = 0; colorIndex < depthPoints.Length; ++colorIndex)
            {
                DepthSpacePoint depthPoint = depthPoints[colorIndex];

                if (!float.IsNegativeInfinity(depthPoint.X) && !float.IsNegativeInfinity(depthPoint.Y))
                {
                    int depthX = (int)(depthPoint.X + 0.5f);
                    int depthY = (int)(depthPoint.Y + 0.5f);

                    if ((depthX >= 0) && (depthX < depthWidth) && (depthY >= 0) && (depthY < depthHeight))
                    {
                        int depthIndex = (depthY * depthWidth) + depthX;
                        byte player = bodyData[depthIndex];
                        if (player != 0xff)
                        {
                            int sourceIndex = colorIndex * 4;

                            OutImage[sourceIndex] = _colorData[sourceIndex++];    
                            OutImage[sourceIndex] = _colorData[sourceIndex++];    
                            OutImage[sourceIndex] = _colorData[sourceIndex++];    
                            OutImage[sourceIndex] = 0xff;                         
                        }
                    }
                }
            }

Init for output Image:

 OutImage= new byte[colorWidth*colorHeight*4]; //1920x1080x4

Upvotes: 1

Related Questions