00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <string>
00011 #include <vector>
00012 #include <iostream>
00013 #include <sstream>
00014
00015 #include "Application/sdash/RegionsOfInterestInfo.h"
00016
00017 #include "Core/Array/Arrays.h"
00018 #include "Core/Geometry/Rectangle.h"
00019 #include "Core/Array/ReadFile.h"
00020 #include "Core/Array/WriteJpg.h"
00021 #include "Core/Array/MakeRoi.h"
00022
00023 #include "Util/DataBaseReadString.h"
00024
00025 namespace Impala
00026 {
00027 namespace Application
00028 {
00029 namespace SDash
00030 {
00031
00032
00033 static const std::string ROI_INFO_FILE = "U:/vietp/nfi-demo/data/boxes-b.bin";
00034
00035
00036
00037 static const std::string VIDEO_BASE_PATH = "U:/vietp/nfi-cams/";
00038
00039
00040 static const std::string FRAME_LISTS_PATH = VIDEO_BASE_PATH;
00041
00042
00043 static const int VIDEO_COUNT = 1;
00044
00045 static const std::string FRAME_LIST_POSTFIX = ".list-short";
00046
00047 static const std::string INDIV_FRAME_FOLDERS[] = {
00048 "hd8-cam01",
00049 "hd8-cam02",
00050 "hd8-cam03",
00051 "hd8-cam04",
00052 "hd8-cam05",
00053 "hd8-cam06",
00054 "hd8-cam07",
00055 "hd9-cam01",
00056 "hd9-cam02",
00057 "hd9-cam03",
00058 "hd9-cam08",
00059 "hd9-cam09"
00060 };
00061
00062
00063 static const int FRAMES_PER_VIDEO[] = {
00064 12322, 8599, 12941, 12841, 12664, 12477, 12225, 10605, 10605, 10614,
00065 10609, 10603};
00066
00067
00068 static const int ROIS_PER_VIDEO[] = {
00069 2472, 452, 3473, 2921, 653, 4147, 3328, 4542, 25, 4707, 3794, 2980};
00070
00071
00072 using namespace Util;
00073
00074 class RoiExtractor
00075 {
00076
00077 typedef Core::Geometry::Rectangle Rectangle;
00078 typedef Core::Array::Array2dVec3UInt8 Array2dVec3UInt8;
00079
00080 public:
00081
00082 RoiExtractor(const RegionsOfInterestInfo& rois) : mRois(rois)
00083 {
00084 }
00085
00086 void Extract()
00087 {
00088 Array2dVec3UInt8 *frameData = 0;
00089
00090 for (int video = 0; video < VIDEO_COUNT; video++)
00091 {
00092 std::cout << "processing video #" << video << std::endl;
00093
00094 std::string frameListFile = FRAME_LISTS_PATH + INDIV_FRAME_FOLDERS[video] + FRAME_LIST_POSTFIX;
00095 std::vector<std::string> frameFileNames;
00096 Util::DatabaseReadStrings(frameFileNames, frameListFile,
00097 &Util::Database::GetInstance());
00098 int nrOfFrames = frameFileNames.size();
00099 if (nrOfFrames != FRAMES_PER_VIDEO[video])
00100 std::cerr << "incorrect frame count for video #" << video << ": " << nrOfFrames << " vs. " << FRAMES_PER_VIDEO[video] << std::endl;
00101
00102 int roisForVideo = 0;
00103 for (int frame = 0; frame < nrOfFrames; frame++)
00104 {
00105 if (frame % 1000 == 0)
00106 std::cout << " processing frame #" << frame << std::endl;
00107
00108 const std::vector<Rectangle>& rois = mRois.GetRois(video, frame);
00109 if (rois.empty())
00110 continue;
00111
00112
00113 std::string frameFile = frameFileNames[frame];
00114
00115 std::string framePath = VIDEO_BASE_PATH + INDIV_FRAME_FOLDERS[video] + "/" + frameFile;
00116 Core::Array::ReadFile<Array2dVec3UInt8>(frameData, framePath);
00117
00118
00119 int nrOfRegions = rois.size();
00120 for (int seqNr = 0; seqNr < nrOfRegions; seqNr++)
00121 {
00122 Rectangle region(rois[seqNr]);
00123
00124
00125 Array2dVec3UInt8 *roi = Core::Array::MakeRoi<Array2dVec3UInt8>(frameData, region);
00126
00127
00128
00129
00130
00131 std::ostringstream regionFile;
00132 regionFile << "roi/video" << video << "/roi_" << video << '_' << frame<< '_' << seqNr << ".jpg";
00133 Core::Array::WriteJpg(roi, regionFile.str());
00134 }
00135 roisForVideo += nrOfRegions;
00136 }
00137 if (roisForVideo != ROIS_PER_VIDEO[video])
00138 std::cerr << "incorrect roi count for video #" << video << ": " << roisForVideo << " vs. " << ROIS_PER_VIDEO[video] << std::endl;
00139 }
00140
00141
00142 delete frameData;
00143 frameData = 0;
00144 }
00145
00146 private:
00147
00148 RegionsOfInterestInfo mRois;
00149
00150 };
00151
00152 }
00153 }
00154 }
00155
00156
00157 using namespace Impala::Application::SDash;
00158
00159 int main(int argc, char* argv[])
00160 {
00161 std::cout << "reading regions-of-interest info file..." << std::endl;
00162 RegionsOfInterestInfo rois(ROI_INFO_FILE, VIDEO_COUNT, 32);
00163 RoiExtractor roiExtr(rois);
00164 std::cout << "extracting regions-of-interest..." << std::endl;
00165 roiExtr.Extract();
00166 std::cout << "ready." << std::endl;
00167 return 0;
00168 }