资源简介
手势指尖检测算法c++实现,使用肤色分割算法将手势从复杂背景中分离出来,通过检测手指指尖进行手指识别。
代码片段和文件信息
#include
#include
#include
#include
int minH = 0 maxH = 20 minS = 30 maxS = 150 minV = 60 maxV = 255;
cv::Mat frame;
int count = 0;
float innerAngle(float px1 float py1 float px2 float py2 float cx1 float cy1)
{
float dist1 = std::sqrt( (px1-cx1)*(px1-cx1) + (py1-cy1)*(py1-cy1) );
float dist2 = std::sqrt( (px2-cx1)*(px2-cx1) + (py2-cy1)*(py2-cy1) );
float Ax Ay;
float Bx By;
float Cx Cy;
//find closest point to C
//printf(“dist = %lf %lf\n“ dist1 dist2);
Cx = cx1;
Cy = cy1;
if(dist1 < dist2)
{
Bx = px1;
By = py1;
Ax = px2;
Ay = py2;
}else{
Bx = px2;
By = py2;
Ax = px1;
Ay = py1;
}
float Q1 = Cx - Ax;
float Q2 = Cy - Ay;
float P1 = Bx - Ax;
float P2 = By - Ay;
float A = std::acos( (P1*Q1 + P2*Q2) / ( std::sqrt(P1*P1+P2*P2) * std::sqrt(Q1*Q1+Q2*Q2) ) );
A = A*180/CV_PI;
return A;
}
void CallbackFunc(int event int x int y int flags void* userdata)
{
cv::Mat RGB = frame(cv::Rect(x y 1 1));
cv::Mat HSV;
cv::cvtColor(RGB HSV CV_BGR2HSV);
cv::Vec3b pixel = HSV.at(0 0);
if (event == cv::EVENT_LBUTTONDBLCLK) // on double left clcik
{
std::cout << “Click“ << std::endl;
int h = pixel.val[0];
int s = pixel.val[1];
int v = pixel.val[2];
if (count == 0)
{
minH = h;
maxH = h;
minS = s;
maxS = s;
minV = v;
maxV = v;
}
else
{
if (h < minH)
{
minH = h;
}
else if (h > maxH)
{
maxH = h;
}
if (s < minS)
{
minS = s;
}
else if (s > maxS)
{
maxS = s;
}
if (v < minV)
{
minV = v;
}
else if (v > maxV)
{
maxV = v;
}
}
count++;
}
std::cout << pixel << std::endl;
}
int main()
{
cv::VideoCapture cap(0);
const char* windowName = “Fingertip detection“;
cv::namedWindow(windowName);
cv::setMouseCallback(windowName CallbackFunc NULL);
int inAngleMin = 200 inAngleMax = 300 angleMin = 180 angleMax = 359 lengthMin = 10 lengthMax = 80;
cv::createTrackbar(“Inner angle min“ windowName &inAngleMin 360);
cv::createTrackbar(“Inner angle max“ windowName &inAngleMax 360);
cv::createTrackbar(“Angle min“ windowName &angleMin 360);
cv::createTrackbar(“Angle max“ windowName &angleMax 360);
cv::createTrackbar(“Length min“ windowName &lengthMin 100);
cv::createTrackbar(“Length max“ windowName &lengthMax 100);
while (1)
{
cap >> frame;
cv::Mat hsv;
cv::cvtColor(frame hsv CV_BGR2HSV);
cv::inRange(hsv cv::Scalar(minH minS minV) cv::Scalar(maxH maxS maxV) hsv);
// Pre processing
int blurSize = 5;
int elementSize = 5;
cv::medianBlur(hsv hsv blurSize);
cv::Mat element = cv::getStructuringElement(cv::MORPH_ELLIPSE cv::Size(2 * elementSize + 1 2 * elementSize + 1) cv::Point(elementSize elementSize
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 155656 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code.htm
文件 999 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\css
文件 241 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\css(1)
文件 252 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\css(2)
文件 217705 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\fingertip1.png
文件 175774 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\fingertip10.png
文件 11147 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\fingertip2.png
文件 25362 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\fingertip3.png
文件 4315 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\fingertip4.png
文件 1016899 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\fingertip5.png
文件 339959 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\fingertip6.png
文件 225033 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\fingertip7.png
文件 202695 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\fingertip8.png
文件 1113 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\github.js
文件 36312 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\handangle.png
文件 92629 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\jquery.min.js
文件 2475 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\jXHR.js
文件 7020 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\modernizr-2.0.js
文件 8357 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\octopress.js
文件 19195 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\screen.css
文件 269 2016-08-08 16:24 手势指尖检测\Fingertip Detection in OpenCV - Tango with code_files\spoiler.js
文件 43581440 2016-11-21 15:05 手势指尖检测\ipch\opennixtionrgbd-1b81a9a\opennixtionrgbd-5e1143c6.ipch
文件 1181 2013-04-29 15:48 手势指尖检测\OpenNIXtionRGBD\intrinsics.yml
文件 5383 2016-08-08 16:21 手势指尖检测\OpenNIXtionRGBD\OpenNIXtionRGBD.cpp
文件 4494 2016-08-04 17:22 手势指尖检测\OpenNIXtionRGBD\OpenNIXtionRGBD.vcxproj
文件 964 2014-06-25 16:38 手势指尖检测\OpenNIXtionRGBD\OpenNIXtionRGBD.vcxproj.filters
文件 299 2016-08-04 15:23 手势指尖检测\OpenNIXtionRGBD\OpenNIXtionRGBD.vcxproj.user
文件 8406 2016-08-04 15:28 手势指尖检测\OpenNIXtionRGBD\results.log
文件 912 2014-06-25 16:36 手势指尖检测\OpenNIXtionRGBD.sln
..A..H. 32256 2016-11-21 15:05 手势指尖检测\OpenNIXtionRGBD.suo
............此处省略8个文件信息
评论
共有 条评论