c++ - Compare strings in same column -


i have downloaded database of pictures.

the database comes csv file codes each picture , identifies important pixels in picture.

the first column string code of subject, i000ra-fn. 000 actual code, , strings start i. letters after 3 digits denote different things such lighting, camera angle, etc.

since there can many pictures of subject 000, due different lighting , camera angles, want keep 1.

so i'd do, check in column 1 number of pictures start i000. randomly keep 1 of , subsequently delete rest, both in csv file , on hard drive.

then i'd iterate on every name in column until number of subjects have became distinct.

i new c++ , can't wrap head around how this. can suggestions on how this? far i've loaded csv file vector of vectors. first column skipped , loaded separate vector called names. i'm @ loss of how proceed though...any suggestions?

int main(int argc, const char** argv) {     ifstream landmarksfile("muct76-opencv.csv");     string row;     string cell;     vector<vector<double>> alllandmarks;     vector<double> individualslandmarks;     vector<string> names;      // skip headers     getline(landmarksfile, row);      // continue...     while (getline(landmarksfile, row))     {         stringstream iss(row);         while (getline(iss, cell, ','))         {             size_t found = cell.find("i");             if (found != string::npos)             {                 names.push_back(cell);             }             else             {                 individualslandmarks.push_back(atof(cell.c_str()));             }         }         alllandmarks.push_back(individualslandmarks);         individualslandmarks.clear();     } } 

edit: sample of csv file...note columns goes on x75 , y75 ,

name        tag x00 y00 x01 y01 x02 y02 x03 i000qa-fn   0   201 348 201 381 202 408 209 i000ra-fn   0   187 326 184 358 182 390 186 i000sa-fn   0   190 344 191 385 197 414 206 i001qa-mn   0   162 368 165 399 172 421 178 i001ra-mn   0   166 370 171 404 178 430 185 i001sa-mn   0   166 369 173 404 177 429 185 i002qa-mn   0   224 289 224 323 223 347 227 i002ra-mn   0   221 288 221 323 222 348 229 i002sa-mn   0   222 302 227 329 230 349 239 i003qa-fn   0   182 429 182 456 187 478 196 i003ra-fn   0   178 429 180 458 184 478 193 i003sa-fn   0   180 432 181 461 185 481 193 i004qa-mn   0   182 258 187 289 185 312 190 

downloadable here: https://code.google.com/p/muct/downloads/detail?name=muct-landmarks-v1.tar.gz&can=2&q=

  1. so i'd do, check in column 1 number of pictures start i000. randomly keep 1 of , subsequently delete rest, both in csv file , on hard drive.

    first, create function creates vector out elements start i000. not difficult...

    template<class container, class unaryop> container container_copy_if(const container& c, unaryop pred) {     container temp;     std::copy_if(std::begin(c), std::end(c), std::back_inserter(temp), pred);     return temp; }  ...  auto vector_with_only_i000 = container_copy_if(names,     [] (const std::string& name) {          return name.substr("i000") != std::string::npos; }); 
  2. ...then randomly keep 1 of , subsequently delete rest, both in csv file , on hard drive.

    you'll have use random number generator this. here how it's done using std::uniform_int_distribution:

    std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution<int> dist(0, vector_with_only_i000.size() - 1);  auto random_name = vector_with_only_i000.at(dist(rd())); 

    now have random name can remove else original names vector doesn't equal random_name:

    auto not_equal_random_name = [&] (const std::string& name) {     return name == random_name; };  names.erase(     std::remove_if(names.begin(), names.end(), not_equal_random_name),     names.end()); 

    now erase them actual file, you'll want this:

    1. save each line of file in vector.
    2. erase each element vector not equal random_name.
    3. create new file new name.
    4. write vector contents new file.
    5. rename file same name old csv file.

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -