added support for OpenNI2 IR stream #4366

This commit is contained in:
Dmitry Trifonov
2016-06-27 10:04:59 -07:00
parent 4142e737b0
commit f9e6741807
4 changed files with 394 additions and 175 deletions

View File

@@ -21,6 +21,8 @@ static void help()
"2.) Data given from RGB image generator\n"
" CAP_OPENNI_BGR_IMAGE - color image (CV_8UC3)\n"
" CAP_OPENNI_GRAY_IMAGE - gray image (CV_8UC1)\n"
"2.) Data given from IR image generator\n"
" CAP_OPENNI_IR_IMAGE - gray image (CV_16UC1)\n"
<< endl;
}
@@ -92,8 +94,8 @@ static void printCommandLineParams()
cout << "-mode= image mode: resolution and fps, supported three values: 0 - CAP_OPENNI_VGA_30HZ, 1 - CAP_OPENNI_SXGA_15HZ," << endl;
cout << " 2 - CAP_OPENNI_SXGA_30HZ (0 by default). Ignored if rgb image or gray image are not selected to show." << endl;
cout << "-m= Mask to set which output images are need. It is a string of size 5. Each element of this is '0' or '1' and" << endl;
cout << " determine: is depth map, disparity map, valid pixels mask, rgb image, gray image need or not (correspondently)?" << endl ;
cout << " By default -m=01010 i.e. disparity map and rgb image will be shown." << endl ;
cout << " determine: is depth map, disparity map, valid pixels mask, rgb image, gray image need or not (correspondently), ir image" << endl ;
cout << " By default -m=010100 i.e. disparity map and rgb image will be shown." << endl ;
cout << "-r= Filename of .oni video file. The data will grabbed from it." << endl ;
}
@@ -101,7 +103,7 @@ static void parseCommandLine( int argc, char* argv[], bool& isColorizeDisp, bool
string& filename, bool& isFileReading )
{
filename.clear();
cv::CommandLineParser parser(argc, argv, "{h help||}{cd|1|}{fmd|0|}{mode|0|}{m|01010|}{r||}");
cv::CommandLineParser parser(argc, argv, "{h help||}{cd|1|}{fmd|0|}{mode|-1|}{m|010100|}{r||}");
if (parser.has("h"))
{
help();
@@ -121,14 +123,14 @@ static void parseCommandLine( int argc, char* argv[], bool& isColorizeDisp, bool
help();
exit(-1);
}
if (flags % 100000 == 0)
if (flags % 1000000 == 0)
{
cout << "No one output image is selected." << endl;
exit(0);
}
for (int i = 0; i < 5; i++)
for (int i = 0; i < 6; i++)
{
retrievedImageFlags[4 - i] = (flags % 10 != 0);
retrievedImageFlags[5 - i] = (flags % 10 != 0);
flags /= 10;
}
}
@@ -141,7 +143,7 @@ int main( int argc, char* argv[] )
{
bool isColorizeDisp, isFixedMaxDisp;
int imageMode;
bool retrievedImageFlags[5];
bool retrievedImageFlags[6];
string filename;
bool isVideoReading;
parseCommandLine( argc, argv, isColorizeDisp, isFixedMaxDisp, imageMode, retrievedImageFlags, filename, isVideoReading );
@@ -165,7 +167,7 @@ int main( int argc, char* argv[] )
return -1;
}
if( !isVideoReading )
if( !isVideoReading && imageMode >= 0 )
{
bool modeRes=false;
switch ( imageMode )
@@ -193,13 +195,35 @@ int main( int argc, char* argv[] )
cout << "\nThis image mode is not supported by the device, the default value (CV_CAP_OPENNI_SXGA_15HZ) will be used.\n" << endl;
}
// turn on depth, color and IR if needed
if (retrievedImageFlags[0] || retrievedImageFlags[1] || retrievedImageFlags[2])
capture.set(CAP_OPENNI_DEPTH_GENERATOR_PRESENT, true);
else
capture.set(CAP_OPENNI_DEPTH_GENERATOR_PRESENT, false);
if (retrievedImageFlags[3] || retrievedImageFlags[4])
capture.set(CAP_OPENNI_IMAGE_GENERATOR_PRESENT, true);
else
capture.set(CAP_OPENNI_IMAGE_GENERATOR_PRESENT, false);
if (retrievedImageFlags[5])
capture.set(CAP_OPENNI_IR_GENERATOR_PRESENT, true);
else
capture.set(CAP_OPENNI_IR_GENERATOR_PRESENT, false);
// Print some avalible device settings.
cout << "\nDepth generator output mode:" << endl <<
"FRAME_WIDTH " << capture.get( CAP_PROP_FRAME_WIDTH ) << endl <<
"FRAME_HEIGHT " << capture.get( CAP_PROP_FRAME_HEIGHT ) << endl <<
"FRAME_MAX_DEPTH " << capture.get( CAP_PROP_OPENNI_FRAME_MAX_DEPTH ) << " mm" << endl <<
"FPS " << capture.get( CAP_PROP_FPS ) << endl <<
"REGISTRATION " << capture.get( CAP_PROP_OPENNI_REGISTRATION ) << endl;
if (capture.get(CAP_OPENNI_DEPTH_GENERATOR_PRESENT))
{
cout << "\nDepth generator output mode:" << endl <<
"FRAME_WIDTH " << capture.get(CAP_PROP_FRAME_WIDTH) << endl <<
"FRAME_HEIGHT " << capture.get(CAP_PROP_FRAME_HEIGHT) << endl <<
"FRAME_MAX_DEPTH " << capture.get(CAP_PROP_OPENNI_FRAME_MAX_DEPTH) << " mm" << endl <<
"FPS " << capture.get(CAP_PROP_FPS) << endl <<
"REGISTRATION " << capture.get(CAP_PROP_OPENNI_REGISTRATION) << endl;
}
else
{
cout << "\nDevice doesn't contain depth generator or it is not selected." << endl;
}
if( capture.get( CAP_OPENNI_IMAGE_GENERATOR_PRESENT ) )
{
cout <<
@@ -210,9 +234,20 @@ int main( int argc, char* argv[] )
}
else
{
cout << "\nDevice doesn't contain image generator." << endl;
if (!retrievedImageFlags[0] && !retrievedImageFlags[1] && !retrievedImageFlags[2])
return 0;
cout << "\nDevice doesn't contain image generator or it is not selected." << endl;
}
if( capture.get(CAP_OPENNI_IR_GENERATOR_PRESENT) )
{
cout <<
"\nIR generator output mode:" << endl <<
"FRAME_WIDTH " << capture.get(CAP_OPENNI_IR_GENERATOR + CAP_PROP_FRAME_WIDTH) << endl <<
"FRAME_HEIGHT " << capture.get(CAP_OPENNI_IR_GENERATOR + CAP_PROP_FRAME_HEIGHT) << endl <<
"FPS " << capture.get(CAP_OPENNI_IR_GENERATOR + CAP_PROP_FPS) << endl;
}
else
{
cout << "\nDevice doesn't contain IR generator or it is not selected." << endl;
}
for(;;)
@@ -222,6 +257,7 @@ int main( int argc, char* argv[] )
Mat disparityMap;
Mat bgrImage;
Mat grayImage;
Mat irImage;
if( !capture.grab() )
{
@@ -261,6 +297,13 @@ int main( int argc, char* argv[] )
if( retrievedImageFlags[4] && capture.retrieve( grayImage, CAP_OPENNI_GRAY_IMAGE ) )
imshow( "gray image", grayImage );
if( retrievedImageFlags[5] && capture.retrieve( irImage, CAP_OPENNI_IR_IMAGE ) )
{
Mat ir8;
irImage.convertTo(ir8, CV_8U, 256.0 / 3500, 0.0);
imshow("IR image", ir8);
}
}
if( waitKey( 30 ) >= 0 )