Commit b2244f87 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

improved the calibration and select3dobj samples

parent fa3c6821
...@@ -9,21 +9,28 @@ ...@@ -9,21 +9,28 @@
using namespace cv; using namespace cv;
using namespace std; using namespace std;
// example command line (for copy-n-paste): /*
// calibration -w 6 -h 8 -s 2 -n 10 -o camera.yml -op -oe [<list_of_views.txt>] example command line (for copy-n-paste):
calibration -w 6 -h 8 -s 2 -o camera.yml -op -oe image_list.xml
/* The list of views may look as following (discard the starting and ending ------ separators):
------------------- where image_list.xml is the standard OpenCV XML/YAML
view000.png file consisting of the list of strings, e.g.:
view001.png
#view002.png <?xml version="1.0"?>
view003.png <opencv_storage>
view010.png <images>
one_extra_view.jpg "view000.png"
------------------- "view001.png"
that is, the file will contain 6 lines, view002.png will not be used for calibration, <!-- view002.png -->
other ones will be (those, in which the chessboard pattern will be found) "view003.png"
*/ "view010.png"
"one_extra_view.jpg"
</images>
</opencv_storage>
you can also use a video file or live camera input to calibrate the camera
*/
enum { DETECTION = 0, CAPTURING = 1, CALIBRATED = 2 }; enum { DETECTION = 0, CAPTURING = 1, CALIBRATED = 2 };
...@@ -170,24 +177,18 @@ void saveCameraParams( const string& filename, ...@@ -170,24 +177,18 @@ void saveCameraParams( const string& filename,
} }
} }
bool readStringList( const string& filename, vector<string>& l ) static bool readStringList( const string& filename, vector<string>& l )
{ {
l.resize(0); l.resize(0);
FILE* f = fopen(filename.c_str(), "rt"); FileStorage fs(filename, FileStorage::READ);
if(!f) if( !fs.isOpened() )
return false; return false;
FileNode n = fs.getFirstTopLevelNode();
for(;;) if( n.type() != FileNode::SEQ )
{ return false;
char buf[1000]; FileNodeIterator it = n.begin(), it_end = n.end();
if( !fgets( buf, sizeof(buf)-2, f )) for( ; it != it_end; ++it )
break; l.push_back((string)*it);
char* ptr = strchr(buf, '\n');
if( ptr ) *ptr = '\0';
if( buf[0] != '\0' && buf[0] != '#' )
l.push_back(string(buf));
}
fclose(f);
return true; return true;
} }
...@@ -347,13 +348,10 @@ int main( int argc, char** argv ) ...@@ -347,13 +348,10 @@ int main( int argc, char** argv )
if( inputFilename ) if( inputFilename )
{ {
capture.open(inputFilename); if( readStringList(inputFilename, imageList) )
if( !capture.isOpened() && !readStringList(inputFilename, imageList) ) mode = CAPTURING;
{ else
fprintf( stderr, "The input file could not be opened\n" ); capture.open(inputFilename);
return -1;
}
mode = CAPTURING;
} }
else else
capture.open(cameraId); capture.open(cameraId);
...@@ -461,6 +459,8 @@ int main( int argc, char** argv ) ...@@ -461,6 +459,8 @@ int main( int argc, char** argv )
mode = CALIBRATED; mode = CALIBRATED;
else else
mode = DETECTION; mode = DETECTION;
if( !capture.isOpened() )
break;
} }
} }
return 0; return 0;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment