OpenNI 讀取兩個kinect的資料

2021-06-12 11:51:46 字數 2746 閱讀 2548

void check(xnstatus result, string step)

for(int i=0;iimagedata,imagemd.data(),640*480*3);

cvcvtcolor(image,imageshow,cv_rgb2bgr);

cvshowimage(imagewindow[i].data(),imageshow);

} if(cvwaitkey(10) == 27) break;

} cvreleaseimage(&depth);

cvreleaseimage(&image);

cvreleaseimage(&depthshow);

cvreleaseimage(&imageshow);

cvdestroyallwindows();

context.stopgeneratingall();

context.shutdown();

return 0;

} 通過列舉所有的depth node和image node來對每乙個camera建立乙個generator,然後就是傳統的生成meta data轉化成image然後輸出了。沒想到openni還自帶了乙個iterator來幫助迴圈,想的挺周到的,可惜剛接觸還沒用習慣。下面進行幾點說明:

1. 程式的devices enumaration部分是用來列舉所有裝置並輸出相關資訊的,寫具體的應用程式時可以省略。

2. 程式的depth nodes enumaration部分列舉所有能用的depth相機,對每乙個相機在context中新增乙個depthgenerator,並設定output mode。程式建立了乙個vector容 器, 所有的depthgenerator放入其中,以供後面生成資料使用。

3. 程式的image nodes enumatation部分同上。

4. 程式的name window部分建立顯示影象的視窗,可以省略。在省略的情況下,顯示影象時傳乙個字串形式的window name給cvshowimage,opencv會自動建立乙個窗  口,最後用cvdestroyallwindows()來一次性關閉所有視窗。

5. 在兩個kinect的情況下,每乙個kinect所產生的depth影象和rgb影象因視點不一樣而不能匹配,這時需要改變乙個影象的視點。openni只允許將depth影象的視點轉變到rgb圖 像上。我想當然的認為depthgenerator和imagegenerator會按角標一一對應,故而試圖用迴圈來改變depth影象的視點到rgb影象上,沒想到在我的電腦上depthgenerator[0]  對應的是imagegenerator[1],而depthgenerator[1]對應的卻是imagegenerator[0]。奇之怪也!似乎系統在找depth node的時候是隨機找的。於是乎只能用列舉的方法改正 視點了。如果有多個kinect,可以在depth nodes enumaration部分增加乙個query,從而找到depth與image之間的對應。(偶沒試過,後面有時間的話試一下)。

6. 這一部分就是標準的讀取資料然後輸出了。

注:連多個kinect時,必須確保每乙個kinect都連在不同的usb中心,也就是說,不能將多個kinect連在同乙個usb集線器中。

附:名古屋工業大學高手**:

#include using namespace cv;

#define check_rc(rc, what) \

if (rc != xn_status_ok) \

using namespace xn;

//multi kinect test

#define num_kinect 2

int main()

for (xn::nodeinfolist::iterator nodeit = device_node_info_list.begin

(); nodeit != device_node_info_list.end (); ++nodeit)

printf("image nodes:\n");

imagegenerator im_multi[num_kinect];

imagemetadata immd;

xn::nodeinfolist image_node_info_list;

vectormimagenodes;

nretval = context.enumerateproductiontrees(xn_node_type_image, null,

image_node_info_list, null);

for (xn::nodeinfolist::iterator nodeit =

image_node_info_list.begin(); nodeit != image_node_info_list.end(); ++nodeit)

for(int i=0;imdepthnodes;

// enumerate depth nodes:

nretval = context.enumerateproductiontrees(xn_node_type_depth, null,

depth_node_info_list, null);

for (xn::nodeinfolist::iterator nodeit =

depth_node_info_list.begin(); nodeit != depth_node_info_list.end(); ++nodeit)

for(int i=0;i

乙個group google上的乙個討論帖,有較高的參考價值:

SAP讀取Excel的兩個方式

1.獲取excel檔案 2.讀出檔案中的資料 3.按照 和內表字段的對應關係,將 資料填充到內錶 兩個functionalsm excel to internal table text convert xls to sap之間的差異主要存在於後兩項。alsm excel to internal ta...

php redis 寫入讀取的兩個class

class myredis return self handler 可以是乙個物件,陣列或者字串 public static function get key return value 寫入乙個鍵值對 public static function set key,value return self ...

opencv讀取並顯示兩個攝像頭

為了實現雙目攝像頭的讀取,蒐集了一些資料,有人說用directshow來實現,有人說直接可以用opencv讀取多個攝像頭。那麼,既然opencv能實現,為什麼還要裝其他的庫呢?現在就來介紹使用opencv讀取並顯示雙目攝像頭。另外我的雙目攝像頭僅僅只是兩個合在一起的只有一條usb線的。直接上 需要注...