int Preprocessor::crop(){ string src = para.crop_src; string dst = para.crop_dst; unsigned int crop_x = para.crop_x; unsigned int crop_y = para.crop_y; unsigned int crop_w = para.crop_w; unsigned int crop_h = para.crop_h; unsigned int serial_beg = para.serial_beg; unsigned int serial_end = para.serial_end; unsigned int thread_num = para.thread_num; string in_pre = para.crop_in_pre; string in_post = para.crop_in_post; string out_pre = para.crop_out_pre; string out_post = para.crop_out_post; unsigned int image_depth = para.image_depth; unsigned int serial_bits = para.serial_bits; string sys_del = para.sys_del; string x_str(""), y_str(""), w_str(""), h_str(""); stringstream str_buffer; str_buffer<<crop_x; str_buffer>>x_str; str_buffer.clear(); str_buffer<<crop_y; str_buffer>>y_str; str_buffer.clear(); str_buffer<<crop_w; str_buffer>>w_str; str_buffer.clear(); str_buffer<<crop_h; str_buffer>>h_str; str_buffer.clear(); cv::Rect roi(crop_x, crop_y, crop_w, crop_h); #pragma omp parallel for num_threads(thread_num) for(int serial_num = int(serial_beg); serial_num <= int(serial_end); ++ serial_num){ cv::Mat out_image, in_image; stringstream tmp_strBuffer; string serial_str, out_name, image_path; tmp_strBuffer<<setw(serial_bits)<<setfill('0')<<serial_num; tmp_strBuffer>>serial_str; tmp_strBuffer.clear(); cout<<serial_str<<" "<<omp_get_thread_num()<<endl; image_path = src + sys_del + in_pre + serial_str + in_post; in_image = cv::imread(image_path, CV_LOAD_IMAGE_UNCHANGED); if(!in_image.data){ cout<<image_path<<" Loaded Error!"<<endl; continue; } if(crop_x < 0 || crop_x + crop_w > in_image.size().width || crop_y < 0 || crop_y + crop_h > in_image.size().height){ cout<<"Out of Range Error!"<<endl; continue; } out_image = cv::Mat(in_image, roi); out_name = dst + sys_del + out_pre + serial_str + "_x" + x_str + "_y" + y_str + "_w" + w_str + "_h" +h_str + out_post; cout<<out_name<<endl; cv::imwrite(out_name, out_image); } return 0; }
void Date::setUnitsAndClear(std::string& str) { // key-words "since" and "before" indicate that a date // serves as a basic date and // key-words: years, months, days, hours, minutes, seconds // indicate the unit of the amount X in getDate(X) relative // to the basic date. The method clears the string from any // key-word. Split x_str(str); str.clear(); for( size_t n=0 ; n < x_str.size() ; ++n) { std::string s(x_str[n]); // accept singular and plural forms if( s[s.size()-1] == 's' ) s = s.substr(0,s.size()-1); if( s == "since" ) continue; // refUnitSign already set by default else if( s == "before" ) refUnitSign=-1.; else if( s.find("year") < std::string::npos) unitStr = "year"; else if( s.find("month") < std::string::npos) unitStr = "month"; else if( s.find("day") < std::string::npos) unitStr = "day"; else if( s.find("hour") < std::string::npos) unitStr = "hour"; else if( s.find("minute") < std::string::npos) unitStr = "minute"; else if( s.find("second") < std::string::npos ) unitStr = "second"; else { if( str.size() ) str += " " ; str += x_str[n]; } } return ; }
std::string Date::convertFormattedToISO_8601(std::string str ) { // Convention: Date ISO 8601 Format: yyyy-mm-ddThh:mm:ss // different compositions of str0 are converted. // Note: yy means really yy A.D., not the century + yy if( hdhC::isNumber(str) ) { double f = hdhC::string2Double(str); return convertFormattedToISO_8601(f); } std::string iso; // convert 'T' into a blank size_t pos; if( (pos=str.find('T')) < std::string::npos ) str[pos] = ' '; // this is for yymmdd_hhmmss if( (pos=str.find('_')) < std::string::npos ) str[pos] = ' '; Split x_str(str); size_t offset; for(offset=0 ; offset < x_str.size() ; ++offset) // parameter true: also sign and decimal if( hdhC::isDigit(x_str[offset][0], true) ) break; // different formats: date [time[[ ]Zone]] std::string t0; bool isSign=false; for( size_t j=offset ; j < x_str.size() ; ++j ) { // the date if( j == offset ) { if( x_str[j][0] == '-' ) { t0 = x_str[j].substr(1); isSign=true; } else t0 = x_str[j]; if( t0.find('-') < std::string::npos ) { Split x_t0(t0,'-') ; // also accepts yyyy-m-d or even yyy-m iso += x_t0[0]; for(size_t i=1 ; i < 3 ; ++i) { iso += '-'; if( x_t0[i].size() == 1 ) iso += '0'; iso += x_t0[i]; } } else if( t0.size() > 3 && hdhC::isDigit(t0) ) { iso += t0.substr(0,4) ; if( t0.size() > 4 ) { iso += '-' ; iso += t0.substr(4,2) ; } if( t0.size() > 6 ) { iso += '-' ; iso += t0.substr(6,2) ; } } } else if( j == (offset +1) ) { //the time t0 = x_str[j]; iso += 'T'; if( t0.find(':') < std::string::npos ) { Split x_t0(t0,':') ; for( size_t i=0 ; i < x_t0.size() ; ++i ) { // also accepts h:m:s.f or even h:m if( i ) iso += ':'; if( x_t0[i].size() == 1 ) iso += '0'; iso += x_t0[i]; } } else if( t0.size() && hdhC::isDigit(t0.substr(0,6)) ) { if( t0.size() == 1 ) iso += '0'; iso += t0.substr(0,2) ; if( t0.size() > 2 ) { iso += ':' ; iso += t0.substr(2,2) ; } if( t0.size() > 4 ) { iso += ':' ; iso += t0.substr(4) ; } } } else if( j == (offset +2) ) iso += x_str[j] ; // add the time-zone } std::string def("0000-00-00T00:00:00"); if( iso.size() < def.size() ) iso += def.substr(iso.size()); if( isSign ) iso = "-" + iso ; return iso ; }