Merge remote-tracking branch 'upstream/3.4' into merge-3.4
OpenCV FFmpeg wrapper download links are preserved from ffmpeg/master branch
This commit is contained in:
@@ -12,9 +12,8 @@
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
Mat src; Mat src_gray;
|
||||
Mat src_gray;
|
||||
int thresh = 100;
|
||||
int max_thresh = 255;
|
||||
RNG rng(12345);
|
||||
|
||||
/// Function header
|
||||
@@ -25,34 +24,31 @@ void thresh_callback(int, void* );
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/// Load source image
|
||||
String imageName("../data/happyfish.jpg"); // by default
|
||||
if (argc > 1)
|
||||
{
|
||||
imageName = argv[1];
|
||||
}
|
||||
src = imread(imageName, IMREAD_COLOR);
|
||||
/// Load source image
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/HappyFish.jpg | input image}" );
|
||||
Mat src = imread( parser.get<String>( "@input" ) );
|
||||
if( src.empty() )
|
||||
{
|
||||
cout << "Could not open or find the image!\n" << endl;
|
||||
cout << "Usage: " << argv[0] << " <Input image>" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (src.empty())
|
||||
{
|
||||
cerr << "No image supplied ..." << endl;
|
||||
return -1;
|
||||
}
|
||||
/// Convert image to gray and blur it
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
blur( src_gray, src_gray, Size(3,3) );
|
||||
|
||||
/// Convert image to gray and blur it
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
blur( src_gray, src_gray, Size(3,3) );
|
||||
/// Create Window
|
||||
const char* source_window = "Source";
|
||||
namedWindow( source_window );
|
||||
imshow( source_window, src );
|
||||
|
||||
/// Create Window
|
||||
const char* source_window = "Source";
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
imshow( source_window, src );
|
||||
const int max_thresh = 255;
|
||||
createTrackbar( "Canny thresh:", source_window, &thresh, max_thresh, thresh_callback );
|
||||
thresh_callback( 0, 0 );
|
||||
|
||||
createTrackbar( " Canny thresh:", "Source", &thresh, max_thresh, thresh_callback );
|
||||
thresh_callback( 0, 0 );
|
||||
|
||||
waitKey(0);
|
||||
return(0);
|
||||
waitKey();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,24 +56,23 @@ int main( int argc, char** argv )
|
||||
*/
|
||||
void thresh_callback(int, void* )
|
||||
{
|
||||
Mat canny_output;
|
||||
vector<vector<Point> > contours;
|
||||
vector<Vec4i> hierarchy;
|
||||
/// Detect edges using Canny
|
||||
Mat canny_output;
|
||||
Canny( src_gray, canny_output, thresh, thresh*2 );
|
||||
|
||||
/// 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) );
|
||||
/// Find contours
|
||||
vector<vector<Point> > contours;
|
||||
vector<Vec4i> hierarchy;
|
||||
findContours( canny_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE );
|
||||
|
||||
/// Draw contours
|
||||
Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
|
||||
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() );
|
||||
}
|
||||
/// Draw contours
|
||||
Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
|
||||
for( size_t i = 0; i< contours.size(); i++ )
|
||||
{
|
||||
Scalar color = Scalar( rng.uniform(0, 256), rng.uniform(0,256), rng.uniform(0,256) );
|
||||
drawContours( drawing, contours, (int)i, color, 2, LINE_8, hierarchy, 0 );
|
||||
}
|
||||
|
||||
/// Show in a window
|
||||
namedWindow( "Contours", WINDOW_AUTOSIZE );
|
||||
imshow( "Contours", drawing );
|
||||
/// Show in a window
|
||||
imshow( "Contours", drawing );
|
||||
}
|
||||
|
||||
@@ -12,9 +12,8 @@
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
Mat src; Mat src_gray;
|
||||
Mat src_gray;
|
||||
int thresh = 100;
|
||||
int max_thresh = 255;
|
||||
RNG rng(12345);
|
||||
|
||||
/// Function header
|
||||
@@ -25,42 +24,37 @@ void thresh_callback(int, void* );
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
//![setup]
|
||||
/// Load source image
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" );
|
||||
src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
|
||||
if( src.empty() )
|
||||
//! [setup]
|
||||
/// Load source image
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" );
|
||||
Mat src = imread( parser.get<String>( "@input" ) );
|
||||
if( src.empty() )
|
||||
{
|
||||
cout << "Could not open or find the image!\n" << endl;
|
||||
cout << "usage: " << argv[0] << " <Input image>" << endl;
|
||||
return -1;
|
||||
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 );
|
||||
blur( src_gray, src_gray, Size(3,3) );
|
||||
//![setup]
|
||||
/// Convert image to gray and blur it
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
blur( src_gray, src_gray, Size(3,3) );
|
||||
//! [setup]
|
||||
|
||||
//![createWindow]
|
||||
/// Create Window
|
||||
const char* source_window = "Source";
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
imshow( source_window, src );
|
||||
//![createWindow]
|
||||
//! [createWindow]
|
||||
/// Create Window
|
||||
const char* source_window = "Source";
|
||||
namedWindow( source_window );
|
||||
imshow( source_window, src );
|
||||
//! [createWindow]
|
||||
|
||||
//![taskbar]
|
||||
createTrackbar( " Threshold:", "Source", &thresh, max_thresh, thresh_callback );
|
||||
//![taskbar]
|
||||
//! [trackbar]
|
||||
const int max_thresh = 255;
|
||||
createTrackbar( "Canny thresh:", source_window, &thresh, max_thresh, thresh_callback );
|
||||
thresh_callback( 0, 0 );
|
||||
//! [trackbar]
|
||||
|
||||
//![callback00]
|
||||
thresh_callback( 0, 0 );
|
||||
//![callback00]
|
||||
|
||||
//![waitForIt]
|
||||
waitKey(0);
|
||||
//![waitForIt]
|
||||
|
||||
return(0);
|
||||
waitKey();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,53 +62,50 @@ int main( int argc, char** argv )
|
||||
*/
|
||||
void thresh_callback(int, void* )
|
||||
{
|
||||
Mat threshold_output;
|
||||
vector<vector<Point> > contours;
|
||||
vector<Vec4i> hierarchy;
|
||||
//! [Canny]
|
||||
/// Detect edges using Canny
|
||||
Mat canny_output;
|
||||
Canny( src_gray, canny_output, thresh, thresh*2 );
|
||||
//! [Canny]
|
||||
|
||||
//![threshold]
|
||||
/// Detect edges using Threshold
|
||||
threshold( src_gray, threshold_output, thresh, 255, THRESH_BINARY );
|
||||
//![threshold]
|
||||
//! [findContours]
|
||||
/// Find contours
|
||||
vector<vector<Point> > contours;
|
||||
findContours( canny_output, contours, RETR_TREE, CHAIN_APPROX_SIMPLE );
|
||||
//! [findContours]
|
||||
|
||||
//![findContours]
|
||||
/// Find contours
|
||||
findContours( threshold_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) );
|
||||
//![findContours]
|
||||
//! [allthework]
|
||||
/// Approximate contours to polygons + get bounding rects and circles
|
||||
vector<vector<Point> > contours_poly( contours.size() );
|
||||
vector<Rect> boundRect( contours.size() );
|
||||
vector<Point2f>centers( contours.size() );
|
||||
vector<float>radius( contours.size() );
|
||||
|
||||
/// Approximate contours to polygons + get bounding rects and circles
|
||||
vector<vector<Point> > contours_poly( contours.size() );
|
||||
vector<Rect> boundRect( contours.size() );
|
||||
vector<Point2f>center( contours.size() );
|
||||
vector<float>radius( contours.size() );
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{
|
||||
approxPolyDP( contours[i], contours_poly[i], 3, true );
|
||||
boundRect[i] = boundingRect( contours_poly[i] );
|
||||
minEnclosingCircle( contours_poly[i], centers[i], radius[i] );
|
||||
}
|
||||
//! [allthework]
|
||||
|
||||
//![allthework]
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{
|
||||
approxPolyDP( contours[i], contours_poly[i], 3, true );
|
||||
boundRect[i] = boundingRect( contours_poly[i] );
|
||||
minEnclosingCircle( contours_poly[i], center[i], radius[i] );
|
||||
}
|
||||
//![allthework]
|
||||
//! [zeroMat]
|
||||
Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
|
||||
//! [zeroMat]
|
||||
|
||||
//![zeroMat]
|
||||
/// Draw polygonal contour + bonding rects + circles
|
||||
Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 );
|
||||
//![zeroMat]
|
||||
//! [forContour]
|
||||
/// Draw polygonal contour + bonding rects + circles
|
||||
for( size_t i = 0; i< contours.size(); i++ )
|
||||
{
|
||||
Scalar color = Scalar( rng.uniform(0, 256), rng.uniform(0,256), rng.uniform(0,256) );
|
||||
drawContours( drawing, contours_poly, (int)i, color );
|
||||
rectangle( drawing, boundRect[i].tl(), boundRect[i].br(), color, 2 );
|
||||
circle( drawing, centers[i], (int)radius[i], color, 2 );
|
||||
}
|
||||
//! [forContour]
|
||||
|
||||
//![forContour]
|
||||
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_poly, (int)i, color, 1, 8, vector<Vec4i>(), 0, Point() );
|
||||
rectangle( drawing, boundRect[i].tl(), boundRect[i].br(), color, 2, 8, 0 );
|
||||
circle( drawing, center[i], (int)radius[i], color, 2, 8, 0 );
|
||||
}
|
||||
//![forContour]
|
||||
|
||||
//![showDrawings]
|
||||
/// Show in a window
|
||||
namedWindow( "Contours", WINDOW_AUTOSIZE );
|
||||
imshow( "Contours", drawing );
|
||||
//![showDrawings]
|
||||
//! [showDrawings]
|
||||
/// Show in a window
|
||||
imshow( "Contours", drawing );
|
||||
//! [showDrawings]
|
||||
}
|
||||
|
||||
@@ -12,9 +12,8 @@
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
Mat src; Mat src_gray;
|
||||
Mat src_gray;
|
||||
int thresh = 100;
|
||||
int max_thresh = 255;
|
||||
RNG rng(12345);
|
||||
|
||||
/// Function header
|
||||
@@ -25,30 +24,31 @@ void thresh_callback(int, void* );
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" );
|
||||
src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
|
||||
if( src.empty() )
|
||||
/// Load source image and convert it to gray
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" );
|
||||
Mat src = imread( parser.get<String>( "@input" ) );
|
||||
if( src.empty() )
|
||||
{
|
||||
cout << "Could not open or find the image!\n" << endl;
|
||||
cout << "Usage: " << argv[0] << " <Input image>" << endl;
|
||||
return -1;
|
||||
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 );
|
||||
blur( src_gray, src_gray, Size(3,3) );
|
||||
/// Convert image to gray and blur it
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
blur( src_gray, src_gray, Size(3,3) );
|
||||
|
||||
/// Create Window
|
||||
const char* source_window = "Source";
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
imshow( source_window, src );
|
||||
/// Create Window
|
||||
const char* source_window = "Source";
|
||||
namedWindow( source_window );
|
||||
imshow( source_window, src );
|
||||
|
||||
createTrackbar( " Threshold:", "Source", &thresh, max_thresh, thresh_callback );
|
||||
thresh_callback( 0, 0 );
|
||||
const int max_thresh = 255;
|
||||
createTrackbar( "Canny thresh:", source_window, &thresh, max_thresh, thresh_callback );
|
||||
thresh_callback( 0, 0 );
|
||||
|
||||
waitKey(0);
|
||||
return(0);
|
||||
waitKey();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,41 +56,43 @@ int main( int argc, char** argv )
|
||||
*/
|
||||
void thresh_callback(int, void* )
|
||||
{
|
||||
Mat threshold_output;
|
||||
vector<vector<Point> > contours;
|
||||
vector<Vec4i> hierarchy;
|
||||
/// Detect edges using Canny
|
||||
Mat canny_output;
|
||||
Canny( src_gray, canny_output, thresh, thresh*2 );
|
||||
/// Find contours
|
||||
vector<vector<Point> > contours;
|
||||
findContours( canny_output, contours, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) );
|
||||
|
||||
/// Detect edges using Threshold
|
||||
threshold( src_gray, threshold_output, thresh, 255, THRESH_BINARY );
|
||||
/// Find contours
|
||||
findContours( threshold_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) );
|
||||
/// Find the rotated rectangles and ellipses for each contour
|
||||
vector<RotatedRect> minRect( contours.size() );
|
||||
vector<RotatedRect> minEllipse( contours.size() );
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{
|
||||
minRect[i] = minAreaRect( contours[i] );
|
||||
if( contours[i].size() > 5 )
|
||||
{
|
||||
minEllipse[i] = fitEllipse( contours[i] );
|
||||
}
|
||||
}
|
||||
|
||||
/// Find the rotated rectangles and ellipses for each contour
|
||||
vector<RotatedRect> minRect( contours.size() );
|
||||
vector<RotatedRect> minEllipse( contours.size() );
|
||||
/// Draw contours + rotated rects + ellipses
|
||||
Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
|
||||
for( size_t i = 0; i< contours.size(); i++ )
|
||||
{
|
||||
Scalar color = Scalar( rng.uniform(0, 256), rng.uniform(0,256), rng.uniform(0,256) );
|
||||
// contour
|
||||
drawContours( drawing, contours, (int)i, color );
|
||||
// ellipse
|
||||
ellipse( drawing, minEllipse[i], color, 2 );
|
||||
// rotated rectangle
|
||||
Point2f rect_points[4];
|
||||
minRect[i].points( rect_points );
|
||||
for ( int j = 0; j < 4; j++ )
|
||||
{
|
||||
line( drawing, rect_points[j], rect_points[(j+1)%4], color );
|
||||
}
|
||||
}
|
||||
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{ minRect[i] = minAreaRect( contours[i] );
|
||||
if( contours[i].size() > 5 )
|
||||
{ minEllipse[i] = fitEllipse( contours[i] ); }
|
||||
}
|
||||
|
||||
/// Draw contours + rotated rects + ellipses
|
||||
Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 );
|
||||
for( size_t i = 0; i< contours.size(); i++ )
|
||||
{
|
||||
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
|
||||
// contour
|
||||
drawContours( drawing, contours, (int)i, color, 1, 8, vector<Vec4i>(), 0, Point() );
|
||||
// ellipse
|
||||
ellipse( drawing, minEllipse[i], color, 2, 8 );
|
||||
// rotated rectangle
|
||||
Point2f rect_points[4]; minRect[i].points( rect_points );
|
||||
for( int j = 0; j < 4; j++ )
|
||||
line( drawing, rect_points[j], rect_points[(j+1)%4], color, 1, 8 );
|
||||
}
|
||||
|
||||
/// Show in a window
|
||||
namedWindow( "Contours", WINDOW_AUTOSIZE );
|
||||
imshow( "Contours", drawing );
|
||||
/// Show in a window
|
||||
imshow( "Contours", drawing );
|
||||
}
|
||||
|
||||
@@ -12,9 +12,8 @@
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
Mat src; Mat src_gray;
|
||||
Mat src_gray;
|
||||
int thresh = 100;
|
||||
int max_thresh = 255;
|
||||
RNG rng(12345);
|
||||
|
||||
/// Function header
|
||||
@@ -25,30 +24,31 @@ void thresh_callback(int, void* );
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
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;
|
||||
}
|
||||
/// Load source image and convert it to gray
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" );
|
||||
Mat src = imread( parser.get<String>( "@input" ) );
|
||||
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 );
|
||||
blur( src_gray, src_gray, Size(3,3) );
|
||||
/// Convert image to gray and blur it
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
blur( src_gray, src_gray, Size(3,3) );
|
||||
|
||||
/// Create Window
|
||||
const char* source_window = "Source";
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
imshow( source_window, src );
|
||||
/// Create Window
|
||||
const char* source_window = "Source";
|
||||
namedWindow( source_window );
|
||||
imshow( source_window, src );
|
||||
|
||||
createTrackbar( " Threshold:", "Source", &thresh, max_thresh, thresh_callback );
|
||||
thresh_callback( 0, 0 );
|
||||
const int max_thresh = 255;
|
||||
createTrackbar( "Canny thresh:", source_window, &thresh, max_thresh, thresh_callback );
|
||||
thresh_callback( 0, 0 );
|
||||
|
||||
waitKey(0);
|
||||
return(0);
|
||||
waitKey();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,31 +56,30 @@ int main( int argc, char** argv )
|
||||
*/
|
||||
void thresh_callback(int, void* )
|
||||
{
|
||||
Mat threshold_output;
|
||||
vector<vector<Point> > contours;
|
||||
vector<Vec4i> hierarchy;
|
||||
/// Detect edges using Canny
|
||||
Mat canny_output;
|
||||
Canny( src_gray, canny_output, thresh, thresh*2 );
|
||||
|
||||
/// Detect edges using Threshold
|
||||
threshold( src_gray, threshold_output, thresh, 255, THRESH_BINARY );
|
||||
/// Find contours
|
||||
vector<vector<Point> > contours;
|
||||
findContours( canny_output, contours, RETR_TREE, CHAIN_APPROX_SIMPLE );
|
||||
|
||||
/// Find contours
|
||||
findContours( threshold_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) );
|
||||
/// Find the convex hull object for each contour
|
||||
vector<vector<Point> >hull( contours.size() );
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{
|
||||
convexHull( contours[i], hull[i] );
|
||||
}
|
||||
|
||||
/// Find the convex hull object for each contour
|
||||
vector<vector<Point> >hull( contours.size() );
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{ convexHull( contours[i], hull[i], false ); }
|
||||
/// Draw contours + hull results
|
||||
Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
|
||||
for( size_t i = 0; i< contours.size(); i++ )
|
||||
{
|
||||
Scalar color = Scalar( rng.uniform(0, 256), rng.uniform(0,256), rng.uniform(0,256) );
|
||||
drawContours( drawing, contours, (int)i, color );
|
||||
drawContours( drawing, hull, (int)i, color );
|
||||
}
|
||||
|
||||
/// Draw contours + hull results
|
||||
Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 );
|
||||
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, 1, 8, vector<Vec4i>(), 0, Point() );
|
||||
drawContours( drawing, hull, (int)i, color, 1, 8, vector<Vec4i>(), 0, Point() );
|
||||
}
|
||||
|
||||
/// Show in a window
|
||||
namedWindow( "Hull demo", WINDOW_AUTOSIZE );
|
||||
imshow( "Hull demo", drawing );
|
||||
/// Show in a window
|
||||
imshow( "Hull demo", drawing );
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
Mat src; Mat src_gray;
|
||||
Mat src_gray;
|
||||
int thresh = 100;
|
||||
int max_thresh = 255;
|
||||
RNG rng(12345);
|
||||
|
||||
/// Function header
|
||||
@@ -25,31 +25,32 @@ void thresh_callback(int, void* );
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/// Load source image and convert it to gray
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" );
|
||||
src = imread( parser.get<String>( "@input" ), IMREAD_COLOR );
|
||||
/// Load source image
|
||||
CommandLineParser parser( argc, argv, "{@input | ../data/stuff.jpg | input image}" );
|
||||
Mat src = imread( parser.get<String>( "@input" ) );
|
||||
|
||||
if( src.empty() )
|
||||
{
|
||||
cout << "Could not open or find the image!\n" << endl;
|
||||
cout << "usage: " << argv[0] << " <Input image>" << endl;
|
||||
exit(0);
|
||||
}
|
||||
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 );
|
||||
blur( src_gray, src_gray, Size(3,3) );
|
||||
/// Convert image to gray and blur it
|
||||
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
||||
blur( src_gray, src_gray, Size(3,3) );
|
||||
|
||||
/// Create Window
|
||||
const char* source_window = "Source";
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
imshow( source_window, src );
|
||||
/// Create Window
|
||||
const char* source_window = "Source";
|
||||
namedWindow( source_window );
|
||||
imshow( source_window, src );
|
||||
|
||||
createTrackbar( " Canny thresh:", "Source", &thresh, max_thresh, thresh_callback );
|
||||
thresh_callback( 0, 0 );
|
||||
const int max_thresh = 255;
|
||||
createTrackbar( "Canny thresh:", source_window, &thresh, max_thresh, thresh_callback );
|
||||
thresh_callback( 0, 0 );
|
||||
|
||||
waitKey(0);
|
||||
return(0);
|
||||
waitKey();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,44 +58,47 @@ int main( int argc, char** argv )
|
||||
*/
|
||||
void thresh_callback(int, void* )
|
||||
{
|
||||
Mat canny_output;
|
||||
vector<vector<Point> > contours;
|
||||
/// Detect edges using canny
|
||||
Mat canny_output;
|
||||
Canny( src_gray, canny_output, thresh, thresh*2, 3 );
|
||||
/// Find contours
|
||||
vector<vector<Point> > contours;
|
||||
findContours( canny_output, contours, RETR_TREE, CHAIN_APPROX_SIMPLE );
|
||||
|
||||
/// Detect edges using canny
|
||||
Canny( src_gray, canny_output, thresh, thresh*2, 3 );
|
||||
/// Find contours
|
||||
findContours( canny_output, contours, RETR_TREE, CHAIN_APPROX_SIMPLE );
|
||||
/// Get the moments
|
||||
vector<Moments> mu(contours.size() );
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{
|
||||
mu[i] = moments( contours[i] );
|
||||
}
|
||||
|
||||
/// Get the moments
|
||||
vector<Moments> mu(contours.size() );
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{ mu[i] = moments( contours[i], false ); }
|
||||
/// Get the mass centers
|
||||
vector<Point2f> mc( contours.size() );
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{
|
||||
//add 1e-5 to avoid division by zero
|
||||
mc[i] = Point2f( static_cast<float>(mu[i].m10 / (mu[i].m00 + 1e-5)),
|
||||
static_cast<float>(mu[i].m01 / (mu[i].m00 + 1e-5)) );
|
||||
cout << "mc[" << i << "]=" << mc[i] << endl;
|
||||
}
|
||||
|
||||
/// Get the mass centers:
|
||||
vector<Point2f> mc( contours.size() );
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{ mc[i] = Point2f( static_cast<float>(mu[i].m10/mu[i].m00) , static_cast<float>(mu[i].m01/mu[i].m00) ); }
|
||||
/// Draw contours
|
||||
Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
|
||||
for( size_t i = 0; i< contours.size(); i++ )
|
||||
{
|
||||
Scalar color = Scalar( rng.uniform(0, 256), rng.uniform(0,256), rng.uniform(0,256) );
|
||||
drawContours( drawing, contours, (int)i, color, 2 );
|
||||
circle( drawing, mc[i], 4, color, -1 );
|
||||
}
|
||||
|
||||
/// Draw contours
|
||||
Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
|
||||
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, LINE_8 );
|
||||
circle( drawing, mc[i], 4, color, -1, 8, 0 );
|
||||
}
|
||||
/// Show in a window
|
||||
imshow( "Contours", drawing );
|
||||
|
||||
/// Show in a window
|
||||
namedWindow( "Contours", WINDOW_AUTOSIZE );
|
||||
imshow( "Contours", drawing );
|
||||
|
||||
/// Calculate the area with the moments 00 and compare with the result of the OpenCV function
|
||||
printf("\t Info: Area and Contour Length \n");
|
||||
for( size_t i = 0; i< contours.size(); i++ )
|
||||
{
|
||||
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, LINE_8 );
|
||||
circle( drawing, mc[i], 4, color, -1, 8, 0 );
|
||||
}
|
||||
/// Calculate the area with the moments 00 and compare with the result of the OpenCV function
|
||||
cout << "\t Info: Area and Contour Length \n";
|
||||
for( size_t i = 0; i < contours.size(); i++ )
|
||||
{
|
||||
cout << " * Contour[" << i << "] - Area (M_00) = " << std::fixed << std::setprecision(2) << mu[i].m00
|
||||
<< " - Area OpenCV: " << contourArea(contours[i]) << " - Length: " << arcLength( contours[i], true ) << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,60 +16,71 @@ using namespace std;
|
||||
*/
|
||||
int main( void )
|
||||
{
|
||||
/// Create an image
|
||||
const int r = 100;
|
||||
Mat src = Mat::zeros( Size( 4*r, 4*r ), CV_8UC1 );
|
||||
/// Create an image
|
||||
const int r = 100;
|
||||
Mat src = Mat::zeros( Size( 4*r, 4*r ), CV_8U );
|
||||
|
||||
/// Create a sequence of points to make a contour:
|
||||
vector<Point2f> vert(6);
|
||||
/// Create a sequence of points to make a contour
|
||||
vector<Point2f> vert(6);
|
||||
vert[0] = Point( 3*r/2, static_cast<int>(1.34*r) );
|
||||
vert[1] = Point( 1*r, 2*r );
|
||||
vert[2] = Point( 3*r/2, static_cast<int>(2.866*r) );
|
||||
vert[3] = Point( 5*r/2, static_cast<int>(2.866*r) );
|
||||
vert[4] = Point( 3*r, 2*r );
|
||||
vert[5] = Point( 5*r/2, static_cast<int>(1.34*r) );
|
||||
|
||||
vert[0] = Point( 3*r/2, static_cast<int>(1.34*r) );
|
||||
vert[1] = Point( 1*r, 2*r );
|
||||
vert[2] = Point( 3*r/2, static_cast<int>(2.866*r) );
|
||||
vert[3] = Point( 5*r/2, static_cast<int>(2.866*r) );
|
||||
vert[4] = Point( 3*r, 2*r );
|
||||
vert[5] = Point( 5*r/2, static_cast<int>(1.34*r) );
|
||||
/// Draw it in src
|
||||
for( int i = 0; i < 6; i++ )
|
||||
{
|
||||
line( src, vert[i], vert[(i+1)%6], Scalar( 255 ), 3 );
|
||||
}
|
||||
|
||||
/// Draw it in src
|
||||
for( int j = 0; j < 6; j++ )
|
||||
{ line( src, vert[j], vert[(j+1)%6], Scalar( 255 ), 3, 8 ); }
|
||||
/// Get the contours
|
||||
vector<vector<Point> > contours;
|
||||
findContours( src, contours, RETR_TREE, CHAIN_APPROX_SIMPLE);
|
||||
|
||||
/// Get the contours
|
||||
vector<vector<Point> > contours;
|
||||
/// Calculate the distances to the contour
|
||||
Mat raw_dist( src.size(), CV_32F );
|
||||
for( int i = 0; i < src.rows; i++ )
|
||||
{
|
||||
for( int j = 0; j < src.cols; j++ )
|
||||
{
|
||||
raw_dist.at<float>(i,j) = (float)pointPolygonTest( contours[0], Point2f((float)j, (float)i), true );
|
||||
}
|
||||
}
|
||||
|
||||
findContours( src, contours, RETR_TREE, CHAIN_APPROX_SIMPLE);
|
||||
double minVal, maxVal;
|
||||
minMaxLoc( raw_dist, &minVal, &maxVal );
|
||||
minVal = abs(minVal);
|
||||
maxVal = abs(maxVal);
|
||||
|
||||
/// Calculate the distances to the contour
|
||||
Mat raw_dist( src.size(), CV_32FC1 );
|
||||
|
||||
for( int j = 0; j < src.rows; j++ )
|
||||
{ for( int i = 0; i < src.cols; i++ )
|
||||
{ raw_dist.at<float>(j,i) = (float)pointPolygonTest( contours[0], Point2f((float)i,(float)j), true ); }
|
||||
}
|
||||
|
||||
double minVal; double maxVal;
|
||||
minMaxLoc( raw_dist, &minVal, &maxVal, 0, 0, Mat() );
|
||||
minVal = abs(minVal); maxVal = abs(maxVal);
|
||||
|
||||
/// Depicting the distances graphically
|
||||
Mat drawing = Mat::zeros( src.size(), CV_8UC3 );
|
||||
|
||||
for( int j = 0; j < src.rows; j++ )
|
||||
{ for( int i = 0; i < src.cols; i++ )
|
||||
{
|
||||
if( raw_dist.at<float>(j,i) < 0 )
|
||||
{ drawing.at<Vec3b>(j,i)[0] = (uchar)(255 - abs(raw_dist.at<float>(j,i))*255/minVal); }
|
||||
else if( raw_dist.at<float>(j,i) > 0 )
|
||||
{ drawing.at<Vec3b>(j,i)[2] = (uchar)(255 - raw_dist.at<float>(j,i)*255/maxVal); }
|
||||
/// Depicting the distances graphically
|
||||
Mat drawing = Mat::zeros( src.size(), CV_8UC3 );
|
||||
for( int i = 0; i < src.rows; i++ )
|
||||
{
|
||||
for( int j = 0; j < src.cols; j++ )
|
||||
{
|
||||
if( raw_dist.at<float>(i,j) < 0 )
|
||||
{
|
||||
drawing.at<Vec3b>(i,j)[0] = (uchar)(255 - abs(raw_dist.at<float>(i,j)) * 255 / minVal);
|
||||
}
|
||||
else if( raw_dist.at<float>(i,j) > 0 )
|
||||
{
|
||||
drawing.at<Vec3b>(i,j)[2] = (uchar)(255 - raw_dist.at<float>(i,j) * 255 / maxVal);
|
||||
}
|
||||
else
|
||||
{ drawing.at<Vec3b>(j,i)[0] = 255; drawing.at<Vec3b>(j,i)[1] = 255; drawing.at<Vec3b>(j,i)[2] = 255; }
|
||||
}
|
||||
}
|
||||
{
|
||||
drawing.at<Vec3b>(i,j)[0] = 255;
|
||||
drawing.at<Vec3b>(i,j)[1] = 255;
|
||||
drawing.at<Vec3b>(i,j)[2] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Show your results
|
||||
imshow( "Source", src );
|
||||
imshow( "Distance", drawing );
|
||||
/// Show your results
|
||||
imshow( "Source", src );
|
||||
imshow( "Distance", drawing );
|
||||
|
||||
waitKey(0);
|
||||
return(0);
|
||||
waitKey();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
@@ -11,48 +11,63 @@ using namespace cv;
|
||||
void detectAndDisplay( Mat frame );
|
||||
|
||||
/** Global variables */
|
||||
String face_cascade_name, eyes_cascade_name;
|
||||
CascadeClassifier face_cascade;
|
||||
CascadeClassifier eyes_cascade;
|
||||
String window_name = "Capture - Face detection";
|
||||
|
||||
/** @function main */
|
||||
int main( int argc, const char** argv )
|
||||
{
|
||||
CommandLineParser parser(argc, argv,
|
||||
"{help h||}"
|
||||
"{face_cascade|../../data/haarcascades/haarcascade_frontalface_alt.xml|}"
|
||||
"{eyes_cascade|../../data/haarcascades/haarcascade_eye_tree_eyeglasses.xml|}");
|
||||
"{help h||}"
|
||||
"{face_cascade|../../data/haarcascades/haarcascade_frontalface_alt.xml|Path to face cascade.}"
|
||||
"{eyes_cascade|../../data/haarcascades/haarcascade_eye_tree_eyeglasses.xml|Path to eyes cascade.}"
|
||||
"{camera|0|Camera device number.}");
|
||||
|
||||
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");
|
||||
VideoCapture capture;
|
||||
Mat frame;
|
||||
String face_cascade_name = parser.get<String>("face_cascade");
|
||||
String eyes_cascade_name = parser.get<String>("eyes_cascade");
|
||||
|
||||
//-- 1. Load the cascades
|
||||
if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading face cascade\n"); return -1; };
|
||||
if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading eyes cascade\n"); return -1; };
|
||||
if( !face_cascade.load( face_cascade_name ) )
|
||||
{
|
||||
cout << "--(!)Error loading face cascade\n";
|
||||
return -1;
|
||||
};
|
||||
if( !eyes_cascade.load( eyes_cascade_name ) )
|
||||
{
|
||||
cout << "--(!)Error loading eyes cascade\n";
|
||||
return -1;
|
||||
};
|
||||
|
||||
int camera_device = parser.get<int>("camera");
|
||||
VideoCapture capture;
|
||||
//-- 2. Read the video stream
|
||||
capture.open( 0 );
|
||||
if ( ! capture.isOpened() ) { printf("--(!)Error opening video capture\n"); return -1; }
|
||||
capture.open( camera_device );
|
||||
if ( ! capture.isOpened() )
|
||||
{
|
||||
cout << "--(!)Error opening video capture\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
Mat frame;
|
||||
while ( capture.read(frame) )
|
||||
{
|
||||
if( frame.empty() )
|
||||
{
|
||||
printf(" --(!) No captured frame -- Break!");
|
||||
cout << "--(!) No captured frame -- Break!\n";
|
||||
break;
|
||||
}
|
||||
|
||||
//-- 3. Apply the classifier to the frame
|
||||
detectAndDisplay( frame );
|
||||
|
||||
if( waitKey(10) == 27 ) { break; } // escape
|
||||
if( waitKey(10) == 27 )
|
||||
{
|
||||
break; // escape
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -60,33 +75,33 @@ int main( int argc, const char** argv )
|
||||
/** @function detectAndDisplay */
|
||||
void detectAndDisplay( Mat frame )
|
||||
{
|
||||
std::vector<Rect> faces;
|
||||
Mat frame_gray;
|
||||
|
||||
cvtColor( frame, frame_gray, COLOR_BGR2GRAY );
|
||||
equalizeHist( frame_gray, frame_gray );
|
||||
|
||||
//-- Detect faces
|
||||
face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CASCADE_SCALE_IMAGE, Size(60, 60) );
|
||||
std::vector<Rect> faces;
|
||||
face_cascade.detectMultiScale( frame_gray, faces );
|
||||
|
||||
for ( size_t i = 0; i < faces.size(); i++ )
|
||||
{
|
||||
Point center( faces[i].x + faces[i].width/2, faces[i].y + faces[i].height/2 );
|
||||
ellipse( frame, center, Size( faces[i].width/2, faces[i].height/2 ), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
|
||||
ellipse( frame, center, Size( faces[i].width/2, faces[i].height/2 ), 0, 0, 360, Scalar( 255, 0, 255 ), 4 );
|
||||
|
||||
Mat faceROI = frame_gray( faces[i] );
|
||||
std::vector<Rect> eyes;
|
||||
|
||||
//-- In each face, detect eyes
|
||||
eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CASCADE_SCALE_IMAGE, Size(30, 30) );
|
||||
std::vector<Rect> eyes;
|
||||
eyes_cascade.detectMultiScale( faceROI, eyes );
|
||||
|
||||
for ( size_t j = 0; j < eyes.size(); j++ )
|
||||
{
|
||||
Point eye_center( faces[i].x + eyes[j].x + eyes[j].width/2, faces[i].y + eyes[j].y + eyes[j].height/2 );
|
||||
int radius = cvRound( (eyes[j].width + eyes[j].height)*0.25 );
|
||||
circle( frame, eye_center, radius, Scalar( 255, 0, 0 ), 4, 8, 0 );
|
||||
circle( frame, eye_center, radius, Scalar( 255, 0, 0 ), 4 );
|
||||
}
|
||||
}
|
||||
|
||||
//-- Show what you got
|
||||
imshow( window_name, frame );
|
||||
imshow( "Capture - Face detection", frame );
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <opencv2/photo.hpp>
|
||||
#include "opencv2/photo.hpp"
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include "opencv2/highgui.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
@@ -10,38 +11,52 @@ using namespace std;
|
||||
|
||||
void loadExposureSeq(String, vector<Mat>&, vector<float>&);
|
||||
|
||||
int main(int, char**argv)
|
||||
int main(int argc, char**argv)
|
||||
{
|
||||
CommandLineParser parser( argc, argv, "{@input | | Input directory that contains images and exposure times. }" );
|
||||
|
||||
//! [Load images and exposure times]
|
||||
vector<Mat> images;
|
||||
vector<float> times;
|
||||
loadExposureSeq(argv[1], images, times);
|
||||
loadExposureSeq(parser.get<String>( "@input" ), images, times);
|
||||
//! [Load images and exposure times]
|
||||
|
||||
//! [Estimate camera response]
|
||||
Mat response;
|
||||
Ptr<CalibrateDebevec> calibrate = createCalibrateDebevec();
|
||||
calibrate->process(images, response, times);
|
||||
//! [Estimate camera response]
|
||||
|
||||
//! [Make HDR image]
|
||||
Mat hdr;
|
||||
Ptr<MergeDebevec> merge_debevec = createMergeDebevec();
|
||||
merge_debevec->process(images, hdr, times, response);
|
||||
//! [Make HDR image]
|
||||
|
||||
//! [Tonemap HDR image]
|
||||
Mat ldr;
|
||||
Ptr<TonemapDurand> tonemap = createTonemapDurand(2.2f);
|
||||
tonemap->process(hdr, ldr);
|
||||
//! [Tonemap HDR image]
|
||||
|
||||
//! [Perform exposure fusion]
|
||||
Mat fusion;
|
||||
Ptr<MergeMertens> merge_mertens = createMergeMertens();
|
||||
merge_mertens->process(images, fusion);
|
||||
//! [Perform exposure fusion]
|
||||
|
||||
//! [Write results]
|
||||
imwrite("fusion.png", fusion * 255);
|
||||
imwrite("ldr.png", ldr * 255);
|
||||
imwrite("hdr.hdr", hdr);
|
||||
//! [Write results]
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void loadExposureSeq(String path, vector<Mat>& images, vector<float>& times)
|
||||
{
|
||||
path = path + std::string("/");
|
||||
path = path + "/";
|
||||
ifstream list_file((path + "list.txt").c_str());
|
||||
string name;
|
||||
float val;
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/imgproc.hpp> // cv::Canny()
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
using std::cout; using std::cerr; using std::endl;
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
Mat frame;
|
||||
cout << "Opening camera..." << endl;
|
||||
VideoCapture capture(-1); // open the first available camera
|
||||
if (!capture.isOpened())
|
||||
{
|
||||
cerr << "ERROR: Can't initialize camera capture" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
cout << "Frame width: " << capture.get(CAP_PROP_FRAME_WIDTH) << endl;
|
||||
cout << " height: " << capture.get(CAP_PROP_FRAME_HEIGHT) << endl;
|
||||
cout << "Capturing FPS: " << capture.get(CAP_PROP_FPS) << endl;
|
||||
|
||||
cout << endl << "Press 'ESC' to quit, 'space' to toggle frame processing" << endl;
|
||||
cout << endl << "Start grabbing..." << endl;
|
||||
|
||||
size_t nFrames = 0;
|
||||
bool enableProcessing = false;
|
||||
int64 t0 = cv::getTickCount();
|
||||
int64 processingTime = 0;
|
||||
for (;;)
|
||||
{
|
||||
capture >> frame; // read the next frame from camera
|
||||
if (frame.empty())
|
||||
{
|
||||
cerr << "ERROR: Can't grab camera frame." << endl;
|
||||
break;
|
||||
}
|
||||
nFrames++;
|
||||
if (nFrames % 10 == 0)
|
||||
{
|
||||
const int N = 10;
|
||||
int64 t1 = cv::getTickCount();
|
||||
cout << "Frames captured: " << cv::format("%5lld", (long long int)nFrames)
|
||||
<< " Average FPS: " << cv::format("%9.1f", (double)getTickFrequency() * N / (t1 - t0))
|
||||
<< " Average time per frame: " << cv::format("%9.2f ms", (double)(t1 - t0) * 1000.0f / (N * getTickFrequency()))
|
||||
<< " Average processing time: " << cv::format("%9.2f ms", (double)(processingTime) * 1000.0f / (N * getTickFrequency()))
|
||||
<< std::endl;
|
||||
t0 = t1;
|
||||
processingTime = 0;
|
||||
}
|
||||
if (!enableProcessing)
|
||||
{
|
||||
imshow("Frame", frame);
|
||||
}
|
||||
else
|
||||
{
|
||||
int64 tp0 = cv::getTickCount();
|
||||
Mat processed;
|
||||
cv::Canny(frame, processed, 400, 1000, 5);
|
||||
processingTime += cv::getTickCount() - tp0;
|
||||
imshow("Frame", processed);
|
||||
}
|
||||
int key = waitKey(1);
|
||||
if (key == 27/*ESC*/)
|
||||
break;
|
||||
if (key == 32/*SPACE*/)
|
||||
{
|
||||
enableProcessing = !enableProcessing;
|
||||
cout << "Enable frame processing ('space' key): " << enableProcessing << endl;
|
||||
}
|
||||
}
|
||||
std::cout << "Number of captured frames: " << nFrames << endl;
|
||||
return nFrames > 0 ? 0 : 1;
|
||||
}
|
||||
Reference in New Issue
Block a user