简体   繁体   English

使用 RotatedRect 跟踪手部旋转

[英]Tracking hand rotation with RotatedRect

I'm using OpenCV for a project to detect hand gestures, I managed to isolate the hand and drawing the convexes the hand is appearing very clearly now.我在一个项目中使用 OpenCV 来检测手势,我设法隔离了手并绘制了手现在非常清晰地出现的凸面。 My goal is to detect if the hand is rotating or moving left or right.我的目标是检测手是否在旋转或向左或向右移动。

I used RotatedRect to figure out if the hand is rotated or not, but it seems like the RotatedRect is always tilted left or right (mostly left) even if my hand is straight.我使用 RotatedRect 来确定手是否旋转,但似乎 RotatedRect 总是向左或向右(主要是向左)倾斜,即使我的手是直的。 How can I possibly fix that?我怎么可能解决这个问题?

手的形象

Here's my code for creating and drawing the RotatedRect:这是我创建和绘制 RotatedRect 的代码:

double angle;
            RotatedRect rc = minAreaRect(biggestcontours[hand]);
            if (rc.size.width < rc.size.height) {
                angle = 90 - rc.angle;
            }
            else {
                angle = -rc.angle;
            }
        Point2f rect_points[4];
            rc.points(rect_points);
            for (int j = 0; j < 4; j++)
            {
                line(onehand, rect_points[j], rect_points[(j + 1) % 4], Scalar(255, 0, 0));
            }

Remark :biggestcontours[hand] contains the contour of my hand.备注:biggestcontours[hand] 包含我手的轮廓。

Here is an approach using PCA这是一种使用 PCA 的方法

You can find the code here 你可以在这里找到代码

Result:结果:

在此处输入图片说明

Note: if the hand shape doesn't change and you have a reference angle, you'll be able to get it's rotation angle accurately.注意:如果手形没有变化并且您有一个参考角度,您将能够准确地获得它的旋转角度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM