Mergin itseez
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
SET(OPENCV_CPP_SAMPLES_REQUIRED_DEPS opencv_core opencv_flann opencv_imgproc
|
||||
opencv_highgui opencv_ml opencv_video opencv_objdetect opencv_photo opencv_nonfree opencv_softcascade
|
||||
opencv_features2d opencv_calib3d opencv_legacy opencv_contrib opencv_stitching opencv_videostab)
|
||||
opencv_features2d opencv_calib3d opencv_legacy opencv_contrib opencv_stitching opencv_videostab opencv_bioinspired)
|
||||
|
||||
ocv_check_dependencies(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
|
||||
|
||||
@@ -95,4 +95,3 @@ if (INSTALL_C_EXAMPLES AND NOT WIN32)
|
||||
DESTINATION share/OpenCV/samples/cpp
|
||||
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
|
||||
endif()
|
||||
|
||||
|
@@ -10,8 +10,9 @@
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
#include "opencv2/contrib.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/bioinspired.hpp" // retina based algorithms
|
||||
#include "opencv2/imgproc.hpp" // cvCvtcolor function
|
||||
#include "opencv2/highgui.hpp" // display
|
||||
|
||||
static void help(std::string errorMessage)
|
||||
{
|
||||
@@ -127,7 +128,7 @@ static void drawPlot(const cv::Mat curve, const std::string figureTitle, const i
|
||||
normalize(imageInputRescaled, imageInputRescaled, 0.0, 255.0, cv::NORM_MINMAX);
|
||||
}
|
||||
|
||||
cv::Ptr<cv::Retina> retina;
|
||||
cv::Ptr<cv::bioinspired::Retina> retina;
|
||||
int retinaHcellsGain;
|
||||
int localAdaptation_photoreceptors, localAdaptation_Gcells;
|
||||
static void callBack_updateRetinaParams(int, void*)
|
||||
@@ -175,6 +176,12 @@ static void drawPlot(const cv::Mat curve, const std::string figureTitle, const i
|
||||
}
|
||||
|
||||
bool useLogSampling = !strcmp(argv[argc-1], "log"); // check if user wants retina log sampling processing
|
||||
int chosenMethod=0;
|
||||
if (!strcmp(argv[argc-1], "fast"))
|
||||
{
|
||||
chosenMethod=1;
|
||||
std::cout<<"Using fast method (no spectral whithning), adaptation of Meylan&al 2008 method"<<std::endl;
|
||||
}
|
||||
|
||||
std::string inputImageName=argv[1];
|
||||
|
||||
@@ -210,17 +217,22 @@ static void drawPlot(const cv::Mat curve, const std::string figureTitle, const i
|
||||
* -> if the last parameter is 'log', then activate log sampling (favour foveal vision and subsamples peripheral vision)
|
||||
*/
|
||||
if (useLogSampling)
|
||||
{
|
||||
retina = cv::createRetina(inputImage.size(),true, cv::RETINA_COLOR_BAYER, true, 2.0, 10.0);
|
||||
{
|
||||
retina = cv::bioinspired::createRetina(inputImage.size(),true, cv::bioinspired::RETINA_COLOR_BAYER, true, 2.0, 10.0);
|
||||
}
|
||||
else// -> else allocate "classical" retina :
|
||||
retina = cv::createRetina(inputImage.size());
|
||||
retina = cv::bioinspired::createRetina(inputImage.size());
|
||||
|
||||
// save default retina parameters file in order to let you see this and maybe modify it and reload using method "setup"
|
||||
retina->write("RetinaDefaultParameters.xml");
|
||||
// create a fast retina tone mapper (Meyla&al algorithm)
|
||||
std::cout<<"Allocating fast tone mapper..."<<std::endl;
|
||||
//cv::Ptr<cv::RetinaFastToneMapping> fastToneMapper=createRetinaFastToneMapping(inputImage.size());
|
||||
std::cout<<"Fast tone mapper allocated"<<std::endl;
|
||||
|
||||
// desactivate Magnocellular pathway processing (motion information extraction) since it is not usefull here
|
||||
retina->activateMovingContoursProcessing(false);
|
||||
// save default retina parameters file in order to let you see this and maybe modify it and reload using method "setup"
|
||||
retina->write("RetinaDefaultParameters.xml");
|
||||
|
||||
// desactivate Magnocellular pathway processing (motion information extraction) since it is not usefull here
|
||||
retina->activateMovingContoursProcessing(false);
|
||||
|
||||
// declare retina output buffers
|
||||
cv::Mat retinaOutput_parvo;
|
||||
@@ -230,20 +242,19 @@ static void drawPlot(const cv::Mat curve, const std::string figureTitle, const i
|
||||
histogramClippingValue=0; // default value... updated with interface slider
|
||||
//inputRescaleMat = inputImage;
|
||||
//outputRescaleMat = imageInputRescaled;
|
||||
cv::namedWindow("Retina input image (with cut edges histogram for basic pixels error avoidance)",1);
|
||||
cv::createTrackbar("histogram edges clipping limit", "Retina input image (with cut edges histogram for basic pixels error avoidance)",&histogramClippingValue,50,callBack_rescaleGrayLevelMat);
|
||||
cv::namedWindow("Processing configuration",1);
|
||||
cv::createTrackbar("histogram edges clipping limit", "Processing configuration",&histogramClippingValue,50,callBack_rescaleGrayLevelMat);
|
||||
|
||||
cv::namedWindow("Retina Parvocellular pathway output : 16bit=>8bit image retina tonemapping", 1);
|
||||
colorSaturationFactor=3;
|
||||
cv::createTrackbar("Color saturation", "Retina Parvocellular pathway output : 16bit=>8bit image retina tonemapping", &colorSaturationFactor,5,callback_saturateColors);
|
||||
cv::createTrackbar("Color saturation", "Processing configuration", &colorSaturationFactor,5,callback_saturateColors);
|
||||
|
||||
retinaHcellsGain=40;
|
||||
cv::createTrackbar("Hcells gain", "Retina Parvocellular pathway output : 16bit=>8bit image retina tonemapping",&retinaHcellsGain,100,callBack_updateRetinaParams);
|
||||
cv::createTrackbar("Hcells gain", "Processing configuration",&retinaHcellsGain,100,callBack_updateRetinaParams);
|
||||
|
||||
localAdaptation_photoreceptors=197;
|
||||
localAdaptation_Gcells=190;
|
||||
cv::createTrackbar("Ph sensitivity", "Retina Parvocellular pathway output : 16bit=>8bit image retina tonemapping", &localAdaptation_photoreceptors,199,callBack_updateRetinaParams);
|
||||
cv::createTrackbar("Gcells sensitivity", "Retina Parvocellular pathway output : 16bit=>8bit image retina tonemapping", &localAdaptation_Gcells,199,callBack_updateRetinaParams);
|
||||
cv::createTrackbar("Ph sensitivity", "Processing configuration", &localAdaptation_photoreceptors,199,callBack_updateRetinaParams);
|
||||
cv::createTrackbar("Gcells sensitivity", "Processing configuration", &localAdaptation_Gcells,199,callBack_updateRetinaParams);
|
||||
|
||||
|
||||
/////////////////////////////////////////////
|
||||
@@ -257,11 +268,28 @@ static void drawPlot(const cv::Mat curve, const std::string figureTitle, const i
|
||||
while(continueProcessing)
|
||||
{
|
||||
// run retina filter
|
||||
retina->run(imageInputRescaled);
|
||||
// Retrieve and display retina output
|
||||
retina->getParvo(retinaOutput_parvo);
|
||||
cv::imshow("Retina input image (with cut edges histogram for basic pixels error avoidance)", imageInputRescaled/255.0);
|
||||
cv::imshow("Retina Parvocellular pathway output : 16bit=>8bit image retina tonemapping", retinaOutput_parvo);
|
||||
if (!chosenMethod)
|
||||
{
|
||||
retina->run(imageInputRescaled);
|
||||
// Retrieve and display retina output
|
||||
retina->getParvo(retinaOutput_parvo);
|
||||
cv::imshow("Retina input image (with cut edges histogram for basic pixels error avoidance)", imageInputRescaled/255.0);
|
||||
cv::imshow("Retina Parvocellular pathway output : 16bit=>8bit image retina tonemapping", retinaOutput_parvo);
|
||||
cv::imwrite("HDRinput.jpg",imageInputRescaled/255.0);
|
||||
cv::imwrite("RetinaToneMapping.jpg",retinaOutput_parvo);
|
||||
}
|
||||
else
|
||||
{
|
||||
// apply the simplified hdr tone mapping method
|
||||
cv::Mat fastToneMappingOutput;
|
||||
retina->applyFastToneMapping(imageInputRescaled, fastToneMappingOutput);
|
||||
cv::imshow("Retina fast tone mapping output : 16bit=>8bit image retina tonemapping", fastToneMappingOutput);
|
||||
}
|
||||
/*cv::Mat fastToneMappingOutput_specificObject;
|
||||
fastToneMapper->setup(3.f, 1.5f, 1.f);
|
||||
fastToneMapper->applyFastToneMapping(imageInputRescaled, fastToneMappingOutput_specificObject);
|
||||
cv::imshow("### Retina fast tone mapping output : 16bit=>8bit image retina tonemapping", fastToneMappingOutput_specificObject);
|
||||
*/
|
||||
cv::waitKey(10);
|
||||
}
|
||||
}catch(cv::Exception e)
|
||||
@@ -274,5 +302,3 @@ static void drawPlot(const cv::Mat curve, const std::string figureTitle, const i
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -14,8 +14,9 @@
|
||||
#include <stdio.h>
|
||||
#include <cstring>
|
||||
|
||||
#include "opencv2/contrib.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/bioinspired.hpp" // retina based algorithms
|
||||
#include "opencv2/imgproc.hpp" // cvCvtcolor function
|
||||
#include "opencv2/highgui.hpp" // display
|
||||
|
||||
static void help(std::string errorMessage)
|
||||
{
|
||||
@@ -160,7 +161,7 @@ static void rescaleGrayLevelMat(const cv::Mat &inputMat, cv::Mat &outputMat, con
|
||||
|
||||
}
|
||||
|
||||
cv::Ptr<cv::Retina> retina;
|
||||
cv::Ptr<cv::bioinspired::Retina> retina;
|
||||
int retinaHcellsGain;
|
||||
int localAdaptation_photoreceptors, localAdaptation_Gcells;
|
||||
static void callBack_updateRetinaParams(int, void*)
|
||||
@@ -280,10 +281,10 @@ static void loadNewFrame(const std::string filenamePrototype, const int currentF
|
||||
*/
|
||||
if (useLogSampling)
|
||||
{
|
||||
retina = cv::createRetina(inputImage.size(),true, cv::RETINA_COLOR_BAYER, true, 2.0, 10.0);
|
||||
retina = cv::bioinspired::createRetina(inputImage.size(),true, cv::bioinspired::RETINA_COLOR_BAYER, true, 2.0, 10.0);
|
||||
}
|
||||
else// -> else allocate "classical" retina :
|
||||
retina = cv::createRetina(inputImage.size());
|
||||
retina = cv::bioinspired::createRetina(inputImage.size());
|
||||
|
||||
// save default retina parameters file in order to let you see this and maybe modify it and reload using method "setup"
|
||||
retina->write("RetinaDefaultParameters.xml");
|
||||
@@ -358,5 +359,3 @@ static void loadNewFrame(const std::string filenamePrototype, const int currentF
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -2563,19 +2563,19 @@ int main(int argc, char** argv)
|
||||
Ptr<FeatureDetector> featureDetector = FeatureDetector::create( ddmParams.detectorType );
|
||||
Ptr<DescriptorExtractor> descExtractor = DescriptorExtractor::create( ddmParams.descriptorType );
|
||||
Ptr<BOWImgDescriptorExtractor> bowExtractor;
|
||||
if( featureDetector.empty() || descExtractor.empty() )
|
||||
if( !featureDetector || !descExtractor )
|
||||
{
|
||||
cout << "featureDetector or descExtractor was not created" << endl;
|
||||
return -1;
|
||||
}
|
||||
{
|
||||
Ptr<DescriptorMatcher> descMatcher = DescriptorMatcher::create( ddmParams.matcherType );
|
||||
if( featureDetector.empty() || descExtractor.empty() || descMatcher.empty() )
|
||||
if( !featureDetector || !descExtractor || !descMatcher )
|
||||
{
|
||||
cout << "descMatcher was not created" << endl;
|
||||
return -1;
|
||||
}
|
||||
bowExtractor = new BOWImgDescriptorExtractor( descExtractor, descMatcher );
|
||||
bowExtractor = makePtr<BOWImgDescriptorExtractor>( descExtractor, descMatcher );
|
||||
}
|
||||
|
||||
// Print configuration to screen
|
||||
|
@@ -35,7 +35,7 @@ int main(int argc, char** argv)
|
||||
setNumThreads(8);
|
||||
|
||||
Ptr<BackgroundSubtractor> fgbg = createBackgroundSubtractorGMG(20, 0.7);
|
||||
if (fgbg.empty())
|
||||
if (!fgbg)
|
||||
{
|
||||
std::cerr << "Failed to create BackgroundSubtractor.GMG Algorithm." << std::endl;
|
||||
return -1;
|
||||
@@ -78,4 +78,3 @@ int main(int argc, char** argv)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -332,4 +332,3 @@ Mat cv::ChessBoardGenerator::operator ()(const Mat& bg, const Mat& camMat, const
|
||||
|
||||
return generageChessBoard(bg, camMat, distCoeffs, zero, pb1, pb2, sqWidth, sqHeight, pts3d, corners);
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ class CascadeDetectorAdapter: public DetectionBasedTracker::IDetector
|
||||
IDetector(),
|
||||
Detector(detector)
|
||||
{
|
||||
CV_Assert(!detector.empty());
|
||||
CV_Assert(detector);
|
||||
}
|
||||
|
||||
void detect(const cv::Mat &Image, std::vector<cv::Rect> &objects)
|
||||
@@ -51,11 +51,11 @@ int main(int , char** )
|
||||
}
|
||||
|
||||
std::string cascadeFrontalfilename = "../../data/lbpcascades/lbpcascade_frontalface.xml";
|
||||
cv::Ptr<cv::CascadeClassifier> cascade = new cv::CascadeClassifier(cascadeFrontalfilename);
|
||||
cv::Ptr<DetectionBasedTracker::IDetector> MainDetector = new CascadeDetectorAdapter(cascade);
|
||||
cv::Ptr<cv::CascadeClassifier> cascade = makePtr<cv::CascadeClassifier>(cascadeFrontalfilename);
|
||||
cv::Ptr<DetectionBasedTracker::IDetector> MainDetector = makePtr<CascadeDetectorAdapter>(cascade);
|
||||
|
||||
cascade = new cv::CascadeClassifier(cascadeFrontalfilename);
|
||||
cv::Ptr<DetectionBasedTracker::IDetector> TrackingDetector = new CascadeDetectorAdapter(cascade);
|
||||
cascade = makePtr<cv::CascadeClassifier>(cascadeFrontalfilename);
|
||||
cv::Ptr<DetectionBasedTracker::IDetector> TrackingDetector = makePtr<CascadeDetectorAdapter>(cascade);
|
||||
|
||||
DetectionBasedTracker::Parameters params;
|
||||
DetectionBasedTracker Detector(MainDetector, TrackingDetector, params);
|
||||
|
@@ -153,7 +153,7 @@ static void doIteration( const Mat& img1, Mat& img2, bool isWarpPerspective,
|
||||
{
|
||||
cout << "< Evaluate descriptor matcher..." << endl;
|
||||
vector<Point2f> curve;
|
||||
Ptr<GenericDescriptorMatcher> gdm = new VectorDescriptorMatcher( descriptorExtractor, descriptorMatcher );
|
||||
Ptr<GenericDescriptorMatcher> gdm = makePtr<VectorDescriptorMatcher>( descriptorExtractor, descriptorMatcher );
|
||||
evaluateGenericDescriptorMatcher( img1, img2, H12, keypoints1, keypoints2, 0, 0, curve, gdm );
|
||||
|
||||
Point2f firstPoint = *curve.begin();
|
||||
@@ -253,7 +253,7 @@ int main(int argc, char** argv)
|
||||
int mactherFilterType = getMatcherFilterType( argv[4] );
|
||||
bool eval = !isWarpPerspective ? false : (atoi(argv[6]) == 0 ? false : true);
|
||||
cout << ">" << endl;
|
||||
if( detector.empty() || descriptorExtractor.empty() || descriptorMatcher.empty() )
|
||||
if( !detector || !descriptorExtractor || !descriptorMatcher )
|
||||
{
|
||||
cout << "Can not create detector or descriptor exstractor or descriptor matcher of given types" << endl;
|
||||
return -1;
|
||||
|
@@ -67,7 +67,7 @@ class CascadeDetectorAdapter: public DetectionBasedTracker::IDetector
|
||||
CascadeDetectorAdapter(cv::Ptr<cv::CascadeClassifier> detector):
|
||||
Detector(detector)
|
||||
{
|
||||
CV_Assert(!detector.empty());
|
||||
CV_Assert(detector);
|
||||
}
|
||||
|
||||
void detect(const cv::Mat &Image, std::vector<cv::Rect> &objects)
|
||||
@@ -117,11 +117,11 @@ static int test_FaceDetector(int argc, char *argv[])
|
||||
}
|
||||
|
||||
std::string cascadeFrontalfilename=cascadefile;
|
||||
cv::Ptr<cv::CascadeClassifier> cascade = new cv::CascadeClassifier(cascadeFrontalfilename);
|
||||
cv::Ptr<DetectionBasedTracker::IDetector> MainDetector = new CascadeDetectorAdapter(cascade);
|
||||
cv::Ptr<cv::CascadeClassifier> cascade = makePtr<cv::CascadeClassifier>(cascadeFrontalfilename);
|
||||
cv::Ptr<DetectionBasedTracker::IDetector> MainDetector = makePtr<CascadeDetectorAdapter>(cascade);
|
||||
|
||||
cascade = new cv::CascadeClassifier(cascadeFrontalfilename);
|
||||
cv::Ptr<DetectionBasedTracker::IDetector> TrackingDetector = new CascadeDetectorAdapter(cascade);
|
||||
cascade = makePtr<cv::CascadeClassifier>(cascadeFrontalfilename);
|
||||
cv::Ptr<DetectionBasedTracker::IDetector> TrackingDetector = makePtr<CascadeDetectorAdapter>(cascade);
|
||||
|
||||
DetectionBasedTracker::Parameters params;
|
||||
DetectionBasedTracker fd(MainDetector, TrackingDetector, params);
|
||||
|
@@ -535,7 +535,7 @@ void DetectorQualityEvaluator::readAlgorithm ()
|
||||
{
|
||||
defaultDetector = FeatureDetector::create( algName );
|
||||
specificDetector = FeatureDetector::create( algName );
|
||||
if( defaultDetector.empty() )
|
||||
if( !defaultDetector )
|
||||
{
|
||||
printf( "Algorithm can not be read\n" );
|
||||
exit(-1);
|
||||
@@ -769,14 +769,14 @@ void DescriptorQualityEvaluator::readAlgorithm( )
|
||||
defaultDescMatcher = GenericDescriptorMatcher::create( algName );
|
||||
specificDescMatcher = GenericDescriptorMatcher::create( algName );
|
||||
|
||||
if( defaultDescMatcher.empty() )
|
||||
if( !defaultDescMatcher )
|
||||
{
|
||||
Ptr<DescriptorExtractor> extractor = DescriptorExtractor::create( algName );
|
||||
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create( matcherName );
|
||||
defaultDescMatcher = new VectorDescriptorMatch( extractor, matcher );
|
||||
specificDescMatcher = new VectorDescriptorMatch( extractor, matcher );
|
||||
defaultDescMatcher = makePtr<VectorDescriptorMatch>( extractor, matcher );
|
||||
specificDescMatcher = makePtr<VectorDescriptorMatch>( extractor, matcher );
|
||||
|
||||
if( extractor.empty() || matcher.empty() )
|
||||
if( !extractor || !matcher )
|
||||
{
|
||||
printf("Algorithm can not be read\n");
|
||||
exit(-1);
|
||||
@@ -881,8 +881,9 @@ public:
|
||||
virtual void readAlgorithm( )
|
||||
{
|
||||
string classifierFile = data_path + "/features2d/calonder_classifier.rtc";
|
||||
defaultDescMatcher = new VectorDescriptorMatch( new CalonderDescriptorExtractor<float>( classifierFile ),
|
||||
new BFMatcher(NORM_L2) );
|
||||
defaultDescMatcher = makePtr<VectorDescriptorMatch>(
|
||||
makePtr<CalonderDescriptorExtractor<float> >( classifierFile ),
|
||||
makePtr<BFMatcher>(int(NORM_L2)));
|
||||
specificDescMatcher = defaultDescMatcher;
|
||||
}
|
||||
};
|
||||
@@ -922,10 +923,11 @@ void OneWayDescriptorQualityTest::processRunParamsFile ()
|
||||
|
||||
readAllDatasetsRunParams();
|
||||
|
||||
OneWayDescriptorBase *base = new OneWayDescriptorBase(patchSize, poseCount, pcaFilename,
|
||||
trainPath, trainImagesList);
|
||||
Ptr<OneWayDescriptorBase> base(
|
||||
new OneWayDescriptorBase(patchSize, poseCount, pcaFilename,
|
||||
trainPath, trainImagesList));
|
||||
|
||||
OneWayDescriptorMatch *match = new OneWayDescriptorMatch ();
|
||||
Ptr<OneWayDescriptorMatch> match = makePtr<OneWayDescriptorMatch>();
|
||||
match->initialize( OneWayDescriptorMatch::Params (), base );
|
||||
defaultDescMatcher = match;
|
||||
writeAllDatasetsRunParams();
|
||||
@@ -958,18 +960,18 @@ int main( int argc, char** argv )
|
||||
|
||||
Ptr<BaseQualityEvaluator> evals[] =
|
||||
{
|
||||
new DetectorQualityEvaluator( "FAST", "quality-detector-fast" ),
|
||||
new DetectorQualityEvaluator( "GFTT", "quality-detector-gftt" ),
|
||||
new DetectorQualityEvaluator( "HARRIS", "quality-detector-harris" ),
|
||||
new DetectorQualityEvaluator( "MSER", "quality-detector-mser" ),
|
||||
new DetectorQualityEvaluator( "STAR", "quality-detector-star" ),
|
||||
new DetectorQualityEvaluator( "SIFT", "quality-detector-sift" ),
|
||||
new DetectorQualityEvaluator( "SURF", "quality-detector-surf" ),
|
||||
makePtr<DetectorQualityEvaluator>( "FAST", "quality-detector-fast" ),
|
||||
makePtr<DetectorQualityEvaluator>( "GFTT", "quality-detector-gftt" ),
|
||||
makePtr<DetectorQualityEvaluator>( "HARRIS", "quality-detector-harris" ),
|
||||
makePtr<DetectorQualityEvaluator>( "MSER", "quality-detector-mser" ),
|
||||
makePtr<DetectorQualityEvaluator>( "STAR", "quality-detector-star" ),
|
||||
makePtr<DetectorQualityEvaluator>( "SIFT", "quality-detector-sift" ),
|
||||
makePtr<DetectorQualityEvaluator>( "SURF", "quality-detector-surf" ),
|
||||
|
||||
new DescriptorQualityEvaluator( "SIFT", "quality-descriptor-sift", "BruteForce" ),
|
||||
new DescriptorQualityEvaluator( "SURF", "quality-descriptor-surf", "BruteForce" ),
|
||||
new DescriptorQualityEvaluator( "FERN", "quality-descriptor-fern"),
|
||||
new CalonderDescriptorQualityEvaluator()
|
||||
makePtr<DescriptorQualityEvaluator>( "SIFT", "quality-descriptor-sift", "BruteForce" ),
|
||||
makePtr<DescriptorQualityEvaluator>( "SURF", "quality-descriptor-surf", "BruteForce" ),
|
||||
makePtr<DescriptorQualityEvaluator>( "FERN", "quality-descriptor-fern"),
|
||||
makePtr<CalonderDescriptorQualityEvaluator>()
|
||||
};
|
||||
|
||||
for( size_t i = 0; i < sizeof(evals)/sizeof(evals[0]); i++ )
|
||||
|
@@ -80,4 +80,3 @@ int main(int argc, const char ** argv)
|
||||
waitKey();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
120
samples/cpp/erfilter.cpp
Normal file
120
samples/cpp/erfilter.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// A demo program of the Extremal Region Filter algorithm described in
|
||||
// Neumann L., Matas J.: Real-Time Scene Text Localization and Recognition, CVPR 2012
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "opencv2/opencv.hpp"
|
||||
#include "opencv2/objdetect.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
void er_draw(Mat &src, Mat &dst, ERStat& er);
|
||||
|
||||
void er_draw(Mat &src, Mat &dst, ERStat& er)
|
||||
{
|
||||
|
||||
if (er.parent != NULL) // deprecate the root region
|
||||
{
|
||||
int newMaskVal = 255;
|
||||
int flags = 4 + (newMaskVal << 8) + FLOODFILL_FIXED_RANGE + FLOODFILL_MASK_ONLY;
|
||||
floodFill(src,dst,Point(er.pixel%src.cols,er.pixel/src.cols),Scalar(255),0,Scalar(er.level),Scalar(0),flags);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, const char * argv[])
|
||||
{
|
||||
|
||||
|
||||
vector<ERStat> regions;
|
||||
|
||||
if (argc < 2) {
|
||||
cout << "Demo program of the Extremal Region Filter algorithm described in " << endl;
|
||||
cout << "Neumann L., Matas J.: Real-Time Scene Text Localization and Recognition, CVPR 2012" << endl << endl;
|
||||
cout << " Usage: " << argv[0] << " input_image <optional_groundtruth_image>" << endl;
|
||||
cout << " Default classifier files (trained_classifierNM*.xml) should be in ./" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Mat original = imread(argv[1]);
|
||||
Mat gt;
|
||||
if (argc > 2)
|
||||
{
|
||||
gt = imread(argv[2]);
|
||||
cvtColor(gt, gt, COLOR_RGB2GRAY);
|
||||
threshold(gt, gt, 254, 255, THRESH_BINARY);
|
||||
}
|
||||
Mat grey(original.size(),CV_8UC1);
|
||||
cvtColor(original,grey,COLOR_RGB2GRAY);
|
||||
|
||||
double t = (double)getTickCount();
|
||||
|
||||
// Build ER tree and filter with the 1st stage default classifier
|
||||
Ptr<ERFilter> er_filter1 = createERFilterNM1(loadClassifierNM1("trained_classifierNM1.xml"));
|
||||
|
||||
er_filter1->run(grey, regions);
|
||||
|
||||
t = (double)getTickCount() - t;
|
||||
cout << " --------------------------------------------------------------------------------------------------" << endl;
|
||||
cout << "\t FIRST STAGE CLASSIFIER done in " << t * 1000. / getTickFrequency() << " ms." << endl;
|
||||
cout << " --------------------------------------------------------------------------------------------------" << endl;
|
||||
cout << setw(9) << regions.size()+er_filter1->getNumRejected() << "\t Extremal Regions extracted " << endl;
|
||||
cout << setw(9) << regions.size() << "\t Extremal Regions selected by the first stage of the sequential classifier." << endl;
|
||||
cout << "\t \t (saving into out_second_stage.jpg)" << endl;
|
||||
cout << " --------------------------------------------------------------------------------------------------" << endl;
|
||||
|
||||
er_filter1.release();
|
||||
|
||||
// draw regions
|
||||
Mat mask = Mat::zeros(grey.rows+2,grey.cols+2,CV_8UC1);
|
||||
for (int r=0; r<(int)regions.size(); r++)
|
||||
er_draw(grey, mask, regions.at(r));
|
||||
mask = 255-mask;
|
||||
imwrite("out_first_stage.jpg", mask);
|
||||
|
||||
if (argc > 2)
|
||||
{
|
||||
Mat tmp_mask = (255-gt) & (255-mask(Rect(Point(1,1),Size(mask.cols-2,mask.rows-2))));
|
||||
cout << "Recall for the 1st stage filter = " << (float)countNonZero(tmp_mask) / countNonZero(255-gt) << endl;
|
||||
}
|
||||
|
||||
t = (double)getTickCount();
|
||||
|
||||
// Default second stage classifier
|
||||
Ptr<ERFilter> er_filter2 = createERFilterNM2(loadClassifierNM2("trained_classifierNM2.xml"));
|
||||
er_filter2->run(grey, regions);
|
||||
|
||||
t = (double)getTickCount() - t;
|
||||
cout << " --------------------------------------------------------------------------------------------------" << endl;
|
||||
cout << "\t SECOND STAGE CLASSIFIER done in " << t * 1000. / getTickFrequency() << " ms." << endl;
|
||||
cout << " --------------------------------------------------------------------------------------------------" << endl;
|
||||
cout << setw(9) << regions.size() << "\t Extremal Regions selected by the second stage of the sequential classifier." << endl;
|
||||
cout << "\t \t (saving into out_second_stage.jpg)" << endl;
|
||||
cout << " --------------------------------------------------------------------------------------------------" << endl;
|
||||
|
||||
er_filter2.release();
|
||||
|
||||
// draw regions
|
||||
mask = mask*0;
|
||||
for (int r=0; r<(int)regions.size(); r++)
|
||||
er_draw(grey, mask, regions.at(r));
|
||||
mask = 255-mask;
|
||||
imwrite("out_second_stage.jpg", mask);
|
||||
|
||||
if (argc > 2)
|
||||
{
|
||||
Mat tmp_mask = (255-gt) & (255-mask(Rect(Point(1,1),Size(mask.cols-2,mask.rows-2))));
|
||||
cout << "Recall for the 2nd stage filter = " << (float)countNonZero(tmp_mask) / countNonZero(255-gt) << endl;
|
||||
}
|
||||
|
||||
regions.clear();
|
||||
|
||||
}
|
@@ -131,11 +131,11 @@ int main(int argc, char * argv[]) {
|
||||
//generate test data
|
||||
cout << "Extracting Test Data from images" << endl <<
|
||||
endl;
|
||||
Ptr<FeatureDetector> detector =
|
||||
Ptr<FeatureDetector> detector(
|
||||
new DynamicAdaptedFeatureDetector(
|
||||
AdjusterAdapter::create("STAR"), 130, 150, 5);
|
||||
Ptr<DescriptorExtractor> extractor =
|
||||
new SurfDescriptorExtractor(1000, 4, 2, false, true);
|
||||
AdjusterAdapter::create("STAR"), 130, 150, 5));
|
||||
Ptr<DescriptorExtractor> extractor(
|
||||
new SurfDescriptorExtractor(1000, 4, 2, false, true));
|
||||
Ptr<DescriptorMatcher> matcher =
|
||||
DescriptorMatcher::create("FlannBased");
|
||||
|
||||
@@ -183,8 +183,8 @@ int main(int argc, char * argv[]) {
|
||||
endl;
|
||||
Ptr<of2::FabMap> fabmap;
|
||||
|
||||
fabmap = new of2::FabMap2(tree, 0.39, 0, of2::FabMap::SAMPLED |
|
||||
of2::FabMap::CHOW_LIU);
|
||||
fabmap.reset(new of2::FabMap2(tree, 0.39, 0, of2::FabMap::SAMPLED |
|
||||
of2::FabMap::CHOW_LIU));
|
||||
fabmap->addTraining(trainData);
|
||||
|
||||
vector<of2::IMatch> matches;
|
||||
|
@@ -56,7 +56,7 @@ static void help( char** argv )
|
||||
}
|
||||
|
||||
int main( int argc, char** argv ) {
|
||||
// check http://opencv.itseez.com/doc/tutorials/features2d/table_of_content_features2d/table_of_content_features2d.html
|
||||
// check http://docs.opencv.org/doc/tutorials/features2d/table_of_content_features2d/table_of_content_features2d.html
|
||||
// for OpenCV general detection/matching framework details
|
||||
|
||||
if( argc != 3 ) {
|
||||
|
@@ -33,7 +33,7 @@ int main(int argc, char** argv)
|
||||
std::string params_filename = std::string(argv[4]);
|
||||
|
||||
Ptr<GenericDescriptorMatcher> descriptorMatcher = GenericDescriptorMatcher::create(alg_name, params_filename);
|
||||
if( descriptorMatcher.empty() )
|
||||
if( !descriptorMatcher )
|
||||
{
|
||||
printf ("Cannot create descriptor\n");
|
||||
return 0;
|
||||
|
@@ -61,4 +61,3 @@ int main(int argc, char** argv)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -31,8 +31,8 @@ int main( int argc, char** argv )
|
||||
help();
|
||||
const char* imagename = argc > 1 ? argv[1] : "lena.jpg";
|
||||
#if DEMO_MIXED_API_USE
|
||||
Ptr<IplImage> iplimg = cvLoadImage(imagename); // Ptr<T> is safe ref-conting pointer class
|
||||
if(iplimg.empty())
|
||||
Ptr<IplImage> iplimg(cvLoadImage(imagename)); // Ptr<T> is safe ref-counting pointer class
|
||||
if(!iplimg)
|
||||
{
|
||||
fprintf(stderr, "Can not load image %s\n", imagename);
|
||||
return -1;
|
||||
|
57
samples/cpp/image_sequence.cpp
Normal file
57
samples/cpp/image_sequence.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
static void help(char** argv)
|
||||
{
|
||||
cout << "\nThis sample shows you how to read a sequence of images using the VideoCapture interface.\n"
|
||||
<< "Usage: " << argv[0] << " <image_mask> (example mask: example_%%02d.jpg)\n"
|
||||
<< "Image mask defines the name variation for the input images that have to be read as a sequence. \n"
|
||||
<< "Using the mask example_%%02d.jpg will read in images labeled as 'example_00.jpg', 'example_01.jpg', etc."
|
||||
<< endl;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(argc != 2)
|
||||
{
|
||||
help(argv);
|
||||
return 1;
|
||||
}
|
||||
|
||||
string first_file = argv[1];
|
||||
VideoCapture sequence(first_file);
|
||||
|
||||
if (!sequence.isOpened())
|
||||
{
|
||||
cerr << "Failed to open the image sequence!\n" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
Mat image;
|
||||
namedWindow("Image sequence | press ESC to close", 1);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
// Read in image from sequence
|
||||
sequence >> image;
|
||||
|
||||
// If no image was retrieved -> end of sequence
|
||||
if(image.empty())
|
||||
{
|
||||
cout << "End of Sequence" << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
imshow("Image sequence | press ESC to close", image);
|
||||
|
||||
if(waitKey(500) == 27)
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@@ -3,7 +3,7 @@
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/contrib/contrib.hpp"
|
||||
|
||||
#ifdef WIN32
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <dirent.h>
|
||||
@@ -59,7 +59,7 @@ static void readDirectory( const string& directoryName, vector<String>& filename
|
||||
{
|
||||
filenames.clear();
|
||||
|
||||
#ifdef WIN32
|
||||
#if defined(WIN32) | defined(_WIN32)
|
||||
struct _finddata_t s_file;
|
||||
string str = directoryName + "\\*.*";
|
||||
|
||||
|
@@ -114,7 +114,7 @@ private:
|
||||
// Functions to store detector and templates in single XML/YAML file
|
||||
static cv::Ptr<cv::linemod::Detector> readLinemod(const std::string& filename)
|
||||
{
|
||||
cv::Ptr<cv::linemod::Detector> detector = new cv::linemod::Detector;
|
||||
cv::Ptr<cv::linemod::Detector> detector = cv::makePtr<cv::linemod::Detector>();
|
||||
cv::FileStorage fs(filename, cv::FileStorage::READ);
|
||||
detector->read(fs.root());
|
||||
|
||||
|
54
samples/cpp/lsd_lines.cpp
Normal file
54
samples/cpp/lsd_lines.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/utility.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::string in;
|
||||
if (argc != 2)
|
||||
{
|
||||
std::cout << "Usage: lsd_lines [input image]. Now loading building.jpg" << std::endl;
|
||||
in = "building.jpg";
|
||||
}
|
||||
else
|
||||
{
|
||||
in = argv[1];
|
||||
}
|
||||
|
||||
Mat image = imread(in, IMREAD_GRAYSCALE);
|
||||
|
||||
#if 0
|
||||
Canny(image, image, 50, 200, 3); // Apply canny edge
|
||||
#endif
|
||||
|
||||
// Create and LSD detector with standard or no refinement.
|
||||
#if 1
|
||||
Ptr<LineSegmentDetector> ls = createLineSegmentDetectorPtr(LSD_REFINE_STD);
|
||||
#else
|
||||
Ptr<LineSegmentDetector> ls = createLineSegmentDetectorPtr(LSD_REFINE_NONE);
|
||||
#endif
|
||||
|
||||
double start = double(getTickCount());
|
||||
vector<Vec4i> lines_std;
|
||||
|
||||
// Detect the lines
|
||||
ls->detect(image, lines_std);
|
||||
|
||||
double duration_ms = (double(getTickCount()) - start) * 1000 / getTickFrequency();
|
||||
std::cout << "It took " << duration_ms << " ms." << std::endl;
|
||||
|
||||
// Show found lines
|
||||
Mat drawnLines(image);
|
||||
ls->drawSegments(drawnLines, lines_std);
|
||||
imshow("Standard refinement", drawnLines);
|
||||
|
||||
waitKey();
|
||||
return 0;
|
||||
}
|
@@ -84,7 +84,7 @@ static bool createDetectorDescriptorMatcher( const string& detectorType, const s
|
||||
descriptorMatcher = DescriptorMatcher::create( matcherType );
|
||||
cout << ">" << endl;
|
||||
|
||||
bool isCreated = !( featureDetector.empty() || descriptorExtractor.empty() || descriptorMatcher.empty() );
|
||||
bool isCreated = featureDetector && descriptorExtractor && descriptorMatcher;
|
||||
if( !isCreated )
|
||||
cout << "Can not create feature detector or descriptor extractor or descriptor matcher of given types." << endl << ">" << endl;
|
||||
|
||||
|
@@ -43,7 +43,3 @@ int main(int, char* [])
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -9,7 +9,7 @@
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
#include "opencv2/contrib.hpp"
|
||||
#include "opencv2/bioinspired.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
|
||||
static void help(std::string errorMessage)
|
||||
@@ -106,15 +106,15 @@ int main(int argc, char* argv[]) {
|
||||
try
|
||||
{
|
||||
// create a retina instance with default parameters setup, uncomment the initialisation you wanna test
|
||||
cv::Ptr<cv::Retina> myRetina;
|
||||
cv::Ptr<cv::bioinspired::Retina> myRetina;
|
||||
|
||||
// if the last parameter is 'log', then activate log sampling (favour foveal vision and subsamples peripheral vision)
|
||||
if (useLogSampling)
|
||||
{
|
||||
myRetina = cv::createRetina(inputFrame.size(), true, cv::RETINA_COLOR_BAYER, true, 2.0, 10.0);
|
||||
myRetina = cv::bioinspired::createRetina(inputFrame.size(), true, cv::bioinspired::RETINA_COLOR_BAYER, true, 2.0, 10.0);
|
||||
}
|
||||
else// -> else allocate "classical" retina :
|
||||
myRetina = cv::createRetina(inputFrame.size());
|
||||
myRetina = cv::bioinspired::createRetina(inputFrame.size());
|
||||
|
||||
// save default retina parameters file in order to let you see this and maybe modify it and reload using method "setup"
|
||||
myRetina->write("RetinaDefaultParameters.xml");
|
||||
@@ -143,7 +143,8 @@ int main(int argc, char* argv[]) {
|
||||
cv::imshow("retina input", inputFrame);
|
||||
cv::imshow("Retina Parvo", retinaOutput_parvo);
|
||||
cv::imshow("Retina Magno", retinaOutput_magno);
|
||||
cv::waitKey(10);
|
||||
|
||||
cv::waitKey(5);
|
||||
}
|
||||
}catch(cv::Exception e)
|
||||
{
|
||||
@@ -155,4 +156,3 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
BIN
samples/cpp/scenetext.jpg
Normal file
BIN
samples/cpp/scenetext.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 83 KiB |
BIN
samples/cpp/scenetext_GT.png
Normal file
BIN
samples/cpp/scenetext_GT.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
@@ -41,15 +41,15 @@ namespace {
|
||||
cout << "press space to save a picture. q or esc to quit" << endl;
|
||||
namedWindow(window_name, WINDOW_KEEPRATIO); //resizable window;
|
||||
Mat frame;
|
||||
|
||||
|
||||
for (;;) {
|
||||
capture >> frame;
|
||||
if (frame.empty())
|
||||
break;
|
||||
|
||||
|
||||
imshow(window_name, frame);
|
||||
char key = (char)waitKey(30); //delay N millis, usually long enough to display and capture input
|
||||
|
||||
|
||||
switch (key) {
|
||||
case 'q':
|
||||
case 'Q':
|
||||
|
@@ -14,15 +14,12 @@
|
||||
Or: http://oreilly.com/catalog/9780596516130/
|
||||
ISBN-10: 0596516134 or: ISBN-13: 978-0596516130
|
||||
|
||||
OTHER OPENCV SITES:
|
||||
* The source code is on sourceforge at:
|
||||
http://sourceforge.net/projects/opencvlibrary/
|
||||
* The OpenCV wiki page (As of Oct 1, 2008 this is down for changing over servers, but should come back):
|
||||
http://opencvlibrary.sourceforge.net/
|
||||
* An active user group is at:
|
||||
http://tech.groups.yahoo.com/group/OpenCV/
|
||||
* The minutes of weekly OpenCV development meetings are at:
|
||||
http://code.opencv.org/projects/opencv/wiki/Meeting_notes
|
||||
OPENCV WEBSITES:
|
||||
Homepage: http://opencv.org
|
||||
Online docs: http://docs.opencv.org
|
||||
Q&A forum: http://answers.opencv.org
|
||||
Issue tracker: http://code.opencv.org
|
||||
GitHub: https://github.com/Itseez/opencv/
|
||||
************************************************** */
|
||||
|
||||
#include "opencv2/calib3d/calib3d.hpp"
|
||||
@@ -404,4 +401,3 @@ int main(int argc, char** argv)
|
||||
StereoCalib(imagelist, boardSize, true, showRectified);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -134,5 +134,3 @@ int parseCmdArgs(int argc, char** argv)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -358,14 +358,14 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
#ifdef HAVE_OPENCV_NONFREE
|
||||
if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0)
|
||||
finder = new SurfFeaturesFinderGpu();
|
||||
finder = makePtr<SurfFeaturesFinderGpu>();
|
||||
else
|
||||
#endif
|
||||
finder = new SurfFeaturesFinder();
|
||||
finder = makePtr<SurfFeaturesFinder>();
|
||||
}
|
||||
else if (features_type == "orb")
|
||||
{
|
||||
finder = new OrbFeaturesFinder();
|
||||
finder = makePtr<OrbFeaturesFinder>();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -469,7 +469,11 @@ int main(int argc, char* argv[])
|
||||
|
||||
HomographyBasedEstimator estimator;
|
||||
vector<CameraParams> cameras;
|
||||
estimator(features, pairwise_matches, cameras);
|
||||
if (!estimator(features, pairwise_matches, cameras))
|
||||
{
|
||||
cout << "Homography estimation failed.\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < cameras.size(); ++i)
|
||||
{
|
||||
@@ -480,8 +484,8 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
|
||||
Ptr<detail::BundleAdjusterBase> adjuster;
|
||||
if (ba_cost_func == "reproj") adjuster = new detail::BundleAdjusterReproj();
|
||||
else if (ba_cost_func == "ray") adjuster = new detail::BundleAdjusterRay();
|
||||
if (ba_cost_func == "reproj") adjuster = makePtr<detail::BundleAdjusterReproj>();
|
||||
else if (ba_cost_func == "ray") adjuster = makePtr<detail::BundleAdjusterRay>();
|
||||
else
|
||||
{
|
||||
cout << "Unknown bundle adjustment cost function: '" << ba_cost_func << "'.\n";
|
||||
@@ -495,7 +499,11 @@ int main(int argc, char* argv[])
|
||||
if (ba_refine_mask[3] == 'x') refine_mask(1,1) = 1;
|
||||
if (ba_refine_mask[4] == 'x') refine_mask(1,2) = 1;
|
||||
adjuster->setRefinementMask(refine_mask);
|
||||
(*adjuster)(features, pairwise_matches, cameras);
|
||||
if (!(*adjuster)(features, pairwise_matches, cameras))
|
||||
{
|
||||
cout << "Camera parameters adjusting failed.\n";
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Find median focal length
|
||||
|
||||
@@ -547,31 +555,49 @@ int main(int argc, char* argv[])
|
||||
#ifdef HAVE_OPENCV_GPUWARPING
|
||||
if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0)
|
||||
{
|
||||
if (warp_type == "plane") warper_creator = new cv::PlaneWarperGpu();
|
||||
else if (warp_type == "cylindrical") warper_creator = new cv::CylindricalWarperGpu();
|
||||
else if (warp_type == "spherical") warper_creator = new cv::SphericalWarperGpu();
|
||||
if (warp_type == "plane")
|
||||
warper_creator = makePtr<cv::PlaneWarperGpu>();
|
||||
else if (warp_type == "cylindrical")
|
||||
warper_creator = makePtr<cv::CylindricalWarperGpu>();
|
||||
else if (warp_type == "spherical")
|
||||
warper_creator = makePtr<cv::SphericalWarperGpu>();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (warp_type == "plane") warper_creator = new cv::PlaneWarper();
|
||||
else if (warp_type == "cylindrical") warper_creator = new cv::CylindricalWarper();
|
||||
else if (warp_type == "spherical") warper_creator = new cv::SphericalWarper();
|
||||
else if (warp_type == "fisheye") warper_creator = new cv::FisheyeWarper();
|
||||
else if (warp_type == "stereographic") warper_creator = new cv::StereographicWarper();
|
||||
else if (warp_type == "compressedPlaneA2B1") warper_creator = new cv::CompressedRectilinearWarper(2, 1);
|
||||
else if (warp_type == "compressedPlaneA1.5B1") warper_creator = new cv::CompressedRectilinearWarper(1.5, 1);
|
||||
else if (warp_type == "compressedPlanePortraitA2B1") warper_creator = new cv::CompressedRectilinearPortraitWarper(2, 1);
|
||||
else if (warp_type == "compressedPlanePortraitA1.5B1") warper_creator = new cv::CompressedRectilinearPortraitWarper(1.5, 1);
|
||||
else if (warp_type == "paniniA2B1") warper_creator = new cv::PaniniWarper(2, 1);
|
||||
else if (warp_type == "paniniA1.5B1") warper_creator = new cv::PaniniWarper(1.5, 1);
|
||||
else if (warp_type == "paniniPortraitA2B1") warper_creator = new cv::PaniniPortraitWarper(2, 1);
|
||||
else if (warp_type == "paniniPortraitA1.5B1") warper_creator = new cv::PaniniPortraitWarper(1.5, 1);
|
||||
else if (warp_type == "mercator") warper_creator = new cv::MercatorWarper();
|
||||
else if (warp_type == "transverseMercator") warper_creator = new cv::TransverseMercatorWarper();
|
||||
if (warp_type == "plane")
|
||||
warper_creator = makePtr<cv::PlaneWarper>();
|
||||
else if (warp_type == "cylindrical")
|
||||
warper_creator = makePtr<cv::CylindricalWarper>();
|
||||
else if (warp_type == "spherical")
|
||||
warper_creator = makePtr<cv::SphericalWarper>();
|
||||
else if (warp_type == "fisheye")
|
||||
warper_creator = makePtr<cv::FisheyeWarper>();
|
||||
else if (warp_type == "stereographic")
|
||||
warper_creator = makePtr<cv::StereographicWarper>();
|
||||
else if (warp_type == "compressedPlaneA2B1")
|
||||
warper_creator = makePtr<cv::CompressedRectilinearWarper>(2.0f, 1.0f);
|
||||
else if (warp_type == "compressedPlaneA1.5B1")
|
||||
warper_creator = makePtr<cv::CompressedRectilinearWarper>(1.5f, 1.0f);
|
||||
else if (warp_type == "compressedPlanePortraitA2B1")
|
||||
warper_creator = makePtr<cv::CompressedRectilinearPortraitWarper>(2.0f, 1.0f);
|
||||
else if (warp_type == "compressedPlanePortraitA1.5B1")
|
||||
warper_creator = makePtr<cv::CompressedRectilinearPortraitWarper>(1.5f, 1.0f);
|
||||
else if (warp_type == "paniniA2B1")
|
||||
warper_creator = makePtr<cv::PaniniWarper>(2.0f, 1.0f);
|
||||
else if (warp_type == "paniniA1.5B1")
|
||||
warper_creator = makePtr<cv::PaniniWarper>(1.5f, 1.0f);
|
||||
else if (warp_type == "paniniPortraitA2B1")
|
||||
warper_creator = makePtr<cv::PaniniPortraitWarper>(2.0f, 1.0f);
|
||||
else if (warp_type == "paniniPortraitA1.5B1")
|
||||
warper_creator = makePtr<cv::PaniniPortraitWarper>(1.5f, 1.0f);
|
||||
else if (warp_type == "mercator")
|
||||
warper_creator = makePtr<cv::MercatorWarper>();
|
||||
else if (warp_type == "transverseMercator")
|
||||
warper_creator = makePtr<cv::TransverseMercatorWarper>();
|
||||
}
|
||||
|
||||
if (warper_creator.empty())
|
||||
if (!warper_creator)
|
||||
{
|
||||
cout << "Can't create the following warper '" << warp_type << "'\n";
|
||||
return 1;
|
||||
@@ -604,32 +630,32 @@ int main(int argc, char* argv[])
|
||||
|
||||
Ptr<SeamFinder> seam_finder;
|
||||
if (seam_find_type == "no")
|
||||
seam_finder = new detail::NoSeamFinder();
|
||||
seam_finder = makePtr<detail::NoSeamFinder>();
|
||||
else if (seam_find_type == "voronoi")
|
||||
seam_finder = new detail::VoronoiSeamFinder();
|
||||
seam_finder = makePtr<detail::VoronoiSeamFinder>();
|
||||
else if (seam_find_type == "gc_color")
|
||||
{
|
||||
#ifdef HAVE_OPENCV_GPU
|
||||
if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0)
|
||||
seam_finder = new detail::GraphCutSeamFinderGpu(GraphCutSeamFinderBase::COST_COLOR);
|
||||
seam_finder = makePtr<detail::GraphCutSeamFinderGpu>(GraphCutSeamFinderBase::COST_COLOR);
|
||||
else
|
||||
#endif
|
||||
seam_finder = new detail::GraphCutSeamFinder(GraphCutSeamFinderBase::COST_COLOR);
|
||||
seam_finder = makePtr<detail::GraphCutSeamFinder>(GraphCutSeamFinderBase::COST_COLOR);
|
||||
}
|
||||
else if (seam_find_type == "gc_colorgrad")
|
||||
{
|
||||
#ifdef HAVE_OPENCV_GPU
|
||||
if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0)
|
||||
seam_finder = new detail::GraphCutSeamFinderGpu(GraphCutSeamFinderBase::COST_COLOR_GRAD);
|
||||
seam_finder = makePtr<detail::GraphCutSeamFinderGpu>(GraphCutSeamFinderBase::COST_COLOR_GRAD);
|
||||
else
|
||||
#endif
|
||||
seam_finder = new detail::GraphCutSeamFinder(GraphCutSeamFinderBase::COST_COLOR_GRAD);
|
||||
seam_finder = makePtr<detail::GraphCutSeamFinder>(GraphCutSeamFinderBase::COST_COLOR_GRAD);
|
||||
}
|
||||
else if (seam_find_type == "dp_color")
|
||||
seam_finder = new detail::DpSeamFinder(DpSeamFinder::COLOR);
|
||||
seam_finder = makePtr<detail::DpSeamFinder>(DpSeamFinder::COLOR);
|
||||
else if (seam_find_type == "dp_colorgrad")
|
||||
seam_finder = new detail::DpSeamFinder(DpSeamFinder::COLOR_GRAD);
|
||||
if (seam_finder.empty())
|
||||
seam_finder = makePtr<detail::DpSeamFinder>(DpSeamFinder::COLOR_GRAD);
|
||||
if (!seam_finder)
|
||||
{
|
||||
cout << "Can't create the following seam finder '" << seam_find_type << "'\n";
|
||||
return 1;
|
||||
@@ -727,7 +753,7 @@ int main(int argc, char* argv[])
|
||||
resize(dilated_mask, seam_mask, mask_warped.size());
|
||||
mask_warped = seam_mask & mask_warped;
|
||||
|
||||
if (blender.empty())
|
||||
if (!blender)
|
||||
{
|
||||
blender = Blender::createDefault(blend_type, try_gpu);
|
||||
Size dst_sz = resultRoi(corners, sizes).size();
|
||||
@@ -736,13 +762,13 @@ int main(int argc, char* argv[])
|
||||
blender = Blender::createDefault(Blender::NO, try_gpu);
|
||||
else if (blend_type == Blender::MULTI_BAND)
|
||||
{
|
||||
MultiBandBlender* mb = dynamic_cast<MultiBandBlender*>(static_cast<Blender*>(blender));
|
||||
MultiBandBlender* mb = dynamic_cast<MultiBandBlender*>(blender.get());
|
||||
mb->setNumBands(static_cast<int>(ceil(log(blend_width)/log(2.)) - 1.));
|
||||
LOGLN("Multi-band blender, number of bands: " << mb->numBands());
|
||||
}
|
||||
else if (blend_type == Blender::FEATHER)
|
||||
{
|
||||
FeatherBlender* fb = dynamic_cast<FeatherBlender*>(static_cast<Blender*>(blender));
|
||||
FeatherBlender* fb = dynamic_cast<FeatherBlender*>(blender.get());
|
||||
fb->setSharpness(1.f/blend_width);
|
||||
LOGLN("Feather blender, sharpness: " << fb->sharpness());
|
||||
}
|
||||
@@ -763,5 +789,3 @@ int main(int argc, char* argv[])
|
||||
LOGLN("Finished, total time: " << ((getTickCount() - app_start_time) / getTickFrequency()) << " sec");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
4046
samples/cpp/trained_classifierNM1.xml
Normal file
4046
samples/cpp/trained_classifierNM1.xml
Normal file
File diff suppressed because it is too large
Load Diff
4046
samples/cpp/trained_classifierNM2.xml
Normal file
4046
samples/cpp/trained_classifierNM2.xml
Normal file
File diff suppressed because it is too large
Load Diff
@@ -76,5 +76,3 @@ void Morphology_Operations( int, void* )
|
||||
morphologyEx( src, dst, operation, element );
|
||||
imshow( window_name, dst );
|
||||
}
|
||||
|
||||
|
||||
|
@@ -66,10 +66,3 @@ int main( void )
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -61,5 +61,3 @@ int main( int, char** argv )
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -15,7 +15,6 @@ using namespace cv;
|
||||
Mat src, dst;
|
||||
int top, bottom, left, right;
|
||||
int borderType;
|
||||
Scalar value;
|
||||
const char* window_name = "copyMakeBorder Demo";
|
||||
RNG rng(12345);
|
||||
|
||||
@@ -64,7 +63,7 @@ int main( int, char** argv )
|
||||
else if( (char)c == 'r' )
|
||||
{ borderType = BORDER_REPLICATE; }
|
||||
|
||||
value = Scalar( rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255) );
|
||||
Scalar value( rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255) );
|
||||
copyMakeBorder( src, dst, top, bottom, left, right, borderType, value );
|
||||
|
||||
imshow( window_name, dst );
|
||||
@@ -72,5 +71,3 @@ int main( int, char** argv )
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -92,4 +92,3 @@ void thresh_callback(int, void* )
|
||||
circle( drawing, mc[i], 4, color, -1, 8, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -79,5 +79,3 @@ int main( void )
|
||||
waitKey(0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -120,4 +120,3 @@ void myHarris_function( int, void* )
|
||||
}
|
||||
imshow( myHarris_window, myHarris_copy );
|
||||
}
|
||||
|
||||
|
@@ -102,4 +102,3 @@ void goodFeaturesToTrack_Demo( int, void* )
|
||||
for( size_t i = 0; i < corners.size(); i++ )
|
||||
{ cout<<" -- Refined Corner ["<<i<<"] ("<<corners[i].x<<","<<corners[i].y<<")"<<endl; }
|
||||
}
|
||||
|
||||
|
@@ -90,4 +90,3 @@ void goodFeaturesToTrack_Demo( int, void* )
|
||||
namedWindow( source_window, WINDOW_AUTOSIZE );
|
||||
imshow( source_window, copy );
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,7 @@
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
#include "opencv2/contrib.hpp"
|
||||
#include "opencv2/bioinspired.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
|
||||
static void help(std::string errorMessage)
|
||||
@@ -95,16 +95,16 @@ int main(int argc, char* argv[]) {
|
||||
try
|
||||
{
|
||||
// create a retina instance with default parameters setup, uncomment the initialisation you wanna test
|
||||
cv::Ptr<cv::Retina> myRetina;
|
||||
cv::Ptr<cv::bioinspired::Retina> myRetina;
|
||||
|
||||
// if the last parameter is 'log', then activate log sampling (favour foveal vision and subsamples peripheral vision)
|
||||
if (useLogSampling)
|
||||
{
|
||||
myRetina = cv::createRetina(inputFrame.size(), true, cv::RETINA_COLOR_BAYER, true, 2.0, 10.0);
|
||||
myRetina = cv::bioinspired::createRetina(inputFrame.size(), true, cv::bioinspired::RETINA_COLOR_BAYER, true, 2.0, 10.0);
|
||||
}
|
||||
else// -> else allocate "classical" retina :
|
||||
{
|
||||
myRetina = cv::createRetina(inputFrame.size());
|
||||
myRetina = cv::bioinspired::createRetina(inputFrame.size());
|
||||
}
|
||||
|
||||
// save default retina parameters file in order to let you see this and maybe modify it and reload using method "setup"
|
@@ -168,5 +168,3 @@ void MyLine( Mat img, Point start, Point end )
|
||||
thickness,
|
||||
lineType );
|
||||
}
|
||||
|
||||
|
||||
|
@@ -75,4 +75,4 @@ int main(int argc, char ** argv)
|
||||
waitKey();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@@ -151,4 +151,4 @@ int main(int ac, char** av)
|
||||
<< "Tip: Open up " << filename << " with a text editor to see the serialized data." << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@@ -214,4 +214,4 @@ Mat& ScanImageAndReduceRandomAccess(Mat& I, const uchar* const table)
|
||||
}
|
||||
|
||||
return I;
|
||||
}
|
||||
}
|
||||
|
@@ -32,8 +32,8 @@ int main( int argc, char** argv )
|
||||
const char* imagename = argc > 1 ? argv[1] : "lena.jpg";
|
||||
|
||||
#ifdef DEMO_MIXED_API_USE
|
||||
Ptr<IplImage> IplI = cvLoadImage(imagename); // Ptr<T> is safe ref-counting pointer class
|
||||
if(IplI.empty())
|
||||
Ptr<IplImage> IplI(cvLoadImage(imagename)); // Ptr<T> is a safe ref-counting pointer class
|
||||
if(!IplI)
|
||||
{
|
||||
cerr << "Can not load image " << imagename << endl;
|
||||
return -1;
|
||||
|
@@ -84,4 +84,4 @@ void Sharpen(const Mat& myImage,Mat& Result)
|
||||
Result.row(Result.rows-1).setTo(Scalar(0));
|
||||
Result.col(0).setTo(Scalar(0));
|
||||
Result.col(Result.cols-1).setTo(Scalar(0));
|
||||
}
|
||||
}
|
||||
|
@@ -82,4 +82,4 @@ int main(int,char**)
|
||||
|
||||
cout << "A vector of 2D Points = " << vPoints << endl << endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@@ -430,4 +430,3 @@ Scalar getMSSIM_GPU_optimized( const Mat& i1, const Mat& i2, BufferMSSIM& b)
|
||||
}
|
||||
return mssim;
|
||||
}
|
||||
|
||||
|
@@ -27,4 +27,4 @@ int main( int argc, char** argv )
|
||||
|
||||
waitKey(0); // Wait for a keystroke in the window
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@@ -203,4 +203,4 @@ Scalar getMSSIM( const Mat& i1, const Mat& i2)
|
||||
|
||||
Scalar mssim = mean( ssim_map ); // mssim = average of ssim map
|
||||
return mssim;
|
||||
}
|
||||
}
|
||||
|
@@ -127,4 +127,4 @@ int main()
|
||||
imwrite("result.png", I); // save the Image
|
||||
imshow("SVM for Non-Linear Training Data", I); // show it to the user
|
||||
waitKey(0);
|
||||
}
|
||||
}
|
||||
|
@@ -1,14 +1,6 @@
|
||||
/**
|
||||
* @file objectDetection.cpp
|
||||
* @author A. Huaman ( based in the classic facedetect.cpp in samples/c )
|
||||
* @brief A simplified version of facedetect.cpp, show how to load a cascade classifier and how to find objects (Face + eyes) in a video stream
|
||||
*/
|
||||
#include "opencv2/objdetect/objdetect.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/core/utility.hpp"
|
||||
|
||||
#include "opencv2/highgui/highgui_c.h"
|
||||
#include "opencv2/objdetect.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
@@ -20,79 +12,73 @@ using namespace cv;
|
||||
void detectAndDisplay( Mat frame );
|
||||
|
||||
/** Global variables */
|
||||
//-- Note, either copy these two files from opencv/data/haarscascades to your current folder, or change these locations
|
||||
string face_cascade_name = "haarcascade_frontalface_alt.xml";
|
||||
string eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
|
||||
String face_cascade_name = "haarcascade_frontalface_alt.xml";
|
||||
String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
|
||||
CascadeClassifier face_cascade;
|
||||
CascadeClassifier eyes_cascade;
|
||||
string window_name = "Capture - Face detection";
|
||||
RNG rng(12345);
|
||||
String window_name = "Capture - Face detection";
|
||||
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
/** @function main */
|
||||
int main( void )
|
||||
{
|
||||
CvCapture* capture;
|
||||
Mat frame;
|
||||
VideoCapture capture;
|
||||
Mat frame;
|
||||
|
||||
//-- 1. Load the cascades
|
||||
if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
|
||||
if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
|
||||
//-- 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; };
|
||||
|
||||
//-- 2. Read the video stream
|
||||
capture = cvCaptureFromCAM( -1 );
|
||||
if( capture )
|
||||
{
|
||||
for(;;)
|
||||
//-- 2. Read the video stream
|
||||
capture.open( -1 );
|
||||
if ( ! capture.isOpened() ) { printf("--(!)Error opening video capture\n"); return -1; }
|
||||
|
||||
while ( capture.read(frame) )
|
||||
{
|
||||
frame = cv::cvarrToMat(cvQueryFrame( capture ));
|
||||
if( frame.empty() )
|
||||
{
|
||||
printf(" --(!) No captured frame -- Break!");
|
||||
break;
|
||||
}
|
||||
|
||||
//-- 3. Apply the classifier to the frame
|
||||
if( !frame.empty() )
|
||||
{ detectAndDisplay( frame ); }
|
||||
else
|
||||
{ printf(" --(!) No captured frame -- Break!"); break; }
|
||||
|
||||
int c = waitKey(10);
|
||||
if( (char)c == 'c' ) { break; }
|
||||
//-- 3. Apply the classifier to the frame
|
||||
detectAndDisplay( frame );
|
||||
|
||||
int c = waitKey(10);
|
||||
if( (char)c == 27 ) { break; } // escape
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @function detectAndDisplay
|
||||
*/
|
||||
/** @function detectAndDisplay */
|
||||
void detectAndDisplay( Mat frame )
|
||||
{
|
||||
std::vector<Rect> faces;
|
||||
Mat frame_gray;
|
||||
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(30, 30) );
|
||||
cvtColor( frame, frame_gray, COLOR_BGR2GRAY );
|
||||
equalizeHist( frame_gray, frame_gray );
|
||||
|
||||
for( size_t i = 0; i < faces.size(); i++ )
|
||||
//-- Detect faces
|
||||
face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CASCADE_SCALE_IMAGE, Size(30, 30) );
|
||||
|
||||
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 ), 2, 8, 0 );
|
||||
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 );
|
||||
|
||||
Mat faceROI = frame_gray( faces[i] );
|
||||
std::vector<Rect> eyes;
|
||||
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) );
|
||||
//-- In each face, detect eyes
|
||||
eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CASCADE_SCALE_IMAGE, Size(30, 30) );
|
||||
|
||||
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 ), 3, 8, 0 );
|
||||
}
|
||||
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 );
|
||||
}
|
||||
}
|
||||
//-- Show what you got
|
||||
imshow( window_name, frame );
|
||||
//-- Show what you got
|
||||
imshow( window_name, frame );
|
||||
}
|
||||
|
@@ -3,12 +3,9 @@
|
||||
* @author A. Huaman ( based in the classic facedetect.cpp in samples/c )
|
||||
* @brief A simplified version of facedetect.cpp, show how to load a cascade classifier and how to find objects (Face + eyes) in a video stream - Using LBP here
|
||||
*/
|
||||
#include "opencv2/objdetect/objdetect.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/core/utility.hpp"
|
||||
|
||||
#include "opencv2/highgui/highgui_c.h"
|
||||
#include "opencv2/objdetect.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
@@ -20,46 +17,43 @@ using namespace cv;
|
||||
void detectAndDisplay( Mat frame );
|
||||
|
||||
/** Global variables */
|
||||
string face_cascade_name = "lbpcascade_frontalface.xml";
|
||||
string eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
|
||||
String face_cascade_name = "lbpcascade_frontalface.xml";
|
||||
String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
|
||||
CascadeClassifier face_cascade;
|
||||
CascadeClassifier eyes_cascade;
|
||||
string window_name = "Capture - Face detection";
|
||||
|
||||
RNG rng(12345);
|
||||
|
||||
String window_name = "Capture - Face detection";
|
||||
/**
|
||||
* @function main
|
||||
*/
|
||||
int main( void )
|
||||
{
|
||||
CvCapture* capture;
|
||||
Mat frame;
|
||||
VideoCapture capture;
|
||||
Mat frame;
|
||||
|
||||
//-- 1. Load the cascade
|
||||
if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
|
||||
if( !eyes_cascade.load( eyes_cascade_name ) ){ printf("--(!)Error loading\n"); return -1; };
|
||||
//-- 1. Load the cascade
|
||||
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; };
|
||||
|
||||
//-- 2. Read the video stream
|
||||
capture = cvCaptureFromCAM( -1 );
|
||||
if( capture )
|
||||
{
|
||||
for(;;)
|
||||
//-- 2. Read the video stream
|
||||
capture.open( -1 );
|
||||
if ( ! capture.isOpened() ) { printf("--(!)Error opening video capture\n"); return -1; }
|
||||
|
||||
while ( capture.read(frame) )
|
||||
{
|
||||
frame = cv::cvarrToMat(cvQueryFrame( capture ));
|
||||
if( frame.empty() )
|
||||
{
|
||||
printf(" --(!) No captured frame -- Break!");
|
||||
break;
|
||||
}
|
||||
|
||||
//-- 3. Apply the classifier to the frame
|
||||
if( !frame.empty() )
|
||||
{ detectAndDisplay( frame ); }
|
||||
else
|
||||
{ printf(" --(!) No captured frame -- Break!"); break; }
|
||||
|
||||
int c = waitKey(10);
|
||||
if( (char)c == 'c' ) { break; }
|
||||
//-- 3. Apply the classifier to the frame
|
||||
detectAndDisplay( frame );
|
||||
|
||||
//-- bail out if escape was pressed
|
||||
int c = waitKey(10);
|
||||
if( (char)c == 27 ) { break; }
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,37 +61,37 @@ int main( void )
|
||||
*/
|
||||
void detectAndDisplay( Mat frame )
|
||||
{
|
||||
std::vector<Rect> faces;
|
||||
Mat frame_gray;
|
||||
std::vector<Rect> faces;
|
||||
Mat frame_gray;
|
||||
|
||||
cvtColor( frame, frame_gray, COLOR_BGR2GRAY );
|
||||
equalizeHist( frame_gray, 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, Size(80, 80) );
|
||||
//-- Detect faces
|
||||
face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0, Size(80, 80) );
|
||||
|
||||
for( size_t i = 0; i < faces.size(); i++ )
|
||||
for( size_t i = 0; i < faces.size(); i++ )
|
||||
{
|
||||
Mat faceROI = frame_gray( faces[i] );
|
||||
std::vector<Rect> eyes;
|
||||
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) );
|
||||
if( eyes.size() == 2)
|
||||
{
|
||||
//-- Draw the face
|
||||
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, 0 ), 2, 8, 0 );
|
||||
//-- In each face, detect eyes
|
||||
eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CASCADE_SCALE_IMAGE, Size(30, 30) );
|
||||
if( eyes.size() == 2)
|
||||
{
|
||||
//-- Draw the face
|
||||
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, 0 ), 2, 8, 0 );
|
||||
|
||||
for( size_t j = 0; j < eyes.size(); j++ )
|
||||
{ //-- Draw the eyes
|
||||
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, 255 ), 3, 8, 0 );
|
||||
}
|
||||
}
|
||||
for( size_t j = 0; j < eyes.size(); j++ )
|
||||
{ //-- Draw the eyes
|
||||
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, 255 ), 3, 8, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//-- Show what you got
|
||||
imshow( window_name, frame );
|
||||
//-- Show what you got
|
||||
imshow( window_name, frame );
|
||||
}
|
||||
|
@@ -152,7 +152,7 @@ int main(int ac, char ** av)
|
||||
|
||||
Mat train_desc, query_desc;
|
||||
const int DESIRED_FTRS = 500;
|
||||
GridAdaptedFeatureDetector detector(new FastFeatureDetector(10, true), DESIRED_FTRS, 4, 4);
|
||||
GridAdaptedFeatureDetector detector(makePtr<FastFeatureDetector>(10, true), DESIRED_FTRS, 4, 4);
|
||||
|
||||
Mat H_prev = Mat::eye(3, 3, CV_32FC1);
|
||||
for (;;)
|
||||
|
@@ -193,7 +193,7 @@ public:
|
||||
|
||||
virtual Ptr<ImageMotionEstimatorBase> build()
|
||||
{
|
||||
MotionEstimatorRansacL2 *est = new MotionEstimatorRansacL2(motionModel(arg(prefix + "model")));
|
||||
Ptr<MotionEstimatorRansacL2> est = makePtr<MotionEstimatorRansacL2>(motionModel(arg(prefix + "model")));
|
||||
|
||||
RansacParams ransac = est->ransacParams();
|
||||
if (arg(prefix + "subset") != "auto")
|
||||
@@ -205,10 +205,10 @@ public:
|
||||
|
||||
est->setMinInlierRatio(argf(prefix + "min-inlier-ratio"));
|
||||
|
||||
Ptr<IOutlierRejector> outlierRejector = new NullOutlierRejector();
|
||||
Ptr<IOutlierRejector> outlierRejector = makePtr<NullOutlierRejector>();
|
||||
if (arg(prefix + "local-outlier-rejection") == "yes")
|
||||
{
|
||||
TranslationBasedLocalOutlierRejector *tblor = new TranslationBasedLocalOutlierRejector();
|
||||
Ptr<TranslationBasedLocalOutlierRejector> tblor = makePtr<TranslationBasedLocalOutlierRejector>();
|
||||
RansacParams ransacParams = tblor->ransacParams();
|
||||
if (arg(prefix + "thresh") != "auto")
|
||||
ransacParams.thresh = argf(prefix + "thresh");
|
||||
@@ -219,14 +219,14 @@ public:
|
||||
#if defined(HAVE_OPENCV_GPUIMGPROC) && defined(HAVE_OPENCV_GPU) && defined(HAVE_OPENCV_GPUOPTFLOW)
|
||||
if (gpu)
|
||||
{
|
||||
KeypointBasedMotionEstimatorGpu *kbest = new KeypointBasedMotionEstimatorGpu(est);
|
||||
Ptr<KeypointBasedMotionEstimatorGpu> kbest = makePtr<KeypointBasedMotionEstimatorGpu>(est);
|
||||
kbest->setOutlierRejector(outlierRejector);
|
||||
return kbest;
|
||||
}
|
||||
#endif
|
||||
|
||||
KeypointBasedMotionEstimator *kbest = new KeypointBasedMotionEstimator(est);
|
||||
kbest->setDetector(new GoodFeaturesToTrackDetector(argi(prefix + "nkps")));
|
||||
Ptr<KeypointBasedMotionEstimator> kbest = makePtr<KeypointBasedMotionEstimator>(est);
|
||||
kbest->setDetector(makePtr<GoodFeaturesToTrackDetector>(argi(prefix + "nkps")));
|
||||
kbest->setOutlierRejector(outlierRejector);
|
||||
return kbest;
|
||||
}
|
||||
@@ -244,12 +244,12 @@ public:
|
||||
|
||||
virtual Ptr<ImageMotionEstimatorBase> build()
|
||||
{
|
||||
MotionEstimatorL1 *est = new MotionEstimatorL1(motionModel(arg(prefix + "model")));
|
||||
Ptr<MotionEstimatorL1> est = makePtr<MotionEstimatorL1>(motionModel(arg(prefix + "model")));
|
||||
|
||||
Ptr<IOutlierRejector> outlierRejector = new NullOutlierRejector();
|
||||
Ptr<IOutlierRejector> outlierRejector = makePtr<NullOutlierRejector>();
|
||||
if (arg(prefix + "local-outlier-rejection") == "yes")
|
||||
{
|
||||
TranslationBasedLocalOutlierRejector *tblor = new TranslationBasedLocalOutlierRejector();
|
||||
Ptr<TranslationBasedLocalOutlierRejector> tblor = makePtr<TranslationBasedLocalOutlierRejector>();
|
||||
RansacParams ransacParams = tblor->ransacParams();
|
||||
if (arg(prefix + "thresh") != "auto")
|
||||
ransacParams.thresh = argf(prefix + "thresh");
|
||||
@@ -260,14 +260,14 @@ public:
|
||||
#if defined(HAVE_OPENCV_GPUIMGPROC) && defined(HAVE_OPENCV_GPU) && defined(HAVE_OPENCV_GPUOPTFLOW)
|
||||
if (gpu)
|
||||
{
|
||||
KeypointBasedMotionEstimatorGpu *kbest = new KeypointBasedMotionEstimatorGpu(est);
|
||||
Ptr<KeypointBasedMotionEstimatorGpu> kbest = makePtr<KeypointBasedMotionEstimatorGpu>(est);
|
||||
kbest->setOutlierRejector(outlierRejector);
|
||||
return kbest;
|
||||
}
|
||||
#endif
|
||||
|
||||
KeypointBasedMotionEstimator *kbest = new KeypointBasedMotionEstimator(est);
|
||||
kbest->setDetector(new GoodFeaturesToTrackDetector(argi(prefix + "nkps")));
|
||||
Ptr<KeypointBasedMotionEstimator> kbest = makePtr<KeypointBasedMotionEstimator>(est);
|
||||
kbest->setDetector(makePtr<GoodFeaturesToTrackDetector>(argi(prefix + "nkps")));
|
||||
kbest->setOutlierRejector(outlierRejector);
|
||||
return kbest;
|
||||
}
|
||||
@@ -363,7 +363,7 @@ int main(int argc, const char **argv)
|
||||
|
||||
// get source video parameters
|
||||
|
||||
VideoFileSource *source = new VideoFileSource(inputPath);
|
||||
Ptr<VideoFileSource> source = makePtr<VideoFileSource>(inputPath);
|
||||
cout << "frame count (rough): " << source->count() << endl;
|
||||
if (arg("fps") == "auto")
|
||||
outputFps = source->fps();
|
||||
@@ -374,15 +374,15 @@ int main(int argc, const char **argv)
|
||||
|
||||
Ptr<IMotionEstimatorBuilder> motionEstBuilder;
|
||||
if (arg("lin-prog-motion-est") == "yes")
|
||||
motionEstBuilder = new MotionEstimatorL1Builder(cmd, arg("gpu") == "yes");
|
||||
motionEstBuilder.reset(new MotionEstimatorL1Builder(cmd, arg("gpu") == "yes"));
|
||||
else
|
||||
motionEstBuilder = new MotionEstimatorRansacL2Builder(cmd, arg("gpu") == "yes");
|
||||
motionEstBuilder.reset(new MotionEstimatorRansacL2Builder(cmd, arg("gpu") == "yes"));
|
||||
|
||||
Ptr<IMotionEstimatorBuilder> wsMotionEstBuilder;
|
||||
if (arg("ws-lp") == "yes")
|
||||
wsMotionEstBuilder = new MotionEstimatorL1Builder(cmd, arg("gpu") == "yes", "ws-");
|
||||
wsMotionEstBuilder.reset(new MotionEstimatorL1Builder(cmd, arg("gpu") == "yes", "ws-"));
|
||||
else
|
||||
wsMotionEstBuilder = new MotionEstimatorRansacL2Builder(cmd, arg("gpu") == "yes", "ws-");
|
||||
wsMotionEstBuilder.reset(new MotionEstimatorRansacL2Builder(cmd, arg("gpu") == "yes", "ws-"));
|
||||
|
||||
// determine whether we must use one pass or two pass stabilizer
|
||||
bool isTwoPass =
|
||||
@@ -400,7 +400,7 @@ int main(int argc, const char **argv)
|
||||
|
||||
if (arg("lin-prog-stab") == "yes")
|
||||
{
|
||||
LpMotionStabilizer *stab = new LpMotionStabilizer();
|
||||
Ptr<LpMotionStabilizer> stab = makePtr<LpMotionStabilizer>();
|
||||
stab->setFrameSize(Size(source->width(), source->height()));
|
||||
stab->setTrimRatio(arg("lps-trim-ratio") == "auto" ? argf("trim-ratio") : argf("lps-trim-ratio"));
|
||||
stab->setWeight1(argf("lps-w1"));
|
||||
@@ -410,18 +410,18 @@ int main(int argc, const char **argv)
|
||||
twoPassStabilizer->setMotionStabilizer(stab);
|
||||
}
|
||||
else if (arg("stdev") == "auto")
|
||||
twoPassStabilizer->setMotionStabilizer(new GaussianMotionFilter(argi("radius")));
|
||||
twoPassStabilizer->setMotionStabilizer(makePtr<GaussianMotionFilter>(argi("radius")));
|
||||
else
|
||||
twoPassStabilizer->setMotionStabilizer(new GaussianMotionFilter(argi("radius"), argf("stdev")));
|
||||
twoPassStabilizer->setMotionStabilizer(makePtr<GaussianMotionFilter>(argi("radius"), argf("stdev")));
|
||||
|
||||
// init wobble suppressor if necessary
|
||||
|
||||
if (arg("wobble-suppress") == "yes")
|
||||
{
|
||||
MoreAccurateMotionWobbleSuppressorBase *ws = new MoreAccurateMotionWobbleSuppressor();
|
||||
Ptr<MoreAccurateMotionWobbleSuppressorBase> ws = makePtr<MoreAccurateMotionWobbleSuppressor>();
|
||||
if (arg("gpu") == "yes")
|
||||
#ifdef HAVE_OPENCV_GPU
|
||||
ws = new MoreAccurateMotionWobbleSuppressorGpu();
|
||||
ws = makePtr<MoreAccurateMotionWobbleSuppressorGpu>();
|
||||
#else
|
||||
throw runtime_error("OpenCV is built without GPU support");
|
||||
#endif
|
||||
@@ -433,12 +433,12 @@ int main(int argc, const char **argv)
|
||||
MotionModel model = ws->motionEstimator()->motionModel();
|
||||
if (arg("load-motions2") != "no")
|
||||
{
|
||||
ws->setMotionEstimator(new FromFileMotionReader(arg("load-motions2")));
|
||||
ws->setMotionEstimator(makePtr<FromFileMotionReader>(arg("load-motions2")));
|
||||
ws->motionEstimator()->setMotionModel(model);
|
||||
}
|
||||
if (arg("save-motions2") != "no")
|
||||
{
|
||||
ws->setMotionEstimator(new ToFileMotionWriter(arg("save-motions2"), ws->motionEstimator()));
|
||||
ws->setMotionEstimator(makePtr<ToFileMotionWriter>(arg("save-motions2"), ws->motionEstimator()));
|
||||
ws->motionEstimator()->setMotionModel(model);
|
||||
}
|
||||
}
|
||||
@@ -450,26 +450,26 @@ int main(int argc, const char **argv)
|
||||
OnePassStabilizer *onePassStabilizer = new OnePassStabilizer();
|
||||
stabilizer = onePassStabilizer;
|
||||
if (arg("stdev") == "auto")
|
||||
onePassStabilizer->setMotionFilter(new GaussianMotionFilter(argi("radius")));
|
||||
onePassStabilizer->setMotionFilter(makePtr<GaussianMotionFilter>(argi("radius")));
|
||||
else
|
||||
onePassStabilizer->setMotionFilter(new GaussianMotionFilter(argi("radius"), argf("stdev")));
|
||||
onePassStabilizer->setMotionFilter(makePtr<GaussianMotionFilter>(argi("radius"), argf("stdev")));
|
||||
}
|
||||
|
||||
stabilizer->setFrameSource(source);
|
||||
stabilizer->setMotionEstimator(motionEstBuilder->build());
|
||||
|
||||
// cast stabilizer to simple frame source interface to read stabilized frames
|
||||
stabilizedFrames = dynamic_cast<IFrameSource*>(stabilizer);
|
||||
stabilizedFrames.reset(dynamic_cast<IFrameSource*>(stabilizer));
|
||||
|
||||
MotionModel model = stabilizer->motionEstimator()->motionModel();
|
||||
if (arg("load-motions") != "no")
|
||||
{
|
||||
stabilizer->setMotionEstimator(new FromFileMotionReader(arg("load-motions")));
|
||||
stabilizer->setMotionEstimator(makePtr<FromFileMotionReader>(arg("load-motions")));
|
||||
stabilizer->motionEstimator()->setMotionModel(model);
|
||||
}
|
||||
if (arg("save-motions") != "no")
|
||||
{
|
||||
stabilizer->setMotionEstimator(new ToFileMotionWriter(arg("save-motions"), stabilizer->motionEstimator()));
|
||||
stabilizer->setMotionEstimator(makePtr<ToFileMotionWriter>(arg("save-motions"), stabilizer->motionEstimator()));
|
||||
stabilizer->motionEstimator()->setMotionModel(model);
|
||||
}
|
||||
|
||||
@@ -478,7 +478,7 @@ int main(int argc, const char **argv)
|
||||
// init deblurer
|
||||
if (arg("deblur") == "yes")
|
||||
{
|
||||
WeightingDeblurer *deblurer = new WeightingDeblurer();
|
||||
Ptr<WeightingDeblurer> deblurer = makePtr<WeightingDeblurer>();
|
||||
deblurer->setRadius(argi("radius"));
|
||||
deblurer->setSensitivity(argf("deblur-sens"));
|
||||
stabilizer->setDeblurer(deblurer);
|
||||
@@ -503,22 +503,22 @@ int main(int argc, const char **argv)
|
||||
Ptr<InpainterBase> inpainters_(inpainters);
|
||||
if (arg("mosaic") == "yes")
|
||||
{
|
||||
ConsistentMosaicInpainter *inp = new ConsistentMosaicInpainter();
|
||||
Ptr<ConsistentMosaicInpainter> inp = makePtr<ConsistentMosaicInpainter>();
|
||||
inp->setStdevThresh(argf("mosaic-stdev"));
|
||||
inpainters->pushBack(inp);
|
||||
}
|
||||
if (arg("motion-inpaint") == "yes")
|
||||
{
|
||||
MotionInpainter *inp = new MotionInpainter();
|
||||
Ptr<MotionInpainter> inp = makePtr<MotionInpainter>();
|
||||
inp->setDistThreshold(argf("mi-dist-thresh"));
|
||||
inpainters->pushBack(inp);
|
||||
}
|
||||
if (arg("color-inpaint") == "average")
|
||||
inpainters->pushBack(new ColorAverageInpainter());
|
||||
inpainters->pushBack(makePtr<ColorAverageInpainter>());
|
||||
else if (arg("color-inpaint") == "ns")
|
||||
inpainters->pushBack(new ColorInpainter(INPAINT_NS, argd("ci-radius")));
|
||||
inpainters->pushBack(makePtr<ColorInpainter>(int(INPAINT_NS), argd("ci-radius")));
|
||||
else if (arg("color-inpaint") == "telea")
|
||||
inpainters->pushBack(new ColorInpainter(INPAINT_TELEA, argd("ci-radius")));
|
||||
inpainters->pushBack(makePtr<ColorInpainter>(int(INPAINT_TELEA), argd("ci-radius")));
|
||||
else if (arg("color-inpaint") != "no")
|
||||
throw runtime_error("unknown color inpainting method: " + arg("color-inpaint"));
|
||||
if (!inpainters->empty())
|
||||
|
Reference in New Issue
Block a user