Merge branch '2.4'

This commit is contained in:
Andrey Kamaev
2013-03-21 20:59:18 +04:00
276 changed files with 11834 additions and 5170 deletions

View File

@@ -16,7 +16,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
ocv_include_directories("${OpenCV_SOURCE_DIR}/include")#for opencv.hpp
ocv_include_modules(${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
if (HAVE_opencv_gpu)
if(HAVE_opencv_gpu)
ocv_include_directories("${OpenCV_SOURCE_DIR}/modules/gpu/include")
endif()
@@ -41,7 +41,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
add_executable(${the_target} ${srcs})
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_CPP_SAMPLES_REQUIRED_DEPS})
if (HAVE_opencv_gpu)
if(HAVE_opencv_gpu)
target_link_libraries(${the_target} opencv_gpu)
endif()

View File

@@ -131,7 +131,7 @@ int build_rtrees_classifier( char* data_filename,
printf( "Could not read the classifier %s\n", filename_to_load );
return -1;
}
printf( "The classifier %s is loaded.\n", data_filename );
printf( "The classifier %s is loaded.\n", filename_to_load );
}
else
{
@@ -262,7 +262,7 @@ int build_boost_classifier( char* data_filename,
printf( "Could not read the classifier %s\n", filename_to_load );
return -1;
}
printf( "The classifier %s is loaded.\n", data_filename );
printf( "The classifier %s is loaded.\n", filename_to_load );
}
else
{
@@ -403,7 +403,7 @@ int build_mlp_classifier( char* data_filename,
printf( "Could not read the classifier %s\n", filename_to_load );
return -1;
}
printf( "The classifier %s is loaded.\n", data_filename );
printf( "The classifier %s is loaded.\n", filename_to_load );
}
else
{
@@ -639,10 +639,11 @@ int build_nbayes_classifier( char* data_filename )
}
static
int build_svm_classifier( char* data_filename )
int build_svm_classifier( char* data_filename, const char* filename_to_save, const char* filename_to_load )
{
CvMat* data = 0;
CvMat* responses = 0;
CvMat* train_resp = 0;
CvMat train_data;
int nsamples_all = 0, ntrain_samples = 0;
int var_count;
@@ -666,13 +667,29 @@ int build_svm_classifier( char* data_filename )
ntrain_samples = (int)(nsamples_all*0.1);
var_count = data->cols;
// train classifier
printf( "Training the classifier (may take a few minutes)...\n");
cvGetRows( data, &train_data, 0, ntrain_samples );
CvMat* train_resp = cvCreateMat( ntrain_samples, 1, CV_32FC1);
for (int i = 0; i < ntrain_samples; i++)
train_resp->data.fl[i] = responses->data.fl[i];
svm.train(&train_data, train_resp, 0, 0, param);
// Create or load Random Trees classifier
if( filename_to_load )
{
// load classifier from the specified file
svm.load( filename_to_load );
ntrain_samples = 0;
if( svm.get_var_count() == 0 )
{
printf( "Could not read the classifier %s\n", filename_to_load );
return -1;
}
printf( "The classifier %s is loaded.\n", filename_to_load );
}
else
{
// train classifier
printf( "Training the classifier (may take a few minutes)...\n");
cvGetRows( data, &train_data, 0, ntrain_samples );
train_resp = cvCreateMat( ntrain_samples, 1, CV_32FC1);
for (int i = 0; i < ntrain_samples; i++)
train_resp->data.fl[i] = responses->data.fl[i];
svm.train(&train_data, train_resp, 0, 0, param);
}
// classification
std::vector<float> _sample(var_count * (nsamples_all - ntrain_samples));
@@ -691,7 +708,10 @@ int build_svm_classifier( char* data_filename )
CvMat *result = cvCreateMat(1, nsamples_all - ntrain_samples, CV_32FC1);
printf("Classification (may take a few minutes)...\n");
double t = (double)cvGetTickCount();
svm.predict(&sample, result);
t = (double)cvGetTickCount() - t;
printf("Prediction type: %gms\n", t/(cvGetTickFrequency()*1000.));
int true_resp = 0;
for (int i = 0; i < nsamples_all - ntrain_samples; i++)
@@ -702,6 +722,9 @@ int build_svm_classifier( char* data_filename )
printf("true_resp = %f%%\n", (float)true_resp / (nsamples_all - ntrain_samples) * 100);
if( filename_to_save )
svm.save( filename_to_save );
cvReleaseMat( &train_resp );
cvReleaseMat( &result );
cvReleaseMat( &data );
@@ -772,7 +795,7 @@ int main( int argc, char *argv[] )
method == 4 ?
build_nbayes_classifier( data_filename) :
method == 5 ?
build_svm_classifier( data_filename ):
build_svm_classifier( data_filename, filename_to_save, filename_to_load ):
-1) < 0)
{
help();

View File

@@ -356,7 +356,7 @@ int main(int argc, char* argv[])
Ptr<FeaturesFinder> finder;
if (features_type == "surf")
{
#ifdef HAVE_OPENCV_GPU
#if defined(HAVE_OPENCV_NONFREE) && defined(HAVE_OPENCV_GPU)
if (try_gpu && gpu::getCudaEnabledDeviceCount() > 0)
finder = new SurfFeaturesFinderGpu();
else