11 Dataset::Dataset(
const std::string &base_location,
const std::string &db_data_location) {
27 std::vector< std::shared_ptr< const Image> > images(this->
num_images());
28 for (uint64_t i = 0; i < this->
num_images(); i++) {
29 images[i] = this->
image(i);
35 std::vector< std::shared_ptr< const Image> > all = this->
all_images();
36 std::random_shuffle(all.begin(), all.end());
37 std::vector< std::shared_ptr< const Image> > images(all.begin(), all.begin() + count);
42 out <<
"Dataset location: " << dataset.
location() <<
", number of images: " << dataset.
num_images();
51 :
Dataset(base_location, db_data_location) {
53 this->
read(db_data_location);
57 this->
write(db_data_location);
64 const std::string &image_path =
id_image_map.right.at(
id);
66 std::shared_ptr<Image> current_image = std::make_shared<SimpleImage>(image_path, id);
72 for (
size_t i = 0; i < image_file_paths.size(); i++) {
79 std::ifstream ifs(db_data_location, std::ios::binary);
82 ifs.read((
char *)&num_images,
sizeof(uint64_t));
88 ifs.read((
char *)&image_id,
sizeof(uint64_t));
89 ifs.read((
char *)&length,
sizeof(uint16_t));
91 std::string image_location;
92 image_location.resize(length);
94 ifs.read((
char *)&image_location[0],
sizeof(
char)* length);
95 std::shared_ptr<const SimpleImage> simage = std::make_shared<const SimpleImage>(image_location, image_id);
99 return (ifs.rdstate() & std::ifstream::failbit) == 0;
105 std::ofstream ofs(db_data_location, std::ios::binary | std::ios::trunc);
107 ofs.write((
const char *)&num_images,
sizeof(uint64_t));
109 for (uint64_t i = 0; i < this->
num_images(); i++) {
111 const std::string &image_location = image->
location();
112 uint64_t image_id = image->id;
113 uint16_t length = image_location.size();
114 ofs.write((
const char *)&image_id,
sizeof(uint64_t));
115 ofs.write((
const char *)&length,
sizeof(uint16_t));
116 ofs.write((
const char *)&image_location[0],
sizeof(
char)* length);
119 return (ofs.rdstate() & std::ofstream::failbit) == 0;
131 uint32_t level0 =
id >> 20;
132 uint32_t level1 = (
id - (level0 << 20)) >> 10;
134 std::stringstream ss;
135 ss <<
"/feats/" << feat_name <<
"/" <<
136 std::setw(4) << std::setfill(
'0') << level0 <<
"/" <<
137 std::setw(4) << std::setfill(
'0') << level1 <<
"/" <<
138 std::setw(9) << std::setfill(
'0') <<
id <<
"." << feat_name;
150 id_image_map.insert(boost::bimap<std::string, uint64_t>::value_type(simage->location(), simage->id));