mirror of
https://github.com/opencv/opencv.git
synced 2026-07-25 21:33:04 +04:00
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
@@ -15,7 +15,7 @@ using namespace std;
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int, char** argv )
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
Mat src, dst;
|
||||
|
||||
@@ -23,12 +23,14 @@ int main( int, char** argv )
|
||||
const char* equalized_window = "Equalized Image";
|
||||
|
||||
/// Load image
|
||||
src = imread( argv[1], IMREAD_COLOR );
|
||||
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/lena.jpg | input image}" );
|
||||
src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
|
||||
if( src.empty() )
|
||||
{ cout<<"Usage: ./EqualizeHist_Demo <path_to_image>"<<endl;
|
||||
return -1;
|
||||
}
|
||||
{
|
||||
cout << "Could not open or find the image!\n" << endl;
|
||||
cout << "Usage: " << argv[0] << " <Input image>" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// Convert to grayscale
|
||||
cvtColor( src, src, COLOR_BGR2GRAY );
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
*/
|
||||
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
/// Global variables
|
||||
Mat src, erosion_dst, dilation_dst;
|
||||
@@ -27,13 +28,17 @@ void Dilation( int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int, char** argv )
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/// Load an image
|
||||
src = imread( argv[1], IMREAD_COLOR );
|
||||
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/chicky_512.png | input image}" );
|
||||
src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
|
||||
if( src.empty() )
|
||||
{ return -1; }
|
||||
{
|
||||
cout << "Could not open or find the image!\n" << endl;
|
||||
cout << "Usage: " << argv[0] << " <Input image>" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// Create windows
|
||||
namedWindow( "Erosion Demo", WINDOW_AUTOSIZE );
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
@@ -32,15 +33,14 @@ void Morphology_Operations( int, void* );
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
//![load]
|
||||
String imageName("../data/baboon.jpg"); // by default
|
||||
if (argc > 1)
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/baboon.jpg | input image}" );
|
||||
src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
|
||||
if (src.empty())
|
||||
{
|
||||
imageName = argv[1];
|
||||
std::cout << "Could not open or find the image!\n" << std::endl;
|
||||
std::cout << "Usage: " << argv[0] << " <Input image>" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
src = imread(imageName, IMREAD_COLOR); // Load an image
|
||||
|
||||
if( src.empty() )
|
||||
{ return -1; }
|
||||
//![load]
|
||||
|
||||
//![window]
|
||||
|
||||
@@ -11,16 +11,15 @@ void show_wait_destroy(const char* winname, cv::Mat img);
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
int main(int, char** argv)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
//! [load_image]
|
||||
// Load the image
|
||||
Mat src = imread(argv[1]);
|
||||
|
||||
// Check if image is loaded fine
|
||||
if(src.empty()){
|
||||
printf(" Error opening image\n");
|
||||
printf(" Program Arguments: [image_path]\n");
|
||||
CommandLineParser parser(argc, argv, "{@input | ../data/notes.png | input image}");
|
||||
Mat src = imread(parser.get<String>("@input"), IMREAD_COLOR);
|
||||
if (src.empty())
|
||||
{
|
||||
cout << "Could not open or find the image!\n" << endl;
|
||||
cout << "Usage: " << argv[0] << " <Input image>" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
*/
|
||||
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
@@ -56,13 +56,18 @@ static void CannyThreshold(int, void*)
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int, char** argv )
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
//![load]
|
||||
src = imread( argv[1], IMREAD_COLOR ); // Load an image
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/fruits.jpg | input image}" );
|
||||
src = imread( parser.get<String>( "@input" ), IMREAD_COLOR ); // Load an image
|
||||
|
||||
if( src.empty() )
|
||||
{ return -1; }
|
||||
{
|
||||
std::cout << "Could not open or find the image!\n" << std::endl;
|
||||
std::cout << "Usage: " << argv[0] << " <Input image>" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
//![load]
|
||||
|
||||
//![create_mat]
|
||||
|
||||
@@ -20,7 +20,7 @@ const char* warp_rotate_window = "Warp + Rotate";
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int, char** argv )
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
Point2f srcTri[3];
|
||||
Point2f dstTri[3];
|
||||
@@ -30,7 +30,14 @@ int main( int, char** argv )
|
||||
Mat src, warp_dst, warp_rotate_dst;
|
||||
|
||||
/// Load the image
|
||||
src = imread( argv[1], IMREAD_COLOR );
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/lena.jpg | input image}" );
|
||||
src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
|
||||
if( src.empty() )
|
||||
{
|
||||
cout << "Could not open or find the image!\n" << endl;
|
||||
cout << "Usage: " << argv[0] << " <Input image>" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// Set the dst image the same type and size as src
|
||||
warp_dst = Mat::zeros( src.rows, src.cols, src.type() );
|
||||
|
||||
@@ -12,7 +12,7 @@ using namespace std;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
//![load]
|
||||
const char* filename = argc >=2 ? argv[1] : "../../../data/smarties.png";
|
||||
const char* filename = argc >=2 ? argv[1] : "../data/smarties.png";
|
||||
|
||||
// Loads an image
|
||||
Mat src = imread( filename, IMREAD_COLOR );
|
||||
|
||||
@@ -16,7 +16,7 @@ int main(int argc, char** argv)
|
||||
Mat dst, cdst, cdstP;
|
||||
|
||||
//![load]
|
||||
const char* default_file = "../../../data/sudoku.png";
|
||||
const char* default_file = "../data/sudoku.png";
|
||||
const char* filename = argc >=2 ? argv[1] : default_file;
|
||||
|
||||
// Loads an image
|
||||
|
||||
@@ -23,11 +23,18 @@ void thresh_callback(int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int, char** argv )
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
//![setup]
|
||||
/// Load source image
|
||||
src = imread( argv[1], IMREAD_COLOR );
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" );
|
||||
src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
|
||||
if( src.empty() )
|
||||
{
|
||||
cout << "Could not open or find the image!\n" << endl;
|
||||
cout << "usage: " << argv[0] << " <Input image>" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// Convert image to gray and blur it
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
@@ -84,8 +91,8 @@ void thresh_callback(int, void* )
|
||||
//![allthework]
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{
|
||||
approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true );
|
||||
boundRect[i] = boundingRect( Mat(contours_poly[i]) );
|
||||
approxPolyDP( contours[i], contours_poly[i], 3, true );
|
||||
boundRect[i] = boundingRect( contours_poly[i] );
|
||||
minEnclosingCircle( contours_poly[i], center[i], radius[i] );
|
||||
}
|
||||
//![allthework]
|
||||
|
||||
@@ -23,10 +23,17 @@ void thresh_callback(int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int, char** argv )
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
src = imread( argv[1], IMREAD_COLOR );
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" );
|
||||
src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
|
||||
if( src.empty() )
|
||||
{
|
||||
cout << "Could not open or find the image!\n" << endl;
|
||||
cout << "Usage: " << argv[0] << " <Input image>" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// Convert image to gray and blur it
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
@@ -63,9 +70,9 @@ void thresh_callback(int, void* )
|
||||
vector<RotatedRect> minEllipse( contours.size() );
|
||||
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{ minRect[i] = minAreaRect( Mat(contours[i]) );
|
||||
{ minRect[i] = minAreaRect( contours[i] );
|
||||
if( contours[i].size() > 5 )
|
||||
{ minEllipse[i] = fitEllipse( Mat(contours[i]) ); }
|
||||
{ minEllipse[i] = fitEllipse( contours[i] ); }
|
||||
}
|
||||
|
||||
/// Draw contours + rotated rects + ellipses
|
||||
|
||||
@@ -23,10 +23,17 @@ void thresh_callback(int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int, char** argv )
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
src = imread( argv[1], IMREAD_COLOR );
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" );
|
||||
src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
|
||||
if( src.empty() )
|
||||
{
|
||||
cout << "Could not open or find the image!\n" << endl;
|
||||
cout << "Usage: " << argv[0] << " <Input image>" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// Convert image to gray and blur it
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
@@ -62,7 +69,7 @@ void thresh_callback(int, void* )
|
||||
/// Find the convex hull object for each contour
|
||||
vector<vector<Point> >hull( contours.size() );
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{ convexHull( Mat(contours[i]), hull[i], false ); }
|
||||
{ convexHull( contours[i], hull[i], false ); }
|
||||
|
||||
/// Draw contours + hull results
|
||||
Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 );
|
||||
|
||||
@@ -23,10 +23,18 @@ void thresh_callback(int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int, char** argv )
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
src = imread( argv[1], IMREAD_COLOR );
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" );
|
||||
src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
|
||||
|
||||
if( src.empty() )
|
||||
{
|
||||
cout << "Could not open or find the image!\n" << endl;
|
||||
cout << "usage: " << argv[0] << " <Input image>" << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/// Convert image to gray and blur it
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
@@ -51,12 +59,11 @@ void thresh_callback(int, void* )
|
||||
{
|
||||
Mat canny_output;
|
||||
vector<vector<Point> > contours;
|
||||
vector<Vec4i> hierarchy;
|
||||
|
||||
/// Detect edges using canny
|
||||
Canny( src_gray, canny_output, thresh, thresh*2, 3 );
|
||||
/// Find contours
|
||||
findContours( canny_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) );
|
||||
findContours( canny_output, contours, RETR_TREE, CHAIN_APPROX_SIMPLE );
|
||||
|
||||
/// Get the moments
|
||||
vector<Moments> mu(contours.size() );
|
||||
@@ -73,7 +80,7 @@ void thresh_callback(int, void* )
|
||||
for( size_t i = 0; i< contours.size(); i++ )
|
||||
{
|
||||
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
|
||||
drawContours( drawing, contours, (int)i, color, 2, 8, hierarchy, 0, Point() );
|
||||
drawContours( drawing, contours, (int)i, color, 2, LINE_8 );
|
||||
circle( drawing, mc[i], 4, color, -1, 8, 0 );
|
||||
}
|
||||
|
||||
@@ -87,7 +94,7 @@ void thresh_callback(int, void* )
|
||||
{
|
||||
printf(" * Contour[%d] - Area (M_00) = %.2f - Area OpenCV: %.2f - Length: %.2f \n", (int)i, mu[i].m00, contourArea(contours[i]), arcLength( contours[i], true ) );
|
||||
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
|
||||
drawContours( drawing, contours, (int)i, color, 2, 8, hierarchy, 0, Point() );
|
||||
drawContours( drawing, contours, (int)i, color, 2, LINE_8 );
|
||||
circle( drawing, mc[i], 4, color, -1, 8, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,10 +35,9 @@ int main( void )
|
||||
{ line( src, vert[j], vert[(j+1)%6], Scalar( 255 ), 3, 8 ); }
|
||||
|
||||
/// Get the contours
|
||||
vector<vector<Point> > contours; vector<Vec4i> hierarchy;
|
||||
Mat src_copy = src.clone();
|
||||
vector<vector<Point> > contours;
|
||||
|
||||
findContours( src_copy, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE);
|
||||
findContours( src, contours, RETR_TREE, CHAIN_APPROX_SIMPLE);
|
||||
|
||||
/// Calculate the distances to the contour
|
||||
Mat raw_dist( src.size(), CV_32FC1 );
|
||||
@@ -67,11 +66,8 @@ int main( void )
|
||||
}
|
||||
}
|
||||
|
||||
/// Create Window and show your results
|
||||
const char* source_window = "Source";
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
imshow( source_window, src );
|
||||
namedWindow( "Distance", WINDOW_AUTOSIZE );
|
||||
/// Show your results
|
||||
imshow( "Source", src );
|
||||
imshow( "Distance", drawing );
|
||||
|
||||
waitKey(0);
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include <iostream>
|
||||
@@ -36,10 +35,17 @@ void myHarris_function( int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int, char** argv )
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
src = imread( argv[1], IMREAD_COLOR );
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" );
|
||||
src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
|
||||
if ( src.empty() )
|
||||
{
|
||||
cout << "Could not open or find the image!\n" << endl;
|
||||
cout << "Usage: " << argv[0] << " <Input image>" << endl;
|
||||
return -1;
|
||||
}
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
|
||||
/// Set some parameters
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include <iostream>
|
||||
@@ -26,10 +25,17 @@ void cornerHarris_demo( int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int, char** argv )
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
src = imread( argv[1], IMREAD_COLOR );
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/building.jpg | input image}" );
|
||||
src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
|
||||
if ( src.empty() )
|
||||
{
|
||||
cout << "Could not open or find the image!\n" << endl;
|
||||
cout << "Usage: " << argv[0] << " <Input image>" << endl;
|
||||
return -1;
|
||||
}
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
|
||||
/// Create a window and a trackbar
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include <iostream>
|
||||
@@ -27,10 +26,17 @@ void goodFeaturesToTrack_Demo( int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int, char** argv )
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
src = imread( argv[1], IMREAD_COLOR );
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/pic3.png | input image}" );
|
||||
src = imread(parser.get<String>( "@input" ), IMREAD_COLOR);
|
||||
if ( src.empty() )
|
||||
{
|
||||
cout << "Could not open or find the image!\n" << endl;
|
||||
cout << "Usage: " << argv[0] << " <Input image>" << endl;
|
||||
return -1;
|
||||
}
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
|
||||
/// Create Window
|
||||
|
||||
@@ -27,10 +27,17 @@ void goodFeaturesToTrack_Demo( int, void* );
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( int, char** argv )
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
src = imread( argv[1], IMREAD_COLOR );
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/pic3.png | input image}" );
|
||||
src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
|
||||
if( src.empty() )
|
||||
{
|
||||
cout << "Could not open or find the image!\n" << endl;
|
||||
cout << "Usage: " << argv[0] << " <Input image>" << endl;
|
||||
return -1;
|
||||
}
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
|
||||
/// Create Window
|
||||
|
||||
@@ -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;
|
||||
@@ -4,8 +4,10 @@
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include <iostream>
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
@@ -30,16 +32,16 @@ void drawAxis(Mat& img, Point p, Point q, Scalar colour, const float scale = 0.2
|
||||
// Here we lengthen the arrow by a factor of scale
|
||||
q.x = (int) (p.x - scale * hypotenuse * cos(angle));
|
||||
q.y = (int) (p.y - scale * hypotenuse * sin(angle));
|
||||
line(img, p, q, colour, 1, CV_AA);
|
||||
line(img, p, q, colour, 1, LINE_AA);
|
||||
|
||||
// create the arrow hooks
|
||||
p.x = (int) (q.x + 9 * cos(angle + CV_PI / 4));
|
||||
p.y = (int) (q.y + 9 * sin(angle + CV_PI / 4));
|
||||
line(img, p, q, colour, 1, CV_AA);
|
||||
line(img, p, q, colour, 1, LINE_AA);
|
||||
|
||||
p.x = (int) (q.x + 9 * cos(angle - CV_PI / 4));
|
||||
p.y = (int) (q.y + 9 * sin(angle - CV_PI / 4));
|
||||
line(img, p, q, colour, 1, CV_AA);
|
||||
line(img, p, q, colour, 1, LINE_AA);
|
||||
//! [visualization1]
|
||||
}
|
||||
|
||||
@@ -59,7 +61,7 @@ double getOrientation(const vector<Point> &pts, Mat &img)
|
||||
}
|
||||
|
||||
//Perform PCA analysis
|
||||
PCA pca_analysis(data_pts, Mat(), CV_PCA_DATA_AS_ROW);
|
||||
PCA pca_analysis(data_pts, Mat(), PCA::DATA_AS_ROW);
|
||||
|
||||
//Store the center of the object
|
||||
Point cntr = Point(static_cast<int>(pca_analysis.mean.at<double>(0, 0)),
|
||||
@@ -98,15 +100,14 @@ int main(int argc, char** argv)
|
||||
{
|
||||
//! [pre-process]
|
||||
// Load image
|
||||
String imageName("../data/pca_test1.jpg"); // by default
|
||||
if (argc > 1)
|
||||
{
|
||||
imageName = argv[1];
|
||||
}
|
||||
Mat src = imread( imageName );
|
||||
CommandLineParser parser(argc, argv, "{@input | ../data/pca_test1.jpg | input image}");
|
||||
parser.about( "This program demonstrates how to use OpenCV PCA to extract the orienation of an object.\n" );
|
||||
parser.printMessage();
|
||||
|
||||
Mat src = imread(parser.get<String>("@input"));
|
||||
|
||||
// Check if image is loaded successfully
|
||||
if(!src.data || src.empty())
|
||||
if(src.empty())
|
||||
{
|
||||
cout << "Problem loading image!!!" << endl;
|
||||
return EXIT_FAILURE;
|
||||
@@ -120,14 +121,13 @@ int main(int argc, char** argv)
|
||||
|
||||
// Convert image to binary
|
||||
Mat bw;
|
||||
threshold(gray, bw, 50, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);
|
||||
threshold(gray, bw, 50, 255, THRESH_BINARY | THRESH_OTSU);
|
||||
//! [pre-process]
|
||||
|
||||
//! [contours]
|
||||
// Find all the contours in the thresholded image
|
||||
vector<Vec4i> hierarchy;
|
||||
vector<vector<Point> > contours;
|
||||
findContours(bw, contours, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);
|
||||
findContours(bw, contours, RETR_LIST, CHAIN_APPROX_NONE);
|
||||
|
||||
for (size_t i = 0; i < contours.size(); ++i)
|
||||
{
|
||||
@@ -137,7 +137,7 @@ int main(int argc, char** argv)
|
||||
if (area < 1e2 || 1e5 < area) continue;
|
||||
|
||||
// Draw each contour only for visualisation purposes
|
||||
drawContours(src, contours, static_cast<int>(i), Scalar(0, 0, 255), 2, 8, hierarchy, 0);
|
||||
drawContours(src, contours, static_cast<int>(i), Scalar(0, 0, 255), 2, LINE_8);
|
||||
// Find the orientation of each shape
|
||||
getOrientation(contours[i], src);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
#include "opencv2/objdetect.hpp"
|
||||
#include "opencv2/videoio.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace std;
|
||||
@@ -26,12 +24,12 @@ int main( int argc, const char** argv )
|
||||
"{face_cascade|../../data/haarcascades/haarcascade_frontalface_alt.xml|}"
|
||||
"{eyes_cascade|../../data/haarcascades/haarcascade_eye_tree_eyeglasses.xml|}");
|
||||
|
||||
cout << "\nThis program demonstrates using the cv::CascadeClassifier class to detect objects (Face + eyes) in a video stream.\n"
|
||||
"You can use Haar or LBP features.\n\n";
|
||||
parser.about( "\nThis program demonstrates using the cv::CascadeClassifier class to detect objects (Face + eyes) in a video stream.\n"
|
||||
"You can use Haar or LBP features.\n\n" );
|
||||
parser.printMessage();
|
||||
|
||||
face_cascade_name = parser.get<string>("face_cascade");
|
||||
eyes_cascade_name = parser.get<string>("eyes_cascade");
|
||||
face_cascade_name = parser.get<String>("face_cascade");
|
||||
eyes_cascade_name = parser.get<String>("eyes_cascade");
|
||||
VideoCapture capture;
|
||||
Mat frame;
|
||||
|
||||
@@ -54,8 +52,7 @@ int main( int argc, const char** argv )
|
||||
//-- 3. Apply the classifier to the frame
|
||||
detectAndDisplay( frame );
|
||||
|
||||
char c = (char)waitKey(10);
|
||||
if( c == 27 ) { break; } // escape
|
||||
if( waitKey(10) == 27 ) { break; } // escape
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -70,7 +67,7 @@ void detectAndDisplay( Mat frame )
|
||||
equalizeHist( frame_gray, frame_gray );
|
||||
|
||||
//-- Detect faces
|
||||
face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CASCADE_SCALE_IMAGE, Size(30, 30) );
|
||||
face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CASCADE_SCALE_IMAGE, Size(60, 60) );
|
||||
|
||||
for ( size_t i = 0; i < faces.size(); i++ )
|
||||
{
|
||||
|
||||
@@ -24,17 +24,21 @@
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
CV_Assert(argc == 2);
|
||||
Mat src;
|
||||
src = imread(argv[1], IMREAD_COLOR);
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/HappyFish.jpg | input image}" );
|
||||
Mat src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
|
||||
if ( src.empty() )
|
||||
{
|
||||
cout << "Could not open or find the image!\n" << endl;
|
||||
cout << "Usage: " << argv[0] << " <Input image>" << endl;
|
||||
return -1;
|
||||
}
|
||||
Mat gray = Mat( src.size(), CV_8UC1 );
|
||||
Mat color_boost = Mat( src.size(), CV_8UC3 );
|
||||
|
||||
Mat gray = Mat(src.size(),CV_8UC1);
|
||||
Mat color_boost = Mat(src.size(),CV_8UC3);
|
||||
|
||||
decolor(src,gray,color_boost);
|
||||
imshow("grayscale",gray);
|
||||
imshow("color_boost",color_boost);
|
||||
decolor( src, gray, color_boost );
|
||||
imshow( "grayscale", gray );
|
||||
imshow( "color_boost", color_boost );
|
||||
waitKey(0);
|
||||
}
|
||||
|
||||
@@ -14,32 +14,24 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include "opencv2/photo.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if(argc < 2)
|
||||
{
|
||||
cout << "usage: " << argv[0] << " <Input image> " << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int num,type;
|
||||
|
||||
Mat src = imread(argv[1], IMREAD_COLOR);
|
||||
CommandLineParser parser(argc, argv, "{@input | ../data/lena.jpg | input image}");
|
||||
Mat src = imread(parser.get<String>("@input"), IMREAD_COLOR);
|
||||
|
||||
if(src.empty())
|
||||
{
|
||||
cout << "Image not found" << endl;
|
||||
cout << "Could not open or find the image!\n" << endl;
|
||||
cout << "Usage: " << argv[0] << " <Input image>" << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,10 +32,10 @@ void KeyboardViz3d(const viz::KeyboardEvent &w, void *t);
|
||||
void DrawHistogram3D(Histo3DData &h)
|
||||
{
|
||||
//! [get_cube_size]
|
||||
int planSize = h.histogram.step1(0);
|
||||
int cols = h.histogram.step1(1);
|
||||
int rows = planSize / cols;
|
||||
int plans = h.histogram.total() / planSize;
|
||||
int planSize = (int)h.histogram.step1(0);
|
||||
int cols = (int)h.histogram.step1(1);
|
||||
int rows = (int)planSize / cols;
|
||||
int plans = (int)h.histogram.total() / planSize;
|
||||
h.fen3D->removeAllWidgets();
|
||||
h.nbWidget=0;
|
||||
if (h.nbWidget==0)
|
||||
|
||||
@@ -56,12 +56,12 @@ int main()
|
||||
{
|
||||
/* Rotation using rodrigues */
|
||||
/// Rotate around (1,1,1)
|
||||
rot_vec.at<float>(0,0) += CV_PI * 0.01f;
|
||||
rot_vec.at<float>(0,1) += CV_PI * 0.01f;
|
||||
rot_vec.at<float>(0,2) += CV_PI * 0.01f;
|
||||
rot_vec.at<float>(0,0) += (float)CV_PI * 0.01f;
|
||||
rot_vec.at<float>(0,1) += (float)CV_PI * 0.01f;
|
||||
rot_vec.at<float>(0,2) += (float)CV_PI * 0.01f;
|
||||
|
||||
/// Shift on (1,1,1)
|
||||
translation_phase += CV_PI * 0.01f;
|
||||
translation_phase += (float)CV_PI * 0.01f;
|
||||
translation = sin(translation_phase);
|
||||
|
||||
Mat rot_mat;
|
||||
|
||||
@@ -19,15 +19,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;
|
||||
|
||||
Reference in New Issue
Block a user