本文整理汇总了C++中CFeatureList::size方法的典型用法代码示例。如果您正苦于以下问题:C++ CFeatureList::size方法的具体用法?C++ CFeatureList::size怎么用?C++ CFeatureList::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFeatureList
的用法示例。
在下文中一共展示了CFeatureList::size方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: int
inline void trackFeatures_addNewFeats<CFeatureList>(CFeatureList &featureList,const TSimpleFeatureList &new_feats, const std::vector<size_t> &sorted_indices, const size_t nNewToCheck,const size_t maxNumFeatures,const float minimum_KLT_response_to_add,const double threshold_sqr_dist_to_add_new,const size_t patchSize,const CImage &cur_gray, TFeatureID &max_feat_ID_at_input)
{
const TImageSize imgSize = cur_gray.getSize();
const int offset = (int)patchSize/2 + 1;
const int w_off = int(imgSize.x - offset);
const int h_off = int(imgSize.y - offset);
for (size_t i=0;i<nNewToCheck && featureList.size()<maxNumFeatures;i++)
{
const TSimpleFeature &feat = new_feats[ sorted_indices[i] ];
if (feat.response<minimum_KLT_response_to_add) continue;
double min_dist_sqr = square(10000);
if (!featureList.empty())
{
//m_timlog.enter("[CGenericFeatureTracker] add new features.kdtree");
min_dist_sqr = featureList.kdTreeClosestPoint2DsqrError(feat.pt.x,feat.pt.y );
//m_timlog.leave("[CGenericFeatureTracker] add new features.kdtree");
}
if (min_dist_sqr>threshold_sqr_dist_to_add_new &&
feat.pt.x > offset &&
feat.pt.y > offset &&
feat.pt.x < w_off &&
feat.pt.y < h_off )
{
// Add new feature:
CFeaturePtr ft = CFeature::Create();
ft->type = featFAST;
ft->ID = ++max_feat_ID_at_input;
ft->x = feat.pt.x;
ft->y = feat.pt.y;
ft->response = feat.response;
ft->orientation = 0;
ft->scale = 1;
ft->patchSize = patchSize; // The size of the feature patch
if( patchSize > 0 )
cur_gray.extract_patch(
ft->patch,
round( ft->x ) - offset,
round( ft->y ) - offset,
patchSize,
patchSize ); // Image patch surronding the feature
featureList.push_back( ft );
}
}
} // end of trackFeatures_addNewFeats<>
示例2: TestExtractFeaturesTile
// ------------------------------------------------------
// TestCapture
// ------------------------------------------------------
void TestExtractFeaturesTile()
{
CDisplayWindow wind1,wind2;
CFeatureExtraction fExt;
CFeatureList featsHarris;
CImage img;
string the_img = myDataDir+string("test_image.jpg");
if (!img.loadFromFile(the_img ))
{
cerr << "Cannot load " << the_img << endl;
return;
}
cout << "Loaded test image: " << the_img << endl;
CTicTac tictac;
cout << "Extracting Harris features (tiled)... [f_harris_tiled.txt]";
fExt.options.featsType = featHarris;
fExt.options.harrisOptions.tile_image = true;
tictac.Tic();
fExt.detectFeatures( img, featsHarris );
cout << format(" %.03fms",tictac.Tac()*1000) << endl;
cout << "Detected " << featsHarris.size() << " features in " << endl;
featsHarris.saveToTextFile("f_harris_tiled.txt");
wind1.setWindowTitle("Harris detected features (Tiled image)");
wind1.showTiledImageAndPoints( img, featsHarris );
cout << "Extracting Harris features... [f_harris.txt]";
fExt.options.harrisOptions.tile_image = false;
tictac.Tic();
fExt.detectFeatures( img, featsHarris );
cout << format(" %.03fms",tictac.Tac()*1000) << endl;
featsHarris.saveToTextFile("f_harris.txt");
wind2.setWindowTitle("Harris detected features");
wind2.showTiledImageAndPoints( img, featsHarris );
mrpt::system::pause();
return;
}
示例3: benchmark_detectFeatures
double benchmark_detectFeatures(int N, [[maybe_unused]] int h)
{
// Generate a random image
CImage img;
getTestImage(0, img);
CFeatureExtraction fExt;
fExt.profiler.enable();
fExt.options.featsType = FEAT_TYPE;
for (int i = 0; i < N; i++)
{
CFeatureList fs;
fExt.detectFeatures(img, fs);
if (i == (N - 1))
std::cout << "(" << std::setw(4) << fs.size() << " found)\n";
}
return fExt.profiler.getMeanTime("detectFeatures");
}
示例4: extractFeaturesSIFT
/************************************************************************************************
* extractFeaturesSIFT *
************************************************************************************************/
void CFeatureExtraction::extractFeaturesSIFT(
const CImage &img,
CFeatureList &feats,
unsigned int init_ID,
unsigned int nDesiredFeatures,
const TImageROI &ROI) const
{
bool usingROI = false;
if( ROI.xMin != 0 || ROI.xMax != 0 || ROI.yMin != 0 || ROI.yMax != 0 )
usingROI = true; // A ROI has been defined
// ROI can not be managed properly (yet) with these method, so we extract a subimage
// use a smart pointer so we just copy the pointer if the image is grayscale, or we'll create a new one if it was RGB:
CImage img_grayscale(img, FAST_REF_OR_CONVERT_TO_GRAY); // Was: auxImgPtr;
if( usingROI )
{
ASSERT_( ROI.xMin >= 0 && ROI.xMin < ROI.xMax && ROI.xMax < img.getWidth() && ROI.yMin >= 0 && ROI.yMax < img.getHeight() && ROI.yMin < ROI.yMax );
CImage auximg;
img_grayscale.extract_patch( auximg, ROI.xMin, ROI.yMin, ROI.xMax-ROI.xMin+1, ROI.yMax-ROI.yMin+1 ); // Subimage in "auxImg"
img_grayscale.swap(auximg);
}
switch( options.SIFTOptions.implementation )
{
// --------------------------------------------------------------------------------------
// Binary in C# -> OPTIONAL: Feature position already computed
// --------------------------------------------------------------------------------------
case CSBinary:
{
#ifdef MRPT_OS_WINDOWS
char filImg[2000],filOut[2000],filFeat[2000];
char paramImg[2000];
GetTempPathA(1000,filOut); os::strcat(filOut,1000,"temp_out.txt"); // OUTPUT FILE
GetTempPathA(1000,filImg); os::strcat(filImg,1000,"temp_img.bmp"); // INPUT IMAGE (BMP) FOR BINARY IN (C#)
bool onlyDesc = feats.size() > 0 ? true : false;
if( onlyDesc )
{
GetTempPathA(1000,filFeat); os::strcat(filFeat,1000,"temp_feats.txt"); // KEYPOINTS INPUT FILE
CMatrix listPoints(feats.size(),2);
for (size_t i= 0;i<feats.size();i++)
{
listPoints(i,0) = feats[i]->x;
listPoints(i,1) = feats[i]->y;
}
listPoints.saveToTextFile( filFeat, MATRIX_FORMAT_FIXED /*Float format*/ );
} // end if
// -------------------------------------------
// CALL TO "extractSIFT.exe"
// -------------------------------------------
img_grayscale.saveToFile( filImg );
// ------------------------------------
// Version with "CreateProcess":
// ------------------------------------
os::strcpy(paramImg,1000,"extractSIFT.exe -i"); os::strcat(paramImg,1000,filImg);
os::strcat(paramImg,1000," -f"); os::strcat(paramImg,1000,filOut);
os::strcat(paramImg,1000," -l"); os::strcat(paramImg,1000,filFeat);
// ------------------------------------
// Launch process
// ------------------------------------
bool ret = mrpt::system::launchProcess( paramImg );
if( !ret )
THROW_EXCEPTION( "[extractFeaturesSIFT] Could not launch external process... (extractSIFT.exe)" )
// Process Results
CFeatureList::iterator itFeat = feats.begin();
size_t nFeats;
CMatrix aux;
aux.loadFromTextFile( filOut );
std::cout << "[computeSiftFeatures] " << aux.getRowCount() << " features." << std::endl;
if( onlyDesc )
nFeats = feats.size();
else
{
nFeats = aux.getRowCount();
feats.resize( nFeats );
}
for( size_t i = 0;
itFeat != feats.end();
i++, itFeat++)
{
(*itFeat)->type = featSIFT;
(*itFeat)->x = usingROI ? aux(i,0) + ROI.xMin : aux(i,0);
(*itFeat)->y = usingROI ? aux(i,1) + ROI.yMin : aux(i,1);
(*itFeat)->orientation = aux(i,2);
(*itFeat)->scale = aux(i,3);
//.........这里部分代码省略.........
示例5: internal_computeSiftDescriptors
// Compute SIFT descriptors on a set of already localized points
void CFeatureExtraction::internal_computeSiftDescriptors( const CImage &in_img,
CFeatureList &in_features) const
{
ASSERT_( in_features.size() > 0 );
switch( options.SIFTOptions.implementation )
{
case CSBinary:
{
#ifdef MRPT_OS_WINDOWS
char filImg[2000],filOut[2000],filFeat[2000];
char paramImg[2000];
CFeatureList::iterator feat;
// Save to temporary file
GetTempPathA(1000,filImg); os::strcat( filImg, 1000, "temp_img.bmp" );
GetTempPathA(1000,filOut); os::strcat( filOut,1000, "temp_feats.txt" );
GetTempPathA(1000,filFeat); os::strcat( filFeat, 1000, "temp_KLT_feats.txt" );
// Fill the input file
FILE *fout = os::fopen( filFeat,"wt");
for(feat = in_features.begin(); feat != in_features.end(); feat++)
os::fprintf( fout, "%.6f %.6f\n", (*feat)->x, (*feat)->y );
os::fclose(fout);
// -------------------------------------------
// CALL TO "extractSIFT.exe"
// -------------------------------------------
in_img.saveToFile( filImg );
// Version with "CreateProcess":
// ------------------------------------
os::strcpy(paramImg,1000,"extractSIFT.exe -i"); os::strcat(paramImg,1000,filImg);
os::strcat(paramImg,1000," -f"); os::strcat(paramImg,1000,filOut);
os::strcat(paramImg,1000," -l"); os::strcat(paramImg,1000,filFeat);
bool ret = mrpt::system::launchProcess( paramImg );
if(!ret)
THROW_EXCEPTION("[extractFeaturesSIFT] Could not launch external process... (extractSIFT.exe)");
MRPT_START
// Load the results:
CMatrix aux;
aux.loadFromTextFile( filOut );
size_t nRows = aux.getRowCount();
printf("[computeSiftFeatures1] %u features\n", nRows);
unsigned int i;
float lx,ly;
lx = 0.0;
ly = 0.0;
feat = in_features.begin();
for(i = 0; i < nRows; i++)
{
if( aux(i,0) != lx || aux(i,1) != ly ) // Only one descriptor for feature
{
(*feat)->type = featSIFT;
(*feat)->orientation = aux(i,2);
(*feat)->scale = aux(i,3);
// The descriptor:
aux.extractRow(i, (*feat)->descriptors.SIFT, 4);
lx = aux(i,0);
ly = aux(i,1);
feat++;
} // end if
} // end for
MRPT_END
break;
#else
THROW_EXCEPTION("TO DO @ linux OS!");
#endif
} // end case CSBinary
case Hess: // Implementation by Hess
{
#if !MRPT_HAS_SIFT_HESS
THROW_EXCEPTION("Method not available since MRPT has been compiled without Hess' SIFT library")
#elif MRPT_HAS_OPENCV // OK, we have Hess' sift:
IplImage* init_img;
IplImage*** gauss_pyr, *** dog_pyr;
CvMemStorage* storage;
CvSeq* features;
int octvs; //, n = 0;
/* check arguments */
ASSERT_(in_img.getWidth() != 0 && in_img.getHeight() != 0);
/* build scale space pyramid; smallest dimension of top level is ~4 pixels */
const CImage img_grayscale(in_img, FAST_REF_OR_CONVERT_TO_GRAY);
const IplImage* ipl_im = img_grayscale.getAs<IplImage>();
//.........这里部分代码省略.........
示例6: Test_Kinect
// ------------------------------------------------------
// Test_Kinect
// ------------------------------------------------------
void Test_Kinect()
{
// Launch grabbing thread:
// --------------------------------------------------------
TThreadParam thrPar;
std::thread thHandle = std::thread(thread_grabbing, std::ref(thrPar));
// Wait until data stream starts so we can say for sure the sensor has been
// initialized OK:
cout << "Waiting for sensor initialization...\n";
do
{
CObservation3DRangeScan::Ptr possiblyNewObs =
std::atomic_load(&thrPar.new_obs);
if (possiblyNewObs && possiblyNewObs->timestamp != INVALID_TIMESTAMP)
break;
else
std::this_thread::sleep_for(10ms);
} while (!thrPar.quit);
// Check error condition:
if (thrPar.quit) return;
// Feature tracking variables:
CFeatureList trackedFeats;
unsigned int step_num = 0;
bool SHOW_FEAT_IDS = true;
bool SHOW_RESPONSES = true;
CGenericFeatureTrackerAutoPtr tracker;
// "CFeatureTracker_KL" is by far the most robust implementation for now:
tracker = CGenericFeatureTrackerAutoPtr(new CFeatureTracker_KL);
tracker->enableTimeLogger(true); // Do time profiling.
// Set of parameters common to any tracker implementation:
// To see all the existing params and documentation, see
// mrpt::vision::CGenericFeatureTracker
// http://reference.mrpt.org/devel/structmrpt_1_1vision_1_1_c_generic_feature_tracker.html
tracker->extra_params["add_new_features"] =
1; // track, AND ALSO, add new features
tracker->extra_params["add_new_feat_min_separation"] = 25;
tracker->extra_params["add_new_feat_max_features"] = 150;
tracker->extra_params["add_new_feat_patch_size"] = 21;
tracker->extra_params["minimum_KLT_response_to_add"] = 40;
tracker->extra_params["check_KLT_response_every"] =
5; // Re-check the KLT-response to assure features are in good points.
tracker->extra_params["minimum_KLT_response"] =
25; // Re-check the KLT-response to assure features are in good points.
tracker->extra_params["update_patches_every"] = 0; // Update patches
// Specific params for "CFeatureTracker_KL"
tracker->extra_params["window_width"] = 25;
tracker->extra_params["window_height"] = 25;
// Global points map:
CColouredPointsMap globalPtsMap;
globalPtsMap.colorScheme.scheme =
CColouredPointsMap::cmFromIntensityImage; // Take points color from
// RGB+D observations
// globalPtsMap.colorScheme.scheme =
// CColouredPointsMap::cmFromHeightRelativeToSensorGray;
// Create window and prepare OpenGL object in the scene:
// --------------------------------------------------------
mrpt::gui::CDisplayWindow3D win3D("kinect-3d-slam 3D view", 800, 600);
win3D.setCameraAzimuthDeg(140);
win3D.setCameraElevationDeg(20);
win3D.setCameraZoom(8.0);
win3D.setFOV(90);
win3D.setCameraPointingToPoint(2.5, 0, 0);
mrpt::opengl::CPointCloudColoured::Ptr gl_points =
mrpt::make_aligned_shared<mrpt::opengl::CPointCloudColoured>();
gl_points->setPointSize(2.5);
mrpt::opengl::CSetOfObjects::Ptr gl_curFeats =
mrpt::make_aligned_shared<mrpt::opengl::CSetOfObjects>();
mrpt::opengl::CSetOfObjects::Ptr gl_keyframes =
mrpt::make_aligned_shared<mrpt::opengl::CSetOfObjects>();
mrpt::opengl::CPointCloudColoured::Ptr gl_points_map =
mrpt::make_aligned_shared<mrpt::opengl::CPointCloudColoured>();
gl_points_map->setPointSize(2.0);
const double aspect_ratio =
480.0 / 640.0; // kinect.rows() / double( kinect.cols() );
mrpt::opengl::CSetOfObjects::Ptr gl_cur_cam_corner =
mrpt::opengl::stock_objects::CornerXYZSimple(0.4f, 4);
opengl::COpenGLViewport::Ptr viewInt;
{
//.........这里部分代码省略.........