Merge remote-tracking branch 'upstream/3.4' into merge-3.4
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
|
||||
#include <opencv2/core/utility.hpp>
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
@@ -32,44 +33,29 @@ static void on_trackbar(int, void*)
|
||||
imshow( "Connected Components", dst );
|
||||
}
|
||||
|
||||
static void help()
|
||||
{
|
||||
cout << "\n This program demonstrates connected components and use of the trackbar\n"
|
||||
"Usage: \n"
|
||||
" ./connected_components <image(../data/stuff.jpg as default)>\n"
|
||||
"The image is converted to grayscale and displayed, another image has a trackbar\n"
|
||||
"that controls thresholding and thereby the extracted contours which are drawn in color\n";
|
||||
}
|
||||
|
||||
const char* keys =
|
||||
{
|
||||
"{help h||}{@image|../data/stuff.jpg|image for converting to a grayscale}"
|
||||
};
|
||||
|
||||
int main( int argc, const char** argv )
|
||||
{
|
||||
CommandLineParser parser(argc, argv, keys);
|
||||
if (parser.has("help"))
|
||||
{
|
||||
help();
|
||||
return 0;
|
||||
}
|
||||
string inputImage = parser.get<string>(0);
|
||||
img = imread(inputImage.c_str(), 0);
|
||||
CommandLineParser parser(argc, argv, "{@image|../data/stuff.jpg|image for converting to a grayscale}");
|
||||
parser.about("\nThis program demonstrates connected components and use of the trackbar\n");
|
||||
parser.printMessage();
|
||||
cout << "\nThe image is converted to grayscale and displayed, another image has a trackbar\n"
|
||||
"that controls thresholding and thereby the extracted contours which are drawn in color\n";
|
||||
|
||||
String inputImage = parser.get<string>(0);
|
||||
img = imread(inputImage, IMREAD_GRAYSCALE);
|
||||
|
||||
if(img.empty())
|
||||
{
|
||||
cout << "Could not read input image file: " << inputImage << endl;
|
||||
return -1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
namedWindow( "Image", 1 );
|
||||
imshow( "Image", img );
|
||||
|
||||
namedWindow( "Connected Components", 1 );
|
||||
namedWindow( "Connected Components", WINDOW_AUTOSIZE);
|
||||
createTrackbar( "Threshold", "Connected Components", &threshval, 255, on_trackbar );
|
||||
on_trackbar(threshval, 0);
|
||||
|
||||
waitKey(0);
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
+11
-16
@@ -1,3 +1,4 @@
|
||||
|
||||
// The "Square Detector" program.
|
||||
// It loads several images sequentially and tries to find squares in
|
||||
// each image
|
||||
@@ -8,22 +9,18 @@
|
||||
#include "opencv2/highgui.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
static void help()
|
||||
static void help(const char* programName)
|
||||
{
|
||||
cout <<
|
||||
"\nA program using pyramid scaling, Canny, contours, contour simpification and\n"
|
||||
"memory storage (it's got it all folks) to find\n"
|
||||
"squares in a list of images pic1-6.png\n"
|
||||
"\nA program using pyramid scaling, Canny, contours and contour simplification\n"
|
||||
"to find squares in a list of images (pic1-6.png)\n"
|
||||
"Returns sequence of squares detected on the image.\n"
|
||||
"the sequence is stored in the specified memory storage\n"
|
||||
"Call:\n"
|
||||
"./squares [file_name (optional)]\n"
|
||||
"./" << programName << " [file_name (optional)]\n"
|
||||
"Using OpenCV version " << CV_VERSION << "\n" << endl;
|
||||
}
|
||||
|
||||
@@ -44,7 +41,6 @@ static double angle( Point pt1, Point pt2, Point pt0 )
|
||||
}
|
||||
|
||||
// returns sequence of squares detected on the image.
|
||||
// the sequence is stored in the specified memory storage
|
||||
static void findSquares( const Mat& image, vector<vector<Point> >& squares )
|
||||
{
|
||||
squares.clear();
|
||||
@@ -93,7 +89,7 @@ static void findSquares( const Mat& image, vector<vector<Point> >& squares )
|
||||
{
|
||||
// approximate contour with accuracy proportional
|
||||
// to the contour perimeter
|
||||
approxPolyDP(Mat(contours[i]), approx, arcLength(Mat(contours[i]), true)*0.02, true);
|
||||
approxPolyDP(contours[i], approx, arcLength(contours[i], true)*0.02, true);
|
||||
|
||||
// square contours should have 4 vertices after approximation
|
||||
// relatively large area (to filter out noisy contours)
|
||||
@@ -102,8 +98,8 @@ static void findSquares( const Mat& image, vector<vector<Point> >& squares )
|
||||
// area may be positive or negative - in accordance with the
|
||||
// contour orientation
|
||||
if( approx.size() == 4 &&
|
||||
fabs(contourArea(Mat(approx))) > 1000 &&
|
||||
isContourConvex(Mat(approx)) )
|
||||
fabs(contourArea(approx)) > 1000 &&
|
||||
isContourConvex(approx) )
|
||||
{
|
||||
double maxCosine = 0;
|
||||
|
||||
@@ -144,7 +140,7 @@ int main(int argc, char** argv)
|
||||
{
|
||||
static const char* names[] = { "../data/pic1.png", "../data/pic2.png", "../data/pic3.png",
|
||||
"../data/pic4.png", "../data/pic5.png", "../data/pic6.png", 0 };
|
||||
help();
|
||||
help(argv[0]);
|
||||
|
||||
if( argc > 1)
|
||||
{
|
||||
@@ -152,12 +148,11 @@ int main(int argc, char** argv)
|
||||
names[1] = "0";
|
||||
}
|
||||
|
||||
namedWindow( wndname, 1 );
|
||||
vector<vector<Point> > squares;
|
||||
|
||||
for( int i = 0; names[i] != 0; i++ )
|
||||
{
|
||||
Mat image = imread(names[i], 1);
|
||||
Mat image = imread(names[i], IMREAD_COLOR);
|
||||
if( image.empty() )
|
||||
{
|
||||
cout << "Couldn't load " << names[i] << endl;
|
||||
@@ -167,7 +162,7 @@ int main(int argc, char** argv)
|
||||
findSquares(image, squares);
|
||||
drawSquares(image, squares);
|
||||
|
||||
char c = (char)waitKey();
|
||||
int c = waitKey();
|
||||
if( c == 27 )
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,9 @@ int parseCmdArgs(int argc, char** argv);
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int retval = parseCmdArgs(argc, argv);
|
||||
if (retval) return -1;
|
||||
if (retval) return EXIT_FAILURE;
|
||||
|
||||
//![stitching]
|
||||
Mat pano;
|
||||
Ptr<Stitcher> stitcher = Stitcher::create(mode, try_use_gpu);
|
||||
Stitcher::Status status = stitcher->stitch(imgs, pano);
|
||||
@@ -29,12 +30,13 @@ int main(int argc, char* argv[])
|
||||
if (status != Stitcher::OK)
|
||||
{
|
||||
cout << "Can't stitch images, error code = " << int(status) << endl;
|
||||
return -1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
//![stitching]
|
||||
|
||||
imwrite(result_name, pano);
|
||||
cout << "stitching completed successfully\n" << result_name << " saved!";
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +65,7 @@ int parseCmdArgs(int argc, char** argv)
|
||||
if (argc == 1)
|
||||
{
|
||||
printUsage(argv);
|
||||
return -1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for (int i = 1; i < argc; ++i)
|
||||
@@ -71,7 +73,7 @@ int parseCmdArgs(int argc, char** argv)
|
||||
if (string(argv[i]) == "--help" || string(argv[i]) == "/?")
|
||||
{
|
||||
printUsage(argv);
|
||||
return -1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else if (string(argv[i]) == "--try_use_gpu")
|
||||
{
|
||||
@@ -82,7 +84,7 @@ int parseCmdArgs(int argc, char** argv)
|
||||
else
|
||||
{
|
||||
cout << "Bad --try_use_gpu flag value\n";
|
||||
return -1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -104,7 +106,7 @@ int parseCmdArgs(int argc, char** argv)
|
||||
else
|
||||
{
|
||||
cout << "Bad --mode flag value\n";
|
||||
return -1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -114,7 +116,7 @@ int parseCmdArgs(int argc, char** argv)
|
||||
if (img.empty())
|
||||
{
|
||||
cout << "Can't read image '" << argv[i] << "'\n";
|
||||
return -1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (divide_images)
|
||||
@@ -130,5 +132,5 @@ int parseCmdArgs(int argc, char** argv)
|
||||
imgs.push_back(img);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,45 +1,3 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
@@ -33,7 +33,7 @@ void Morphology_Operations( int, void* );
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
//![load]
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/LinuxLogo.jpg | input image}" );
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/baboon.jpg | input image}" );
|
||||
src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
|
||||
if (src.empty())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user