00001 #ifndef Impala_Application_SDash_RoiLoader_h 00002 #define Impala_Application_SDash_RoiLoader_h 00003 00004 #include <string> 00005 #include <ostream> 00006 #include <strstream> 00007 00008 #include "Core/Array/Arrays.h" 00009 #include "Core/Array/ReadJpg.h" 00010 00011 #include "Visualization/RgbOglImage.h" 00012 00013 namespace Impala { 00014 namespace Application { 00015 namespace SDash { 00016 00017 class RoiLoader { 00018 00019 public: 00020 00021 RoiLoader(const std::string& roiPath) : mRoiPath(roiPath) 00022 { 00023 } 00024 00025 virtual ~RoiLoader() 00026 { 00027 } 00028 00029 OGLIMAGE* GetDummyImage() 00030 { 00031 if (!VAN_GOGH) 00032 { 00033 char buf[40]; 00034 sprintf(buf, "SurvIm_5.jpg"); 00035 Core::Array::Array2dVec3UInt8* im = 0; 00036 ReadJpg(im, buf); 00037 VAN_GOGH = Visualization::RgbOglImage::OglImage(im); 00038 } 00039 return VAN_GOGH; 00040 } 00041 00042 OGLIMAGE* Load(int videoId, int frameNr, int roiNr) 00043 { 00044 std::ostrstream roiFileName; 00045 roiFileName << "roi_" << videoId << '_' << frameNr << '_' << roiNr << ".jpg" << std::ends; 00046 //std::cout << "reading roi from: " << roiFileName.str() << std::endl; 00047 std::ostrstream roiFilePath; 00048 roiFilePath << mRoiPath << "video" << videoId << '/'; 00049 roiFilePath << roiFileName.str() << std::ends; 00050 00051 OGLIMAGE* regionImage; 00052 File file(std::string(roiFilePath.str()), "r", false); 00053 if (file.Valid()) 00054 { 00055 file.Close(); 00056 Core::Array::Array2dVec3UInt8* im = 0; 00057 Core::Array::ReadJpg(im, roiFilePath.str()); 00058 regionImage = Visualization::RgbOglImage::OglImage(im); 00059 } 00060 else 00061 { 00062 std::cout << "failed to read roi" << std::endl; 00063 regionImage = GetDummyImage(); 00064 } 00065 return regionImage; 00066 } 00067 00068 private: 00069 00070 static OGLIMAGE* VAN_GOGH; 00071 00072 std::string mRoiPath; 00073 00074 }; // class 00075 00076 OGLIMAGE* RoiLoader::VAN_GOGH = 0; 00077 00078 } 00079 } 00080 } 00081 00082 #endif