資源簡介
基于opencv的手勢識別,可以在一個窗口上顯示手勢和識別到底是哪個手勢。
用C語言實現的。

代碼片段和文件信息
#include?“cv.h“
#include?“highgui.h“
#include?
#include?
#define?WNDCOUNT?3
#define?sample_count?(frame_count<100?frame_count:100)
char*?wndname[7]?=?{?“源圖像“???“圖像1“
?????????????????????“圖像2“?“圖像3“
?????????????????????“圖像4“?“圖像5“
?????????????????????“圖像6“
???????????????????};
int?wndposition[7][2]?=?{?{10?0}??{335?0}?{660?0}
????{10?260}{335?260}{660?260}
????{1080?0}
}?;
float?hu[100000][7];
int?ii=0;
int?n;
float?hu11[10000][7];
void?getHandContour(CvSeq*?c?CvSeq**?hc)?????//提取手的輪廓函數????????
{
????while?(c?!=?NULL)
????{
????????CvRect?r?=?((CvContour*)c)->rect;
????????if?(r.height*r.width>10000)
????????{
????????????*hc?=?c;
????????}
????????c?=?c->h_next;
????}
}
//int?simplyConvexHull(CvSeq*?h?CvPoint?(*pts)[20])
int?simplyConvexHull(CvSeq*?h?CvPoint*?pts)
{
????int?ij;
????int?count?=?h->total;
????CvPoint**?pt0?=?(CvPoint**)(cvGetSeqElem(h?count-1));
????for?(i?=?0j?=?0;?i ????{
????????CvPoint**?pt?=?(CvPoint**)(cvGetSeqElem(h?i));
????????//printf(“x?=?%d?\n“?(*pt)->x);
????????//排除相鄰點
????????if?((abs((*pt)->x?-?(*pt0)->x)?+?abs((*pt)->y?-?(*pt0)->y))?>20)
????????{
????????????(pts+j)->x?=?(*pt)->x;
????????????(pts+j)->y?=?(*pt)->y;
????????????j++;
????????????pt0?=?pt;
????????}
????}
????return?j;
}
void?drawConvexHullArray(IplImage*?src?CvPoint*?pts?int?count)
{
????int?i;
????cvCircle(src?*(pts?+?count-1)?3?CV_RGB(02550)?CV_FILLED);
????cvLine(src?*pts?*(pts?+?count-1)CV_RGB(02550)?1?8?0);
????for?(i?=?0;?i????{
????????cvCircle(src?*(pts?+?i)?3?CV_RGB(02550)?CV_FILLED);
????????cvLine(src*(pts?+?i)*(pts?+?i?+?1)CV_RGB(02550)?1?8?0);
????}
}
int?getConvexityDefectArray(CvSeq*?h?CvPoint*?pts)????????//計算凹缺陷數
{
????int?ij;
????int?count?=?h->total;
????//printf(“缺陷數量?=?%d?\n“?count);
????for?(i?=?0?j?=?0;?i ????{
????????CvConvexityDefect*?cd?=?(CvConvexityDefect*)cvGetSeqElem(h?i);
????????if?((cd)?&&?(cd->depth>20))
????????{
????????????CvPoint*?pt?=?cd->depth_point;
????????????(pts+j)->x?=?pt->x;
????????????(pts+j)->y?=?pt->y;
????????????j++;
????????}
????}
????return?j;
}
//顯示矩陣數值
void?PrintMat(CvMat?*A)
{
????int?ij;
????//printf(“\nMatrix=:“);
????for(i=0;?irows;?i++)
????{
????????printf(“\n“);
????????switch(CV_MAT_DEPTH(A->type))
????????{
????????case?CV_32F:
????????case?CV_64F:
????????????for(j=0;?jcols;?j++)
????????????????printf(“%9.3f“(float)cvGetReal2D(Aij));
????????????break;
????????case?CV_8U:
????????case?CV_16U:
????????????for(j=0;?jcols;?j++)
????????????????printf(“%6d“(int)cvGetReal2D(Aij));
????????????break;
????????default:
????????????break;
????????}
????}
????printf(“\n“);
}
//計算樣本hu矩數據的k均值并存儲為xml文件作為樣本模型
//void?createtemplate(float?p_hu[100][6])
void?createtemplate(float?*p_hu?int?RowCount)
{
//????char*?da
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2010-12-31?15:36??11月7號晚上\
?????目錄???????????0??2010-12-31?15:36??11月7號晚上\.git\
?????文件??????????17??2010-10-18?11:57??11月7號晚上\.git\COMMIT_EDITMSG
?????文件?????????178??2010-10-18?11:59??11月7號晚上\.git\config
?????文件??????????73??2010-10-18?10:41??11月7號晚上\.git\desc
?????文件??????????46??2010-10-18?11:59??11月7號晚上\.git\GITGUI_MSG
?????文件??????????23??2010-10-18?10:41??11月7號晚上\.git\HEAD
?????目錄???????????0??2010-12-31?15:36??11月7號晚上\.git\hooks\
?????文件?????????452??2010-10-18?10:41??11月7號晚上\.git\hooks\applypatch-msg.sample
?????文件?????????894??2010-10-18?10:41??11月7號晚上\.git\hooks\commit-msg.sample
?????文件?????????160??2010-10-18?10:41??11月7號晚上\.git\hooks\post-commit.sample
?????文件?????????552??2010-10-18?10:41??11月7號晚上\.git\hooks\post-receive.sample
?????文件?????????189??2010-10-18?10:41??11月7號晚上\.git\hooks\post-update.sample
?????文件?????????398??2010-10-18?10:41??11月7號晚上\.git\hooks\pre-applypatch.sample
?????文件????????1567??2010-10-18?10:41??11月7號晚上\.git\hooks\pre-commit.sample
?????文件????????4942??2010-10-18?10:41??11月7號晚上\.git\hooks\pre-reba
?????文件????????1219??2010-10-18?10:41??11月7號晚上\.git\hooks\prepare-commit-msg.sample
?????文件????????3609??2010-10-18?10:41??11月7號晚上\.git\hooks\update.sample
?????文件??????????32??2010-10-18?11:57??11月7號晚上\.git\index
?????目錄???????????0??2010-12-31?15:36??11月7號晚上\.git\info\
?????文件?????????240??2010-10-18?10:41??11月7號晚上\.git\info\exclude
?????目錄???????????0??2010-12-31?15:36??11月7號晚上\.git\ob
?????目錄???????????0??2010-12-31?15:36??11月7號晚上\.git\ob
?????文件??????????15??2010-10-18?10:42??11月7號晚上\.git\ob
?????目錄???????????0??2010-12-31?15:36??11月7號晚上\.git\ob
?????文件?????????490??2010-10-18?10:44??11月7號晚上\.git\ob
?????目錄???????????0??2010-12-31?15:36??11月7號晚上\.git\ob
?????文件???????28070??2010-10-18?10:44??11月7號晚上\.git\ob
?????目錄???????????0??2010-12-31?15:36??11月7號晚上\.git\ob
?????目錄???????????0??2010-12-31?15:36??11月7號晚上\.git\ob
?????目錄???????????0??2010-12-31?15:36??11月7號晚上\.git\refs\
............此處省略28個文件信息
評論
共有 條評論