kinect學習筆記(四) 各種資料流

2021-09-07 21:39:13 字數 4310 閱讀 6042

一、kinect開發的乙個流程圖

1、我們可以知道乙個簡單的框架就是幾部分

(1)選擇使用的kinect感測器

kinectsensor.kinectsensors[0]
(2)開啟需要的資料流

_kinect.depthstream.enable();

_kinect.colorstream.enable();

_kinect.skeletonstream.enable();

(3)註冊事件

其實就是主要的演算法在這裡體現。

有個小竅門:vs的codesnippet快速生成事件**,如在**「_kinect.depthframeready+=」後面連續按兩次「tab」鍵,就會生成相應的時間並處理相應的**。

二、初始化、啟用kinect裝置

**如下,記得要宣告乙個私有成員變數_kinect,並在mainwindow()裡面呼叫。

kinectsensor _kinect;

private

void

startkinect()

else

}

void _kinect_allframesready(object sender, allframesreadyeventargs e)

三、彩色影象流資料處理

1、在mainwindows窗體上新增乙個image控制項,命名為imagecamera

2、在_kinect_allframesready事件處理中增加如下**、

//

顯示彩色攝像頭

using(colorimageframe colorframe =e.opencolorimageframe())

byte pixels = new

byte

[colorframe.pixeldatalength];

colorframe.copypixeldatato(pixels);

//bgr32格式乙個畫素為4個位元組

int stride = colorframe.width * 4

; imagecamera.source = bitmapsource.create(colorframe.width, colorframe.height, 96, 96, pixelformats.bgr32, null

, pixels, stride);

}

bgr32影象的1畫素對應4位元組(32位),分別是b,g,r,阿爾法通道(透明度)。

bitmapsource.create是乙個從陣列到二維矩陣的過程。

stride為步長,代表一行畫素所佔的位元組數,為攝像頭傳輸的寬度乘以4,

dpi,越高越清晰,普通的顯示器就是96差不多。

3、效果圖

四、深度資料捕獲

1、定義深度影象的有效視角範圍。

const

float maxdepthdistance = 4095

;

const

float mindepthdistance = 850

;

const

float maxdepthdistanceoffest = maxdepthdistance -mindepthdistance;

private

const

int redindex = 2

;

private

const

int greenindex = 1

;

private

const

int blueindex = 0;

2、**

private

byte

convertdepthframetocolorframe(depthimageframe depthframe)

else

if(depth>900&&depth<2000

)

else

if(depth>2000

)

byte intensity =calculateintensityfromdepth(depth);

piexls[colorindex + blueindex] =intensity;

piexls[colorindex + greenindex] =intensity;

piexls[colorindex + redindex] =intensity;

if(player>0

)

}return

piexls;

}void _kinect_allframesready(object

sender, allframesreadyeventargs e)

byte pixels = new

byte

[colorframe.pixeldatalength];

colorframe.copypixeldatato(pixels);

//bgr32格式乙個畫素為4個位元組

int stride = colorframe.width * 4

; imagecamera.source = bitmapsource.create(colorframe.width, colorframe.height, 96, 96, pixelformats.bgr32, null

, pixels, stride);

}using(depthimageframe depthframe =e.opendepthimageframe())

byte piexls =convertdepthframetocolorframe(depthframe);

int stride = depthframe.width * 4

; imagedepth.source = bitmapsource.create(depthframe.width, depthframe.height, 96, 96, pixelformats.bgr32, null

, piexls, stride);

}

3、效果圖

五、骨骼追蹤

1、首先注釋掉我們之前註冊的時間,重新註冊乙個彩色資料流時間和乙個骨骼事件,然後新增如下**

private

skeleton skeletons;

void _kinect_skeletonframeready(object

sender, skeletonframereadyeventargs e)

}if(isskeletondataeeady==true

) }}

void

lockheadwithspot(skeleton s)

void _kinect_colorframeready(object

sender, colorimageframereadyeventargs e)

byte pixels = new

byte

[colorframe.pixeldatalength];

colorframe.copypixeldatato(pixels);

//bgr32格式乙個畫素為4個位元組

int stride = colorframe.width * 4

; imagecamera.source = bitmapsource.create(colorframe.width, colorframe.height, 96, 96, pixelformats.bgr32, null

, pixels, stride);}}

2、效果圖

六關閉kinect裝置

private

void

stopkinect()}}

寒假筆記 各種數

卡特蘭數又稱卡塔蘭數,英文名catalan number,是組合數學中乙個常出現在各種計數問題 現的數列。以比利時的數學家歐仁 查理 卡塔蘭 1814 1894 的名字來命名,其前幾項為 從第零項開始 1,1,2,5,14,42,132,429,1430,4862,16796,58786,20801...

kinect 學習筆記一

顏色深度影象的顯示 初始化 繫結流 提取流。1 提取顏色資料 include include windows.h include msr nuiapi.h include cv.h include highgui.h using namespace std int main int argc,cha...

kinect 學習筆記一

kinect 學習筆記一 顏色深度影象的顯示 初始化 繫結流 提取流。1 提取顏色資料 include include windows.h include msr nuiapi.h include cv.h include highgui.h using namespace std int main...