c++ - 在 Kinec 图片 C++ 中检测手和物体的接触

标签 c++ kinect

首先:我在通过 MS Visual Studio 对 Kinec 进行编程方面还很陌生……如果我的问题有点愚蠢,我深表歉意。

我想检测我的手是否接触到象限的上部;为此我编程:

Image<Gray, Byte> HandImage = GetThresholdedImage(ref bgrImage, (int)hueHand);
Image<Gray, Byte> depthImageBin = depthImage.ThresholdBinary(new Gray(30), new Gray(255));

List<MCvBox2D> DangerAreas = new List<MCvBox2D>();
List<MCvBox2D> HandAreas = new List<MCvBox2D>();

// build list of object rectangles
DangerAreas = ProcessObjectContours(bgrImage, contoursDepthObjects, contoursHand, objectSize);
// build list of hand rectangles
HandAreas = ProcessHandContours(bgrImage, contoursHand, contoursDepthObjects, handSize);      

objectSizehandSize 定义对象的最小限制。

到目前为止一切正常,我在显示屏上看到了形状。如果两个结构匹配,则它们合并。

但我希望软件在我的手 (HandAreas) 触摸指定区域的对象 (DangerAreas) 时发出通知。

我尝试用 MatchShapes 解决问题:

contoursDepthObjects.MatchShapes(contoursDepthObjects[0], contoursHand[0], Emgu.CV.CvEnum.MATCH_CONTOUR_TREE_METHOD.CONTOUR_TREES_MATCH_I1, 2);

但由于错误,这种形式的 MatchShapes 不被接受。所以有两个问题:这是检测我的手何时接触危险区域的正确方法吗?如果是,如何正确处理方法 MatchShapes

最佳答案

我这样做的方法是研究碰撞检测算法。 您可以很容易地获取手的位置并将其转换为相对于矩形所在容器的二维点,然后获取危险区域矩形的二维点。然后只需确定手点是否在矩形点的顶部(或半径范围内)即可。

要获取骨架相对于网格的位置,所有元素都位于:

private static Point GetPosition2DLocation(SkeletonPoint position, Grid skeletonCanvas, DepthImageFrame depthFrame)
        {
            DepthImagePoint depthPoint = depthFrame.MapFromSkeletonPoint(position);
            return new Point(
                (int)(skeletonCanvas.ActualWidth * depthPoint.X / depthFrame.Width),
                (int)(skeletonCanvas.ActualHeight * depthPoint.Y / depthFrame.Height)
            );
        }

检查两点是否相交(半径 70 以内):

private static bool PointsIntersecting(Point item1, Point item2)
        {
            //Give the center a radius so that collision does not have to be exact.
            //TODO configurable
            const int radius = 70;

            //compare the distance to combined radii
            double dx = item2.X - item1.X;
            double dy = item2.Y - item1.Y;
            const int radii = radius + radius;
            if ((dx * dx) + (dy * dy) < radii * radii)
            {
                return true;
            }
            return false;
        }

希望这是有道理的。

关于c++ - 在 Kinec 图片 C++ 中检测手和物体的接触,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9761442/

相关文章:

c++ - 将 size_t 转换为 vector<unsigned char>

c# - Kinect V2 红外面部点跟踪未显示正确的坐标位置

c++ - 从 MSVC2015 更新 2 移植到 GCC 5.3 - SFINAE 错误

c++ - OpenCV:findContours 函数错误

c++ - 删除句点和空格的函数

c# - 使用 Kinect 调整 body 关节角度

kinect - 让 children 编程 Microsoft Kinect 的可行性如何?

wpf - Kinect SDK 1.6 和 Joint.ScaleTo 方法

c# - 使用OpenNI和Kinect获取云点

c++ - c++ 中的 "new"运算符,指针问题