Related to the latest questions of mine regarding kinect one and opencv I have a loop where I am transforming the images obtained from kinect to opencv matrices and then I am showing these matrices, the procedure is quite similar to the way we are using with the VideoCapture()
class. A snippet code can be seen below:
while( 1 ){
// Frame
// get color image
IColorFrame* pColorFrame = nullptr;
hResult = pColorReader->AcquireLatestFrame( &pColorFrame );
if( SUCCEEDED( hResult ) ){
hResult = pColorFrame->CopyConvertedFrameDataToArray( bufferSizeColor, reinterpret_cast<BYTE*>( colorBufferMat.data ), ColorImageFormat::ColorImageFormat_Bgra );
// resize for visual reasons
if( SUCCEEDED( hResult ) ){
cv::resize( colorBufferMat, colorMat, cv::Size(), 0.5, 0.5 );
}
}
// get depth image
// // method 1
// IDepthFrame* pDepthFrame = nullptr;
// hResult = pDepthReader->AcquireLatestFrame( &pDepthFrame );
// if( SUCCEEDED( hResult ) ){
// hResult = pDepthFrame->AccessUnderlyingBuffer( &bufferSizeDepth, reinterpret_cast<UINT16**>( &depthBufferMat.data ) );
// if( SUCCEEDED( hResult ) ){
// depthBufferMat.convertTo( depthMat, CV_8U, 0.05f/*-255.0f / 8000.0f, 255.0f*/ );
// }
// }
// method 2
IDepthFrame* pDepthFrame = nullptr;
hResult = pDepthReader->AcquireLatestFrame( &pDepthFrame );
if( SUCCEEDED( hResult ) ){
unsigned int bufferSize = 0;
unsigned short* buffer = nullptr;
hResult = pDepthFrame->AccessUnderlyingBuffer( &bufferSize, &buffer );
if( SUCCEEDED( hResult ) ){
for( int y = 0; y < depthHeight; y++ ){
for( int x = 0; x < depthWidth; x++ ){
unsigned int index = y * depthWidth + x;
BYTE intensity = buffer[ index ] == 0 || buffer[ index ] > 4095/*2047*/ ? 0 : 255 - (BYTE)(((float)buffer[ index ] / 4095.0f/*2047.0f*/) * 255.0f);
depthMat.at<unsigned char>( y, x ) = intensity;
}
}
}
// memcpy(depth_im.data, buffer, depthHeight*depthWidth*sizeof(UINT16)); // creating an opencv image from the raw data in buffer above with the raw data
}
// get a colormap of the depth image
applyColorMap(depthMat, colorDepthMat, COLORMAP_JET);
// get infrared image
IInfraredFrame* pInfraredFrame = nullptr;
hResult = pInfraredReader->AcquireLatestFrame( &pInfraredFrame );
if( SUCCEEDED( hResult ) ){
unsigned int bufferSize = 0;
unsigned short* buffer = nullptr;
hResult/*IR*/ = pInfraredFrame->AccessUnderlyingBuffer( &bufferSize, &buffer );
if( SUCCEEDED( hResult ) ){
for( int y = 0; y < irHeight; y++ ){
for( int x = 0; x < irWidth; x++ ){
unsigned int index = y * irWidth + x;
infraredMat.at<unsigned char>( y, x ) = buffer[ index ] >> 8;
}
}
}
}
SafeRelease( pColorFrame );
SafeRelease( pDepthFrame );
SafeRelease( pInfraredFrame );
cv::imshow( "Color", colorMat );
// raw size
// cv::imshow( "Color", colorBufferMat );
cv::imshow( "Depth", depthMat );
cv::imshow( "Color Depth", colorDepthMat );
cv::imshow( "Infrared", infraredMat );
int key = waitKey(1);
if( key == VK_ESCAPE ){
break;
}
}
the question now is, is there any way to accurate measure the framerate that I get from kinect? I guess it does not have to do strictly related to kinect it could be any normal camera. Searching around I could something clear. Officially it says that kinect supports 30 fps so I would like to see if I get something close to that.