lot's of changes; nonfree & photo modules added; SIFT & SURF -> nonfree module; Inpainting -> photo; refactored features2d (ORB is still failing tests), optimized brute-force matcher and made it non-template.

This commit is contained in:
Vadim Pisarevsky
2012-03-15 14:36:01 +00:00
parent 6300215b94
commit 957e80abbd
99 changed files with 6719 additions and 7240 deletions

View File

@@ -1,134 +1,86 @@
/* This sample code was originally provided by Liu Liu
* Copyright<EFBFBD> 2009, Liu Liu All rights reserved.
* Copyright (C) 2009, Liu Liu All rights reserved.
*/
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
void help()
{
printf("\nThis program demonstrates the Maximal Extremal Region interest point detector.\n"
"It finds the most stable (in size) dark and white regions as a threshold is increased.\n"
"\nCall:\n"
"./mser_sample <path_and_image_filename, Default is 'puzzle.png'>\n\n");
cout << "\nThis program demonstrates the Maximal Extremal Region interest point detector.\n"
"It finds the most stable (in size) dark and white regions as a threshold is increased.\n"
"\nCall:\n"
"./mser_sample <path_and_image_filename, Default is 'puzzle.png'>\n\n";
}
static CvScalar colors[] =
static const Vec3b bcolors[] =
{
{{0,0,255}},
{{0,128,255}},
{{0,255,255}},
{{0,255,0}},
{{255,128,0}},
{{255,255,0}},
{{255,0,0}},
{{255,0,255}},
{{255,255,255}},
{{196,255,255}},
{{255,255,196}}
Vec3b(0,0,255),
Vec3b(0,128,255),
Vec3b(0,255,255),
Vec3b(0,255,0),
Vec3b(255,128,0),
Vec3b(255,255,0),
Vec3b(255,0,0),
Vec3b(255,0,255),
Vec3b(255,255,255)
};
static uchar bcolors[][3] =
{
{0,0,255},
{0,128,255},
{0,255,255},
{0,255,0},
{255,128,0},
{255,255,0},
{255,0,0},
{255,0,255},
{255,255,255}
};
int main( int argc, char** argv )
{
char path[1024];
IplImage* img;
string path;
Mat img0, img, yuv, gray, ellipses;
help();
if (argc!=2)
img0 = imread( argc != 2 ? "puzzle.png" : argv[1], 1 );
if( img0.empty() )
{
if( argc != 2 )
cout << "\nUsage: mser_sample <path_to_image>\n";
else
cout << "Unable to load image " << argv[1] << endl;
return 0;
}
cvtColor(img0, yuv, COLOR_BGR2YCrCb);
cvtColor(img0, gray, COLOR_BGR2GRAY);
cvtColor(gray, img, COLOR_GRAY2BGR);
img.copyTo(ellipses);
vector<vector<Point> > contours;
double t = (double)getTickCount();
MSER()(yuv, contours);
t = (double)getTickCount() - t;
printf( "MSER extracted %d contours in %g ms.\n", (int)contours.size(),
t*1000./getTickFrequency() );
// draw mser's with different colors
for( int i = (int)contours.size()-1; i >= 0; i-- )
{
strcpy(path,"puzzle.png");
img = cvLoadImage( path, CV_LOAD_IMAGE_GRAYSCALE );
if (!img)
const vector<Point>& r = contours[i];
for ( int j = 0; j < (int)r.size(); j++ )
{
printf("\nUsage: mser_sample <path_to_image>\n");
return 0;
Point pt = r[j];
img.at<Vec3b>(r[j]) = bcolors[i%9];
}
// find ellipse (it seems cvfitellipse2 have error or sth?)
RotatedRect box = fitEllipse( r );
box.angle=(float)CV_PI/2-box.angle;
ellipse( ellipses, box, Scalar(196,255,255), 2 );
}
else
{
strcpy(path,argv[1]);
img = cvLoadImage( path, CV_LOAD_IMAGE_GRAYSCALE );
}
if (!img)
{
printf("Unable to load image %s\n",path);
return 0;
}
IplImage* rsp = cvLoadImage( path, CV_LOAD_IMAGE_COLOR );
IplImage* ellipses = cvCloneImage(rsp);
cvCvtColor(img,ellipses,CV_GRAY2BGR);
CvSeq* contours;
CvMemStorage* storage= cvCreateMemStorage();
IplImage* hsv = cvCreateImage( cvGetSize( rsp ), IPL_DEPTH_8U, 3 );
cvCvtColor( rsp, hsv, CV_BGR2YCrCb );
CvMSERParams params = cvMSERParams();//cvMSERParams( 5, 60, cvRound(.2*img->width*img->height), .25, .2 );
double t = (double)cvGetTickCount();
cvExtractMSER( hsv, NULL, &contours, storage, params );
t = cvGetTickCount() - t;
printf( "MSER extracted %d contours in %g ms.\n", contours->total, t/((double)cvGetTickFrequency()*1000.) );
uchar* rsptr = (uchar*)rsp->imageData;
// draw mser with different color
for ( int i = contours->total-1; i >= 0; i-- )
{
CvSeq* r = *(CvSeq**)cvGetSeqElem( contours, i );
for ( int j = 0; j < r->total; j++ )
{
CvPoint* pt = CV_GET_SEQ_ELEM( CvPoint, r, j );
rsptr[pt->x*3+pt->y*rsp->widthStep] = bcolors[i%9][2];
rsptr[pt->x*3+1+pt->y*rsp->widthStep] = bcolors[i%9][1];
rsptr[pt->x*3+2+pt->y*rsp->widthStep] = bcolors[i%9][0];
}
}
// find ellipse ( it seems cvfitellipse2 have error or sth?
for ( int i = 0; i < contours->total; i++ )
{
CvContour* r = *(CvContour**)cvGetSeqElem( contours, i );
CvBox2D box = cvFitEllipse2( r );
box.angle=(float)CV_PI/2-box.angle;
if ( r->color > 0 )
cvEllipseBox( ellipses, box, colors[9], 2 );
else
cvEllipseBox( ellipses, box, colors[2], 2 );
}
cvSaveImage( "rsp.png", rsp );
cvNamedWindow( "original", 0 );
cvShowImage( "original", img );
cvNamedWindow( "response", 0 );
cvShowImage( "response", rsp );
cvNamedWindow( "ellipses", 0 );
cvShowImage( "ellipses", ellipses );
cvWaitKey(0);
cvDestroyWindow( "original" );
cvDestroyWindow( "response" );
cvDestroyWindow( "ellipses" );
cvReleaseImage(&rsp);
cvReleaseImage(&img);
cvReleaseImage(&ellipses);
imshow( "original", img0 );
imshow( "response", img );
imshow( "ellipses", ellipses );
waitKey(0);
}