Update documentation and samples

This commit is contained in:
Suleyman TURKMEN
2018-08-02 21:22:58 +03:00
parent 1c73e66edf
commit c61bc3a0cb
63 changed files with 365 additions and 303 deletions
+11 -16
View File
@@ -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;
}