15 static bool calibrated =
false;
16 static int calib_count=0;
19 static int64 prev_tick=0;
20 static bool initialized =
false;
23 cam.
SetRes(image->width, image->height);
24 prev_tick = cvGetTickCount();
28 bool flip_image = (image->origin?
true:
false);
31 image->origin = !image->origin;
41 std::cout<<
"Calibrating..."<<endl;
52 int64 tick = cvGetTickCount();
53 if ((tick - prev_tick) > (cvGetTickFrequency() * 1000 * 1000 * 1.5)) {
75 image->origin = !image->origin;
79 int main(
int argc,
char *argv[])
84 filename = filename.substr(filename.find_last_of(
'\\') + 1);
85 std::cout <<
"SampleCamCalib" << std::endl;
86 std::cout <<
"==============" << std::endl;
87 std::cout << std::endl;
88 std::cout <<
"Description:" << std::endl;
89 std::cout <<
" This is an example of how to use the 'Camera' and 'ProjPoints' classes" << std::endl;
90 std::cout <<
" to perform camera calibration. Point the camera to the chessboard" << std::endl;
91 std::cout <<
" calibration pattern (see ALVAR.pdf) from several directions until 50" << std::endl;
92 std::cout <<
" calibration images are collected. A 'calib.xml' file that contains the" << std::endl;
93 std::cout <<
" internal parameters of the camera is generated and can be used by other" << std::endl;
94 std::cout <<
" applications that require a calibrated camera." << std::endl;
95 std::cout << std::endl;
96 std::cout <<
"Usage:" << std::endl;
97 std::cout <<
" " << filename <<
" [device]" << std::endl;
98 std::cout << std::endl;
99 std::cout <<
" device integer selecting device from enumeration list (default 0)" << std::endl;
100 std::cout <<
" highgui capture devices are prefered" << std::endl;
101 std::cout << std::endl;
102 std::cout <<
"Keyboard Shortcuts:" << std::endl;
103 std::cout <<
" q: quit" << std::endl;
104 std::cout << std::endl;
111 if (plugins.size() < 1) {
112 std::cout <<
"Could not find any capture plugins." << std::endl;
117 std::cout <<
"Available Plugins: ";
119 std::cout << std::endl;
123 if (devices.size() < 1) {
124 std::cout <<
"Could not find any capture devices." << std::endl;
131 selectedDevice = atoi(argv[1]);
133 if (selectedDevice >= (
int)devices.size()) {
138 std::cout <<
"Enumerated Capture Devices:" << std::endl;
140 std::cout << std::endl;
144 std::string uniqueName = devices[selectedDevice].uniqueName();
149 std::stringstream settingsFilename;
150 settingsFilename <<
"camera_settings_" << uniqueName <<
".xml";
157 std::cout <<
"Loading settings: " << settingsFilename.str() << std::endl;
160 std::stringstream title;
166 std::cout <<
"Saving settings: " << settingsFilename.str() << std::endl;
175 std::cout <<
"Could not initialize the selected capture backend." << std::endl;
180 catch (
const std::exception &e) {
181 std::cout <<
"Exception: " << e.what() << endl;
184 std::cout <<
"Exception: unknown" << std::endl;
static CvTestbed & Instance()
The one and only instance of CvTestbed is accessed using CvTestbed::Instance()
Capture * createCapture(const CaptureDevice captureDevice)
Create Capture class. Transfers onwership to the caller.
bool SaveCalib(const char *calibfile, FILE_FORMAT format=FILE_FORMAT_DEFAULT)
Save the current calibration information to a file.
virtual void stop()=0
Stops the camera capture.
int main(int argc, char *argv[])
This file implements a camera used for projecting points and computing homographies.
virtual bool start()=0
Starts the camera capture.
CaptureDevice captureDevice()
The camera information associated to this capture object.
void SetVideoCallback(void(*_videocallback)(IplImage *image))
Set the videocallback function that will be called for every frame.
static CaptureFactory * instance()
The singleton instance of CaptureFactory.
void Reset()
Reset object_points , image_points and point_counts.
void SetRes(int _x_res, int _y_res)
If we have no calibration file we can still adjust the default calibration to current resolution...
std::stringstream calibrationFilename
std::vector< CaptureDevice > CaptureDeviceVector
Vector of CaptureDevices.
Simple Camera class for calculating distortions, orientation or projections with pre-calibrated camer...
std::string captureType() const
The type of capture backend.
bool StartVideo(Capture *_cap, const char *_wintitle=0)
Start video input from given capture device.
std::vector< std::string > CapturePluginVector
Vector of strings.
void outputEnumeratedPlugins(CaptureFactory::CapturePluginVector &plugins)
std::vector< CvPoint3D64f > object_points
3D object points corresponding with the detected 2D image points.
void ProjectPoints(std::vector< CvPoint3D64f > &pw, Pose *pose, std::vector< CvPoint2D64f > &pi) const
Project points.
CaptureDeviceVector enumerateDevices(const std::string &captureType="")
Enumerate capture devices currently available.
Simple structure for collecting 2D and 3D points e.g. for camera calibration.
Pose representation derived from the Rotation class
CapturePluginVector enumeratePlugins()
Enumerate capture plugins currently available.
void Calibrate(ProjPoints &pp)
Calibrate using the collected ProjPoints.
std::vector< CvPoint2D64f > image_points
Detected 2D object points If point_counts[0] == 10, then the first 10 points are detected in the firs...
void outputEnumeratedDevices(CaptureFactory::CaptureDeviceVector &devices, int selectedDevice)
bool AddPointsUsingChessboard(IplImage *image, double etalon_square_size, int etalon_rows, int etalon_columns, bool visualize)
Add elements to object_points , image_points and point_counts using Chessboard pattern.
Capture interface that plugins must implement.
void CalcExteriorOrientation(std::vector< CvPoint3D64f > &pw, std::vector< CvPoint2D64f > &pi, Pose *pose)
Calculate exterior orientation.
virtual bool loadSettings(std::string filename)
Load camera settings from a file.
void videocallback(IplImage *image)
int defaultDevice(CaptureFactory::CaptureDeviceVector &devices)
virtual void setResolution(const unsigned long xResolution, const unsigned long yResolution)
Set the resolution.
const int calib_count_max
virtual bool saveSettings(std::string filename)
Save camera settings to a file.