Merge remote-tracking branch 'origin/2.4' into merge-2.4
Conflicts: CMakeLists.txt cmake/OpenCVDetectCUDA.cmake doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.rst modules/core/src/cmdparser.cpp modules/gpu/CMakeLists.txt modules/gpu/doc/introduction.rst modules/gpu/perf/perf_video.cpp modules/highgui/doc/reading_and_writing_images_and_video.rst modules/ocl/src/cl_context.cpp modules/video/include/opencv2/video/background_segm.hpp samples/cpp/image_sequence.cpp samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp samples/python/chessboard.py samples/python/cvutils.py samples/python/demhist.py samples/python/dft.py samples/python/distrans.py samples/python/edge.py samples/python/ffilldemo.py samples/python/fitellipse.py samples/python/houghlines.py samples/python/inpaint.py samples/python/logpolar.py samples/python/morphology.py samples/python/numpy_array.py samples/python/watershed.py
This commit is contained in:
@@ -7,50 +7,102 @@
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main(int, char** argv)
|
||||
namespace
|
||||
{
|
||||
Mat src, src_gray;
|
||||
// windows and trackbars name
|
||||
const std::string windowName = "Hough Circle Detection Demo";
|
||||
const std::string cannyThresholdTrackbarName = "Canny threshold";
|
||||
const std::string accumulatorThresholdTrackbarName = "Accumulator Threshold";
|
||||
const std::string usage = "Usage : tutorial_HoughCircle_Demo <path_to_input_image>\n";
|
||||
|
||||
/// Read the image
|
||||
src = imread( argv[1], 1 );
|
||||
// initial and max values of the parameters of interests.
|
||||
const int cannyThresholdInitialValue = 200;
|
||||
const int accumulatorThresholdInitialValue = 50;
|
||||
const int maxAccumulatorThreshold = 200;
|
||||
const int maxCannyThreshold = 255;
|
||||
|
||||
if( !src.data )
|
||||
{ return -1; }
|
||||
|
||||
/// Convert it to gray
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
|
||||
/// Reduce the noise so we avoid false circle detection
|
||||
GaussianBlur( src_gray, src_gray, Size(9, 9), 2, 2 );
|
||||
|
||||
vector<Vec3f> circles;
|
||||
|
||||
/// Apply the Hough Transform to find the circles
|
||||
HoughCircles( src_gray, circles, HOUGH_GRADIENT, 1, src_gray.rows/8, 200, 100, 0, 0 );
|
||||
|
||||
/// Draw the circles detected
|
||||
for( size_t i = 0; i < circles.size(); i++ )
|
||||
void HoughDetection(const Mat& src_gray, const Mat& src_display, int cannyThreshold, int accumulatorThreshold)
|
||||
{
|
||||
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
|
||||
int radius = cvRound(circles[i][2]);
|
||||
// circle center
|
||||
circle( src, center, 3, Scalar(0,255,0), -1, 8, 0 );
|
||||
// circle outline
|
||||
circle( src, center, radius, Scalar(0,0,255), 3, 8, 0 );
|
||||
// will hold the results of the detection
|
||||
std::vector<Vec3f> circles;
|
||||
// runs the actual detection
|
||||
HoughCircles( src_gray, circles, HOUGH_GRADIENT, 1, src_gray.rows/8, cannyThreshold, accumulatorThreshold, 0, 0 );
|
||||
|
||||
// clone the colour, input image for displaying purposes
|
||||
Mat display = src_display.clone();
|
||||
for( size_t i = 0; i < circles.size(); i++ )
|
||||
{
|
||||
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
|
||||
int radius = cvRound(circles[i][2]);
|
||||
// circle center
|
||||
circle( display, center, 3, Scalar(0,255,0), -1, 8, 0 );
|
||||
// circle outline
|
||||
circle( display, center, radius, Scalar(0,0,255), 3, 8, 0 );
|
||||
}
|
||||
|
||||
// shows the results
|
||||
imshow( windowName, display);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Mat src, src_gray;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
std::cerr<<"No input image specified\n";
|
||||
std::cout<<usage;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// Show your results
|
||||
namedWindow( "Hough Circle Transform Demo", WINDOW_AUTOSIZE );
|
||||
imshow( "Hough Circle Transform Demo", src );
|
||||
// Read the image
|
||||
src = imread( argv[1], 1 );
|
||||
|
||||
if( !src.data )
|
||||
{
|
||||
std::cerr<<"Invalid input image\n";
|
||||
std::cout<<usage;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Convert it to gray
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
|
||||
// Reduce the noise so we avoid false circle detection
|
||||
GaussianBlur( src_gray, src_gray, Size(9, 9), 2, 2 );
|
||||
|
||||
//declare and initialize both parameters that are subjects to change
|
||||
int cannyThreshold = cannyThresholdInitialValue;
|
||||
int accumulatorThreshold = accumulatorThresholdInitialValue;
|
||||
|
||||
// create the main window, and attach the trackbars
|
||||
namedWindow( windowName, WINDOW_AUTOSIZE );
|
||||
createTrackbar(cannyThresholdTrackbarName, windowName, &cannyThreshold,maxCannyThreshold);
|
||||
createTrackbar(accumulatorThresholdTrackbarName, windowName, &accumulatorThreshold, maxAccumulatorThreshold);
|
||||
|
||||
// infinite loop to display
|
||||
// and refresh the content of the output image
|
||||
// until the user presses q or Q
|
||||
int key = 0;
|
||||
while(key != 'q' && key != 'Q')
|
||||
{
|
||||
// those paramaters cannot be =0
|
||||
// so we must check here
|
||||
cannyThreshold = std::max(cannyThreshold, 1);
|
||||
accumulatorThreshold = std::max(accumulatorThreshold, 1);
|
||||
|
||||
//runs the detection, and update the display
|
||||
HoughDetection(src_gray, src, cannyThreshold, accumulatorThreshold);
|
||||
|
||||
// get user key
|
||||
key = waitKey(10);
|
||||
}
|
||||
|
||||
waitKey(0);
|
||||
return 0;
|
||||
}
|
||||
|
@@ -66,12 +66,14 @@ int main( int argc, char** argv )
|
||||
printf("-- Max dist : %f \n", max_dist );
|
||||
printf("-- Min dist : %f \n", min_dist );
|
||||
|
||||
//-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist )
|
||||
//-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist,
|
||||
//-- or a small arbitary value ( 0.02 ) in the event that min_dist is very
|
||||
//-- small)
|
||||
//-- PS.- radiusMatch can also be used here.
|
||||
std::vector< DMatch > good_matches;
|
||||
|
||||
for( int i = 0; i < descriptors_1.rows; i++ )
|
||||
{ if( matches[i].distance <= 2*min_dist )
|
||||
{ if( matches[i].distance <= max(2*min_dist, 0.02) )
|
||||
{ good_matches.push_back( matches[i]); }
|
||||
}
|
||||
|
||||
|
@@ -73,7 +73,7 @@ int main(int, char *argv[])
|
||||
BufferPSNR bufferPSNR;
|
||||
BufferMSSIM bufferMSSIM;
|
||||
|
||||
int TIMES;
|
||||
int TIMES = 10;
|
||||
stringstream sstr(argv[3]);
|
||||
sstr >> TIMES;
|
||||
double time, result = 0;
|
||||
|
Reference in New Issue
Block a user