Update samples (#10333)
* Update samples * Update calib3d.hpp * Update calib3d.hpp * Update calib3d.hpp * Update calib3d.hpp
This commit is contained in:
committed by
Vadim Pisarevsky
parent
d3a124c820
commit
1654dfe3a9
@@ -1,7 +1,6 @@
|
||||
#include <opencv2/features2d.hpp>
|
||||
#include <opencv2/imgcodecs.hpp>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <vector>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
@@ -10,13 +9,17 @@ using namespace cv;
|
||||
const float inlier_threshold = 2.5f; // Distance threshold to identify inliers
|
||||
const float nn_match_ratio = 0.8f; // Nearest neighbor matching ratio
|
||||
|
||||
int main(void)
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
Mat img1 = imread("../data/graf1.png", IMREAD_GRAYSCALE);
|
||||
Mat img2 = imread("../data/graf3.png", IMREAD_GRAYSCALE);
|
||||
CommandLineParser parser(argc, argv,
|
||||
"{@img1 | ../data/graf1.png | input image 1}"
|
||||
"{@img2 | ../data/graf3.png | input image 2}"
|
||||
"{@homography | ../data/H1to3p.xml | homography matrix}");
|
||||
Mat img1 = imread(parser.get<String>("@img1"), IMREAD_GRAYSCALE);
|
||||
Mat img2 = imread(parser.get<String>("@img2"), IMREAD_GRAYSCALE);
|
||||
|
||||
Mat homography;
|
||||
FileStorage fs("../data/H1to3p.xml", FileStorage::READ);
|
||||
FileStorage fs(parser.get<String>("@homography"), FileStorage::READ);
|
||||
fs.getFirstTopLevelNode() >> homography;
|
||||
|
||||
vector<KeyPoint> kpts1, kpts2;
|
||||
|
||||
Executable → Regular
+12
-14
@@ -153,16 +153,13 @@ void decomposeHomography(const string &img1Path, const string &img2Path, const S
|
||||
//! [decompose-homography-estimated-by-findHomography]
|
||||
}
|
||||
|
||||
const char* about = "Code for homography tutorial.\n"
|
||||
"Example 4: decompose the homography matrix.\n";
|
||||
|
||||
const char* params
|
||||
= "{ h help | false | print usage }"
|
||||
"{ image1 | | path to the source chessboard image (left02.jpg) }"
|
||||
"{ image2 | | path to the desired chessboard image (left01.jpg) }"
|
||||
"{ intrinsics | | path to camera intrinsics (left_intrinsics.yml) }"
|
||||
"{ width w | 9 | chessboard width }"
|
||||
"{ height h | 6 | chessboard height }"
|
||||
= "{ help h | | print usage }"
|
||||
"{ image1 | ../data/left02.jpg | path to the source chessboard image }"
|
||||
"{ image2 | ../data/left01.jpg | path to the desired chessboard image }"
|
||||
"{ intrinsics | ../data/left_intrinsics.yml | path to camera intrinsics }"
|
||||
"{ width bw | 9 | chessboard width }"
|
||||
"{ height bh | 6 | chessboard height }"
|
||||
"{ square_size | 0.025 | chessboard square size }";
|
||||
}
|
||||
|
||||
@@ -170,19 +167,20 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
CommandLineParser parser(argc, argv, params);
|
||||
|
||||
if (parser.get<bool>("help"))
|
||||
if ( parser.has("help") )
|
||||
{
|
||||
cout << about << endl;
|
||||
parser.about( "Code for homography tutorial.\n"
|
||||
"Example 4: decompose the homography matrix.\n" );
|
||||
parser.printMessage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Size patternSize(parser.get<int>("width"), parser.get<int>("height"));
|
||||
float squareSize = (float) parser.get<double>("square_size");
|
||||
decomposeHomography(parser.get<string>("image1"),
|
||||
parser.get<string>("image2"),
|
||||
decomposeHomography(parser.get<String>("image1"),
|
||||
parser.get<String>("image2"),
|
||||
patternSize, squareSize,
|
||||
parser.get<string>("intrinsics"));
|
||||
parser.get<String>("intrinsics"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
+12
-14
@@ -168,16 +168,13 @@ void homographyFromCameraDisplacement(const string &img1Path, const string &img2
|
||||
waitKey();
|
||||
}
|
||||
|
||||
const char* about = "Code for homography tutorial.\n"
|
||||
"Example 3: homography from the camera displacement.\n";
|
||||
|
||||
const char* params
|
||||
= "{ h help | false | print usage }"
|
||||
"{ image1 | | path to the source chessboard image (left02.jpg) }"
|
||||
"{ image2 | | path to the desired chessboard image (left01.jpg) }"
|
||||
"{ intrinsics | | path to camera intrinsics (left_intrinsics.yml) }"
|
||||
"{ width w | 9 | chessboard width }"
|
||||
"{ height h | 6 | chessboard height }"
|
||||
= "{ help h | | print usage }"
|
||||
"{ image1 | ../data/left02.jpg | path to the source chessboard image }"
|
||||
"{ image2 | ../data/left01.jpg | path to the desired chessboard image }"
|
||||
"{ intrinsics | ../data/left_intrinsics.yml | path to camera intrinsics }"
|
||||
"{ width bw | 9 | chessboard width }"
|
||||
"{ height bh | 6 | chessboard height }"
|
||||
"{ square_size | 0.025 | chessboard square size }";
|
||||
}
|
||||
|
||||
@@ -185,19 +182,20 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
CommandLineParser parser(argc, argv, params);
|
||||
|
||||
if (parser.get<bool>("help"))
|
||||
if (parser.has("help"))
|
||||
{
|
||||
cout << about << endl;
|
||||
parser.about("Code for homography tutorial.\n"
|
||||
"Example 3: homography from the camera displacement.\n");
|
||||
parser.printMessage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Size patternSize(parser.get<int>("width"), parser.get<int>("height"));
|
||||
float squareSize = (float) parser.get<double>("square_size");
|
||||
homographyFromCameraDisplacement(parser.get<string>("image1"),
|
||||
parser.get<string>("image2"),
|
||||
homographyFromCameraDisplacement(parser.get<String>("image1"),
|
||||
parser.get<String>("image2"),
|
||||
patternSize, squareSize,
|
||||
parser.get<string>("intrinsics"));
|
||||
parser.get<String>("intrinsics"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
%YAML:1.0
|
||||
---
|
||||
image_width: 640
|
||||
image_height: 480
|
||||
board_width: 9
|
||||
board_height: 6
|
||||
square_size: 1.
|
||||
aspectRatio: 1.
|
||||
flags: 2
|
||||
camera_matrix: !!opencv-matrix
|
||||
rows: 3
|
||||
cols: 3
|
||||
dt: d
|
||||
data: [ 5.3591575307485539e+02, 0., 3.4228314953752817e+02, 0.,
|
||||
5.3591575307485539e+02, 2.3557082321320789e+02, 0., 0., 1. ]
|
||||
distortion_coefficients: !!opencv-matrix
|
||||
rows: 5
|
||||
cols: 1
|
||||
dt: d
|
||||
data: [ -2.6637290673868386e-01, -3.8586722644459073e-02,
|
||||
1.7831841406179300e-03, -2.8122035403651473e-04,
|
||||
2.3838760574917545e-01 ]
|
||||
avg_reprojection_error: 3.9259109564815858e-01
|
||||
Executable → Regular
+10
-12
@@ -92,15 +92,12 @@ void perspectiveCorrection(const string &img1Path, const string &img2Path, const
|
||||
//! [compute-transformed-corners]
|
||||
}
|
||||
|
||||
const char* about = "Code for homography tutorial.\n"
|
||||
"Example 2: perspective correction.\n";
|
||||
|
||||
const char* params
|
||||
= "{ h help | false | print usage }"
|
||||
"{ image1 | | path to the source chessboard image (left02.jpg) }"
|
||||
"{ image2 | | path to the desired chessboard image (left01.jpg) }"
|
||||
"{ width w | 9 | chessboard width }"
|
||||
"{ height h | 6 | chessboard height }";
|
||||
= "{ help h | | print usage }"
|
||||
"{ image1 | ../data/left02.jpg | path to the source chessboard image }"
|
||||
"{ image2 | ../data/left01.jpg | path to the desired chessboard image }"
|
||||
"{ width bw | 9 | chessboard width }"
|
||||
"{ height bh | 6 | chessboard height }";
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -108,16 +105,17 @@ int main(int argc, char *argv[])
|
||||
cv::RNG rng( 0xFFFFFFFF );
|
||||
CommandLineParser parser(argc, argv, params);
|
||||
|
||||
if (parser.get<bool>("help"))
|
||||
if (parser.has("help"))
|
||||
{
|
||||
cout << about << endl;
|
||||
parser.about("Code for homography tutorial.\n"
|
||||
"Example 2: perspective correction.\n");
|
||||
parser.printMessage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Size patternSize(parser.get<int>("width"), parser.get<int>("height"));
|
||||
perspectiveCorrection(parser.get<string>("image1"),
|
||||
parser.get<string>("image2"),
|
||||
perspectiveCorrection(parser.get<String>("image1"),
|
||||
parser.get<String>("image2"),
|
||||
patternSize, rng);
|
||||
|
||||
return 0;
|
||||
Executable → Regular
+10
-12
@@ -116,15 +116,12 @@ void poseEstimationFromCoplanarPoints(const string &imgPath, const string &intri
|
||||
//! [display-pose]
|
||||
}
|
||||
|
||||
const char* about = "Code for homography tutorial.\n"
|
||||
"Example 1: pose from homography with coplanar points.\n";
|
||||
|
||||
const char* params
|
||||
= "{ h help | false | print usage }"
|
||||
"{ image | | path to a chessboard image (left04.jpg) }"
|
||||
"{ intrinsics | | path to camera intrinsics (left_intrinsics.yml) }"
|
||||
"{ width w | 9 | chessboard width }"
|
||||
"{ height h | 6 | chessboard height }"
|
||||
= "{ help h | | print usage }"
|
||||
"{ image | ../data/left04.jpg | path to a chessboard image }"
|
||||
"{ intrinsics | ../data/left_intrinsics.yml | path to camera intrinsics }"
|
||||
"{ width bw | 9 | chessboard width }"
|
||||
"{ height bh | 6 | chessboard height }"
|
||||
"{ square_size | 0.025 | chessboard square size }";
|
||||
}
|
||||
|
||||
@@ -132,17 +129,18 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
CommandLineParser parser(argc, argv, params);
|
||||
|
||||
if (parser.get<bool>("help"))
|
||||
if (parser.has("help"))
|
||||
{
|
||||
cout << about << endl;
|
||||
parser.about("Code for homography tutorial.\n"
|
||||
"Example 1: pose from homography with coplanar points.\n");
|
||||
parser.printMessage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Size patternSize(parser.get<int>("width"), parser.get<int>("height"));
|
||||
float squareSize = (float) parser.get<double>("square_size");
|
||||
poseEstimationFromCoplanarPoints(parser.get<string>("image"),
|
||||
parser.get<string>("intrinsics"),
|
||||
poseEstimationFromCoplanarPoints(parser.get<String>("image"),
|
||||
parser.get<String>("intrinsics"),
|
||||
patternSize, squareSize);
|
||||
|
||||
return 0;
|
||||
Reference in New Issue
Block a user