Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
c1a6cb62
Commit
c1a6cb62
authored
Mar 21, 2012
by
Maria Dimashova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added oni-files reading
parent
82a2a50f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
14 deletions
+77
-14
cap_openni.cpp
modules/highgui/src/cap_openni.cpp
+52
-10
openni_capture.cpp
samples/cpp/openni_capture.cpp
+25
-4
No files found.
modules/highgui/src/cap_openni.cpp
View file @
c1a6cb62
...
...
@@ -124,6 +124,8 @@ protected:
xn
::
Context
context
;
bool
isContextOpened
;
xn
::
ProductionNode
productionNode
;
// Data generators with its metadata
xn
::
DepthGenerator
depthGenerator
;
xn
::
DepthMetaData
depthMetaData
;
...
...
@@ -171,14 +173,22 @@ XnMapOutputMode defaultMapOutputMode()
CvCapture_OpenNI
::
CvCapture_OpenNI
(
int
index
)
{
XnStatus
status
;
isContextOpened
=
false
;
// Initialize and configure the context.
if
(
context
.
Init
()
==
XN_STATUS_OK
)
status
=
context
.
Init
();
if
(
status
!=
XN_STATUS_OK
)
{
std
::
cerr
<<
"CvCapture_OpenNI::CvCapture_OpenNI : Failed to initialize the context: "
<<
std
::
string
(
xnGetStatusString
(
status
))
<<
std
::
endl
;
return
;
}
// Find devices
xn
::
NodeInfoList
devicesList
;
XnStatus
status
=
context
.
EnumerateProductionTrees
(
XN_NODE_TYPE_DEVICE
,
NULL
,
devicesList
,
0
);
status
=
context
.
EnumerateProductionTrees
(
XN_NODE_TYPE_DEVICE
,
NULL
,
devicesList
,
0
);
if
(
status
!=
XN_STATUS_OK
)
{
std
::
cerr
<<
"CvCapture_OpenNI::CvCapture_OpenNI : Failed to enumerate production trees: "
...
...
@@ -191,7 +201,7 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
for
(
int
i
=
0
;
i
<
index
;
++
i
)
it
++
;
xn
::
NodeInfo
deviceNode
=
*
it
;
status
=
context
.
CreateProductionTree
(
device
Node
);
status
=
context
.
CreateProductionTree
(
deviceNode
,
production
Node
);
if
(
status
!=
XN_STATUS_OK
)
{
std
::
cerr
<<
"CvCapture_OpenNI::CvCapture_OpenNI : Failed to create production tree: "
...
...
@@ -275,14 +285,46 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
outputMaps
.
resize
(
outputMapsTypesCount
);
isContextOpened
=
true
;
}
setProperty
(
CV_CAP_PROP_OPENNI_REGISTRATION
,
1.0
);
}
CvCapture_OpenNI
::
CvCapture_OpenNI
(
const
char
*
filename
)
{
CV_Assert
(
0
);
XnStatus
status
;
isContextOpened
=
false
;
// Initialize and configure the context.
status
=
context
.
Init
();
if
(
status
!=
XN_STATUS_OK
)
{
std
::
cerr
<<
"CvCapture_OpenNI::CvCapture_OpenNI : Failed to initialize the context: "
<<
std
::
string
(
xnGetStatusString
(
status
))
<<
std
::
endl
;
return
;
}
// Open file
status
=
context
.
OpenFileRecording
(
filename
,
productionNode
);
if
(
status
!=
XN_STATUS_OK
)
{
std
::
cerr
<<
"CvCapture_OpenNI::CvCapture_OpenNI : Failed to open input file ("
<<
filename
<<
"): "
<<
std
::
string
(
xnGetStatusString
(
status
))
<<
std
::
endl
;
return
;
}
std
::
cout
<<
context
.
FindExistingNode
(
XN_NODE_TYPE_DEPTH
,
depthGenerator
)
<<
std
::
endl
;
std
::
cout
<<
context
.
FindExistingNode
(
XN_NODE_TYPE_IMAGE
,
imageGenerator
)
<<
std
::
endl
;
if
(
!
readCamerasParams
()
)
{
std
::
cerr
<<
"CvCapture_OpenNI::CvCapture_OpenNI : Could not read cameras parameters"
<<
std
::
endl
;
return
;
}
outputMaps
.
resize
(
outputMapsTypesCount
);
isContextOpened
=
true
;
}
CvCapture_OpenNI
::~
CvCapture_OpenNI
()
...
...
@@ -424,6 +466,7 @@ double CvCapture_OpenNI::getDepthGeneratorProperty( int propIdx )
break
;
case
CV_CAP_PROP_OPENNI_REGISTRATION
:
propValue
=
depthGenerator
.
GetAlternativeViewPointCap
().
IsViewPointAs
(
imageGenerator
)
?
1.0
:
0.0
;
break
;
default
:
{
std
::
stringstream
ss
;
...
...
@@ -731,15 +774,14 @@ IplImage* CvCapture_OpenNI::retrieveValidDepthMask()
inline
void
getBGRImageFromMetaData
(
const
xn
::
ImageMetaData
&
imageMetaData
,
cv
::
Mat
&
bgrImage
)
{
int
cols
=
imageMetaData
.
XRes
();
int
rows
=
imageMetaData
.
YRes
();
cv
::
Mat
rgbImage
(
rows
,
cols
,
CV_8UC3
);
if
(
imageMetaData
.
PixelFormat
()
!=
XN_PIXEL_FORMAT_RGB24
)
CV_Error
(
CV_StsUnsupportedFormat
,
"Unsupported format of grabbed image
\n
"
);
cv
::
Mat
rgbImage
(
imageMetaData
.
YRes
(),
imageMetaData
.
XRes
(),
CV_8UC3
);
const
XnRGB24Pixel
*
pRgbImage
=
imageMetaData
.
RGB24Data
();
// CV_Assert( 3*sizeof(uchar) == sizeof(XnRGB24Pixel) );
memcpy
(
rgbImage
.
data
,
pRgbImage
,
cols
*
rows
*
sizeof
(
XnRGB24Pixel
)
);
memcpy
(
rgbImage
.
data
,
pRgbImage
,
rgbImage
.
total
()
*
sizeof
(
XnRGB24Pixel
)
);
cv
::
cvtColor
(
rgbImage
,
bgrImage
,
CV_RGB2BGR
);
}
...
...
samples/cpp/openni_capture.cpp
View file @
c1a6cb62
...
...
@@ -93,9 +93,11 @@ void printCommandLineParams()
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
<<
"-r Filename of .oni video file. The data will grabbed from it."
<<
endl
;
}
void
parseCommandLine
(
int
argc
,
char
*
argv
[],
bool
&
isColorizeDisp
,
bool
&
isFixedMaxDisp
,
int
&
imageMode
,
bool
retrievedImageFlags
[]
)
void
parseCommandLine
(
int
argc
,
char
*
argv
[],
bool
&
isColorizeDisp
,
bool
&
isFixedMaxDisp
,
int
&
imageMode
,
bool
retrievedImageFlags
[],
string
&
filename
,
bool
&
isFileReading
)
{
// set defaut values
isColorizeDisp
=
true
;
...
...
@@ -108,6 +110,9 @@ void parseCommandLine( int argc, char* argv[], bool& isColorizeDisp, bool& isFix
retrievedImageFlags
[
3
]
=
true
;
retrievedImageFlags
[
4
]
=
false
;
filename
.
clear
();
isFileReading
=
false
;
if
(
argc
==
1
)
{
help
();
...
...
@@ -154,6 +159,11 @@ void parseCommandLine( int argc, char* argv[], bool& isColorizeDisp, bool& isFix
exit
(
0
);
}
}
else
if
(
!
strcmp
(
argv
[
i
],
"-r"
)
)
{
filename
=
argv
[
++
i
];
isFileReading
=
true
;
}
else
{
cout
<<
"Unsupported command line argument: "
<<
argv
[
i
]
<<
"."
<<
endl
;
...
...
@@ -172,10 +182,17 @@ int main( int argc, char* argv[] )
bool
isColorizeDisp
,
isFixedMaxDisp
;
int
imageMode
;
bool
retrievedImageFlags
[
5
];
parseCommandLine
(
argc
,
argv
,
isColorizeDisp
,
isFixedMaxDisp
,
imageMode
,
retrievedImageFlags
);
string
filename
;
bool
isVideoReading
;
parseCommandLine
(
argc
,
argv
,
isColorizeDisp
,
isFixedMaxDisp
,
imageMode
,
retrievedImageFlags
,
filename
,
isVideoReading
);
cout
<<
"Device opening ..."
<<
endl
;
VideoCapture
capture
(
CV_CAP_OPENNI
);
VideoCapture
capture
;
if
(
isVideoReading
)
capture
.
open
(
filename
);
else
capture
.
open
(
CV_CAP_OPENNI
);
cout
<<
"done."
<<
endl
;
if
(
!
capture
.
isOpened
()
)
...
...
@@ -184,6 +201,8 @@ int main( int argc, char* argv[] )
return
-
1
;
}
if
(
!
isVideoReading
)
{
bool
modeRes
=
false
;
switch
(
imageMode
)
{
...
...
@@ -201,13 +220,15 @@ int main( int argc, char* argv[] )
}
if
(
!
modeRes
)
cout
<<
"
\n
This image mode is not supported by the device, the default value (CV_CAP_OPENNI_SXGA_15HZ) will be used.
\n
"
<<
endl
;
}
// Print some avalible device settings.
cout
<<
"
\n
Depth generator output mode:"
<<
endl
<<
"FRAME_WIDTH "
<<
capture
.
get
(
CV_CAP_PROP_FRAME_WIDTH
)
<<
endl
<<
"FRAME_HEIGHT "
<<
capture
.
get
(
CV_CAP_PROP_FRAME_HEIGHT
)
<<
endl
<<
"FRAME_MAX_DEPTH "
<<
capture
.
get
(
CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH
)
<<
" mm"
<<
endl
<<
"FPS "
<<
capture
.
get
(
CV_CAP_PROP_FPS
)
<<
endl
;
"FPS "
<<
capture
.
get
(
CV_CAP_PROP_FPS
)
<<
endl
<<
"REGISTRATION "
<<
capture
.
get
(
CV_CAP_PROP_OPENNI_REGISTRATION
)
<<
endl
;
if
(
capture
.
get
(
CV_CAP_OPENNI_IMAGE_GENERATOR_PRESENT
)
)
{
cout
<<
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment