Update documentation and samples
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
// The "Square Detector" program.
|
||||
// It loads several images sequentially and tries to find squares in
|
||||
// each image
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/core/ocl.hpp"
|
||||
@@ -9,7 +6,6 @@
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
@@ -31,7 +27,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 UMat& image, vector<vector<Point> >& squares )
|
||||
{
|
||||
squares.clear();
|
||||
@@ -66,7 +61,7 @@ static void findSquares( const UMat& image, vector<vector<Point> >& squares )
|
||||
{
|
||||
// apply threshold if l!=0:
|
||||
// tgray(x,y) = gray(x,y) < (l+1)*255/N ? 255 : 0
|
||||
cv::threshold(gray0, gray, (l+1)*255/N, 255, THRESH_BINARY);
|
||||
threshold(gray0, gray, (l+1)*255/N, 255, THRESH_BINARY);
|
||||
}
|
||||
|
||||
// find contours and store them all as a list
|
||||
@@ -80,7 +75,7 @@ static void findSquares( const UMat& 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)
|
||||
@@ -89,8 +84,8 @@ static void findSquares( const UMat& 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;
|
||||
|
||||
@@ -150,7 +145,7 @@ int main(int argc, char** argv)
|
||||
|
||||
if(cmd.has("help"))
|
||||
{
|
||||
cout << "Usage : squares [options]" << endl;
|
||||
cout << "Usage : " << argv[0] << " [options]" << endl;
|
||||
cout << "Available options:" << endl;
|
||||
cmd.printMessage();
|
||||
return EXIT_SUCCESS;
|
||||
@@ -158,7 +153,7 @@ int main(int argc, char** argv)
|
||||
if (cmd.has("cpu_mode"))
|
||||
{
|
||||
ocl::setUseOpenCL(false);
|
||||
std::cout << "OpenCL was disabled" << std::endl;
|
||||
cout << "OpenCL was disabled" << endl;
|
||||
}
|
||||
|
||||
string inputName = cmd.get<string>("i");
|
||||
@@ -185,11 +180,11 @@ int main(int argc, char** argv)
|
||||
|
||||
do
|
||||
{
|
||||
int64 t_start = cv::getTickCount();
|
||||
int64 t_start = getTickCount();
|
||||
findSquares(image, squares);
|
||||
t_cpp += cv::getTickCount() - t_start;
|
||||
|
||||
t_start = cv::getTickCount();
|
||||
t_start = getTickCount();
|
||||
|
||||
cout << "run loop: " << j << endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user