본문 바로가기

프로그래밍/C,C++

Kinect sdk 이미지 얻기

#include <Kinect.h>



IKinectSensor* pSensor;

GetDefaultKinectSensor(&pSensor);

pSensor->Open();




// Source

IColorFrameSource* pColorSource;

pSensor->get_ColorFrameSource(&pColorSource);


IDepthFrameSource* pDepthSource;

pSensor->get_DepthFrameSource(&pDepthSource);


IInfraredFrameSource* pInfraredSource;

pSensor->getInfraredFrameSource(&pInfraredSource);




// Reader

IColorFrameReader* pColorReader;

pColorSource->OpenReader(&pColorReader);


IDepthFrameReader* pDepthReader;

pDepthSource->OpenReader(&pDepthReader);


IInfraredFrameReader* pInfraredReader;

pInfraredSource->OpenReader(&pInfraredReader);






// Description

color : 1920*1080*4

depth: 512*424*2


IFrameDescription* colorFrameDesc;

colorFrameSource->CreateFrameDescription( ColorImageFormat::ColorImageFormat_Bgra,&colorFrameDesc);

colorFrameDesc->get_Width(&width);

colorFrameDesc->get_Height(&height);

colorFrameDesc->get_BytesPerPixel( &bytesPerPixel);

int colorSize = width*height*bytesPerPixel;




Mat colorBufferMat(height, width, CV_8UC4);

Mat colorMat(height/2, width/2, CV_8UC4);



int depthSize = 512*424*2;


Mat depthBufferMat( 512, 424, CV_16UC1);

Mat depthMat( 512,424, CV_8UC1);



// Frame


* 호출 즉시 프레임 데이터가 입력되지 않으므로 대기하는 루틴 필요 *


IColorFrame* colorFrame;

pColorFrameReader->AcquireLastestFrame( &colorFrame );



IDepthFrame* depthFrame;

pDepthFrameReader->AcquireLatestFrame( &depthFrame);



IInfraredFrame* infraredFrame;

pInfraredFrameReader->AcquireLastestFrame( &infraredFrame);




// convert

colorFrame->CopyConvertedFrameDataToArray( 

colorSize , 

reinterpret_cast<BYTE*>(colorBufferMat.data), ColorImageFormat_Bgra);



// depth와 ir프레임은 16bit 값을 가지고 있으므로, 

depthFrame->AccessUnderlyingBuffer(

&depthSize,

reinterpret_cast<UINT16**>(&depthBufferMat.data) );


depthBufferMat.convertTo( depthMat, CV_8U, -255>>8, 255.0f); // 색상 반전시키려면 세번째 파라미터를 양수로




// release

if( pSensor != nullptr )

{

pSensor->Close();

}


SAFE_RELEASE(colorFrame);

SAFE_RELEASE(colorFrameDesc);

.

.

SAFE_RELEASE(pSensor);

'프로그래밍 > C,C++' 카테고리의 다른 글

[Mono] Embedding Mono  (0) 2018.10.03
MS 프로젝트 파일  (0) 2018.10.02
Boost 라이브러리 빌드  (0) 2018.08.28
[Win API] Console project  (0) 2017.12.06
[C++] 시스템 클럭 밀리세컨드 얻기  (0) 2017.12.06
C# OLEDB 엑셀 읽기  (0) 2016.02.21
[C#] 파일 읽고,쓰기 기초  (0) 2013.09.12
[C#] 이미지 처리 기본 사항들  (0) 2013.09.12
[C#] 이벤트  (0) 2013.09.12
[C#] 폼 띄우기  (0) 2013.09.12