使用opencv Kinect進行手勢控制滑鼠

2021-09-17 20:43:19 字數 3836 閱讀 1010

使用opencv+kinect進行手勢控制滑鼠

參考csdn的前輩文章,使用kinect相機進行手勢識別,手指最長的進行識別,同時控制滑鼠移動。強烈推薦

模擬方形框等比對應電腦螢幕。然後移動控制。但是我現在找不到是從**的了,所以寫一下,算乙個備份。

這個**是

#include

#include

#include

#pragma comment ( lib, 「kinect20.lib」 )

#include

#include

#include

#include

#include

#include

#include

#include

using namespace std;

using namespace cv;

bool depth_rage_check(int, int, int, int);

bool level_check(const cameraspacepoint &, const cameraspacepoint &);

bool distance_check(const cameraspacepoint &, const cameraspacepoint &);

bool check_new_point(depthspacepoint &, depthspacepoint &, int, int);

void draw_line(mat &, const depthspacepoint &, depthspacepoint &);

void draw_body(mat &, byte *, int, int);

void draw_hand(mat &, const depthspacepoint &);

void draw_circle(mat &, int, int);

int main(void)

; //用來記錄上一次滑鼠的位置

depthspacepoint depthupleft = ; //操作視窗的左上角和右下角,要注意這兩個x和x、y和y的差會作為除數,所以不能都為0

depthspacepoint depthdownright = ;

bool gotedge = false;//端にまではfalseです

while (1)//while(1)代表了迴圈永遠執行下去.除非遇到break;才跳出迴圈.原因是while的迴圈裡面是乙個布林值,而1代表了true,所以是乙個無限迴圈.

; cameraspacepoint cameradownright = ;//這兩行是確定框框的上下左右吧

gotedge = true;

}//指尖識別,記錄最長的那根手指的指尖,

depthspacepoint highestpoint = ;

if (jointarray[jointtype_handright].trackingstate == trackingstate_tracked)

;if (bodyindexbuffer[index] > 5 || (bodyindexbuffer[index] <= 5 && !level_check(camerahandright, cameratemp))) //看此畫素是否不屬於人體(指尖上方一點),或者屬於人體但是和手不在同一平面(胸)

}if (flag && i < highestpoint.y)}}

}int windowwidth = (int)depthdownright.x - (int)depthupleft.x; //計算操作視窗的尺寸

int windowheight = (int)depthdownright.y - (int)depthupleft.y;

draw_line(img, depthupleft, depthdownright);

if (check_new_point(front, highestpoint, depthheight, depthwidth))

else //如果和上一幀相比移動的幅度小於閾值,則保持上一幀的狀態

}} imshow("test", img);

if (waitkey(30) == vk_escape)

break;

mydepthframe->release();

mybodyindexframe->release();

mybodyframe->release();

delete bodyarray;

}mybodysource->release();

mybodyindexsource->release();

mydepthsource->release();

mybodyreader->release();

mybodyindexreader->release();

mydepthreader->release();

mydescription->release();

mysensor->close();

mysensor->release();

return 0;void draw_body(mat & img, byte * buffer, int height, int width)//定義函式

}void draw_circle(mat & img, int x, int y)//void代表的是函式定義,mat類是opencv表達二維的基礎

;circle(img, center, 5, color_table[green], -1, 0, 0);

}void draw_hand(mat & img, const depthspacepoint & hand)

;circle(img, center, 5, color_table[blue], -1, 0, 0);

}void draw_line(mat & img, const depthspacepoint & upleft, depthspacepoint & downright)

;circle(img, a, 5, color_table[red], -1, 0, 0);

point b = ;

circle(img, b, 5, color_table[green], -1, 0, 0);

point c = ;

circle(img, c, 5, color_table[blue], -1, 0, 0);

point d = ;

circle(img, d, 5, color_table[white], -1, 0, 0);

line(img, a, b, color_table[red], 1, 8, 0);

line(img, b, c, color_table[red], 1, 8, 0);

line(img, c, d, color_table[red], 1, 8, 0);

line(img, a, d, color_table[red], 1, 8, 0);

}bool level_check(const cameraspacepoint & hand, const cameraspacepoint & temp)

bool distance_check(const cameraspacepoint & hand, const cameraspacepoint & temp)

bool depth_rage_check(int x, int y, int depthwidth, int depthheight)

bool check_new_point(depthspacepoint & front, depthspacepoint & now, int height, int width)

WPF使用IDataErrorInfo進行資料校驗

原文 wpf使用idataerrorinfo進行資料校驗 這篇部落格將介紹如何使用idataerrorinfo進行資料校驗。下面直接看例子。乙個customer類,兩個屬性 firstname,age class customer public intage 將customer類繼承idataerr...

WPF使用IDataErrorInfo進行資料校驗

原文 wpf使用idataerrorinfo進行資料校驗 這篇部落格將介紹如何使用idataerrorinfo進行資料校驗。下面直接看例子。乙個customer類,兩個屬性 firstname,age class customer public intage 將customer類繼承idataerr...

mybatis使用associaton進行分步查詢

employee類 public class employeedepartment類 public class departmentselect from tbl employee where id select id,dept name departmentname from tbl dept w...