ObjectFinder.C
00001
00002
00003
00004
00005
00006
00007 #include "Robots/BeoHawk/vision/ObjectFinder.H"
00008 #include "Robots/RobotBrain/RobotBrainComponent.H"
00009 #include "Component/ModelParam.H"
00010 #include "Component/ModelOptionDef.H"
00011
00012 #include <dirent.h>
00013
00014 const ModelOptionCateg MOC_ObjectFinder = {
00015 MOC_SORTPRI_3, "ObjectFinder Related Options" };
00016
00017 const ModelOptionDef OPT_ImagesDir =
00018 { MODOPT_ARG(std::string), "ImagesDir", &MOC_ObjectFinder, OPTEXP_CORE,
00019 "The directory in which we should search for images to build the database for the Object Finder."
00020 " To avoid having to check for whether the files are of valid type, ONLY images may be stored"
00021 "in this directory.",
00022 "images-dir", '\0', "<string>", "images" };
00023
00024 ObjectFinder::ObjectFinder(OptionManager &mgr,
00025 const std::string &descrName, const std::string &tagName) :
00026 VisionBrainComponentI(mgr, descrName, tagName),
00027 imagesDir(&OPT_ImagesDir, this, 0) {
00028
00029 }
00030
00031 ObjectFinder::~ObjectFinder() {
00032 }
00033
00034 void ObjectFinder::registerTopics() {
00035
00036 LINFO("Registering ObjectFinder Messages/Subscriptions");
00037 registerVisionTopics();
00038 }
00039
00040 void ObjectFinder::updateFrame(Image<PixRGB<byte> > img, bool isFwdCamera) {
00041
00042 LINFO("Image Received: %d", itsFrameCount);
00043
00044 featureDB.searchDB(img);
00045 LINFO("##### Size is %dx%d", img.getWidth(), img.getHeight());
00046
00047 }
00048
00049
00050 void ObjectFinder::buildFeatureDB() {
00051
00052 std::string imageDirName = imagesDir.getVal();
00053 if (imageDirName.rfind('/') != imageDirName.length() - 1)
00054 imageDirName = imageDirName + "/";
00055
00056 DIR * imageDir = opendir(imageDirName.c_str());
00057 struct dirent * curFile;
00058
00059 if (imageDir == NULL) {
00060 LFATAL("Invalid directory passed (%s).", imageDirName.c_str());
00061 return;
00062 }
00063
00064 while ((curFile = readdir(imageDir))) {
00065 if (curFile->d_name[0] != '.') {
00066 std::string fullFilename = std::string(curFile->d_name);
00067 std::string truncFilename = std::string(curFile->d_name);
00068 if (fullFilename.rfind('.') > 0)
00069 truncFilename = truncFilename.substr(0, fullFilename.rfind('.'));
00070
00071
00072
00073
00074
00075
00076
00077
00078 LINFO("FAILURE: Could not add image (%s) to DB.", curFile->d_name);
00079 }
00080 }
00081
00082
00083 closedir(imageDir);
00084 }