bool camera<Tdata>::record_frame() { #ifdef __GUI__ std::ostringstream oss; oss << recording_name << "/frame_"; oss << setfill('0') << setw(6) << record_cnt << ".png"; save_window(oss.str().c_str()); out << "saved " << oss.str() << std::endl; record_cnt++; #endif return true; }
static void save_children (GString *s, GdkWindow *window) { GList *l; GdkWindow *child; for (l = g_list_reverse (gdk_window_peek_children (window)); l != NULL; l = l->next) { child = l->data; save_window (s, child); } }
void detection_thread<T>::execute() { try { bool display = false; #ifdef __GUI__ display = conf.exists_true("display") && conf.exists_true("display_threads"); bool mindisplay = conf.exists_true("minimal_display"); bool save_video = conf.exists_true("save_video"); bool display_states = conf.exists_true("display_states"); uint wid = 0; // window id uint wid_states = 0; // window id #endif uint display_sleep = conf.try_get_uint("display_sleep", 0); // if (!display && save_video) { // // we still want to output images but not show them // display = true; // #ifdef __GUI__ // set_gui_silent(); // #endif // } // load network and weights in a forward-only parameter parameter<T> theparam; theparam.set_forward_only(); idx<ubyte> classes(1,1); //try { // try loading classes names but do not stop upon failure load_matrix<ubyte>(classes, conf.get_cstring("classes")); // } catch(std::string &err) { // merr << "warning: " << err; // merr << std::endl; // } std::vector<std::string> sclasses = ubyteidx_to_stringvector(classes); answer_module<T> *ans = create_answer<T,T,T>(conf, classes.dim(0)); uint noutputs = ans->get_nfeatures(); intg thick = -1; module_1_1<T> *net = create_network<T>(theparam, conf, thick, noutputs, "arch", this->_id); // loading weights if (conf.exists("weights")) { // manual weights // concatenate weights if multiple ones std::vector<std::string> w = string_to_stringvector(conf.get_string("weights")); mout << "Loading weights from: " << w << std::endl; theparam.load_x(w); // permute weights by blocks if (conf.exists("weights_permutation")) { std::string sblocks = conf.get_string("weights_blocks"); std::string spermut = conf.get_string("weights_permutation"); std::vector<intg> blocks = string_to_intgvector(sblocks.c_str()); std::vector<uint> permut = string_to_uintvector(spermut.c_str()); theparam.permute_x(blocks, permut); } } else { if (conf.exists_true("manual_load")) { // manual load eblwarn("\"weights\" variable not defined, loading manually " << "if manual_load defined"); manually_load_network(*((layers<T>*)net), conf); } else { // random weights int seed = dynamic_init_drand(); eblwarn("No weights to load, randomizing weights with seed " << seed); forget_param_linear fgp(1, 0.5, seed); net->forget(fgp); } } DEBUGMEM_PRETTY("before detection"); // detector detector<T> detect(*net, sclasses, ans, NULL, NULL, mout, merr); init_detector(detect, conf, outdir, silent); // keep pointer to detector pdetect = &detect; bootstrapping<T> boot(conf); // when a bbox file is given, ignore the processing, load the pre-computed // bboxes and feed them to the nms (non-maximum suppression). bboxes boxes(bbox_all, NULL, mout, merr); boxes.print_saving_type(); // inform user how we save boxes bool precomputed_boxes = false; if (conf.exists("bbox_file")) { precomputed_boxes = true; std::string bbfile = conf.get_string("bbox_file"); boxes.load_eblearn(bbfile); } bool bmask_class = false; if (conf.exists("mask_class")) bmask_class = detect.set_mask_class(conf.get_cstring("mask_class")); std::string viddir = outdir; viddir += "video/"; mkdir_full(viddir); // gui #ifdef __GUI__ uint display_wmax = conf.try_get_uint("display_max_width", 3000); T display_min = (T) conf.try_get_double("display_min", -1.7); T display_max = (T) conf.try_get_double("display_max", 1.7); T display_in_max = (T) conf.try_get_double("display_in_max", 255); T display_in_min = (T) conf.try_get_double("display_in_min", 0); float display_transp = conf.try_get_float("display_bb_transparency", 0); uint qstep1 = conf.try_get_uint("qstep1", 0); uint qheight1 = conf.try_get_uint("qheight1", 0); uint qwidth1 = conf.try_get_uint("qwidth1", 0); uint qstep2 = conf.try_get_uint("qstep2", 0); uint qheight2 = conf.try_get_uint("qheight2", 0); uint qwidth2 = conf.try_get_uint("qwidth2", 0); module_1_1_gui netgui; wid_states = display_states ? new_window("network states"):0; night_mode(); std::string title = "EBLearn detector: "; title += _name; if (display) { wid = new_window(title.c_str()); mout << "displaying in window " << wid << std::endl; night_mode(); } float zoom = conf.try_get_float("display_zoom", 1); bool bbox_show_conf = !conf.exists_false("bbox_show_conf"); bool bbox_show_class = !conf.exists_false("bbox_show_class"); detector_gui<T> dgui(conf.try_get_uint("show_extracted", 0), conf.exists_bool("queue1"), qstep1, qheight1, qwidth1, conf.exists_bool("queue2"), qstep2, qheight2, qwidth2, bbox_show_class, bbox_show_conf); if (bmask_class) dgui.set_mask_class(conf.get_cstring("mask_class"), (T) conf.try_get_double("mask_threshold", 0)); #endif // timing variables timer tpass, toverall; long ms; // loop toverall.start(); // we're ready bavailable = true; while(!this->_stop) { // wait until a new image is made available while (!in_updated && !_stop) { millisleep(1); } tpass.restart(); if (_stop) break ; // we got a new frame, reset new frame flag in_updated = false; // no need to lock mutex // check if this frame should be skipped if (boot.skip_frame(frame_name)) { skip_frame(); continue ; } else if (!frame_loaded) { uframe = load_image<ubyte>(frame_fullname); mout << "loaded image " << frame_fullname << std::endl; } if (!silent) mout << "processing " << frame_name << std::endl; // check frame is correctly allocated, if not, allocate. if (frame.order() != uframe.order()) frame = idx<T>(uframe.get_idxdim()); else if (frame.get_idxdim() != uframe.get_idxdim()) frame.resize(uframe.get_idxdim()); // copy frame idx_copy(uframe, frame); // run detector if (!display) { // fprop without display if (precomputed_boxes) { try { bboxes *bb = boxes.get_group(frame_name); idxdim d = boxes.get_group_dims(frame_name); d.insert_dim(0, 1); bboxes pruned; detect.init(d); detect.fprop_nms(*bb, pruned); copy_bboxes(pruned); // make a copy of bounding boxes // resize frame so that caller knows the size of the frame idxdim framedim = frame.get_idxdim(); if (d.dim(1) == -1 || d.dim(2) == -1) eblerror("pre-computed boxes must contain full image size, " << "but found: " << d); framedim.setdim(0, d.dim(1)); framedim.setdim(1, d.dim(2)); frame.resize(framedim); } catch(eblexception &e) { #ifdef __NOEXCEPTIONS__ merr << "exception" << std::endl; #else merr << e << std::endl; #endif } } else { try { mout << "starting processing of frame " << frame_name << std::endl; bboxes &bb = detect.fprop(frame, frame_name.c_str(), frame_id); copy_bboxes(bb); // make a copy of bounding boxes } catch(ebl::eblexception &e) { // detection failed #ifdef __NOEXCEPTIONS__ eblwarn("detection failed"); #else eblwarn("detection failed: " << e); #endif clear_bboxes(); } } } #ifdef __GUI__ else { // fprop and display if (precomputed_boxes) eblerror("not implemented for nms only (TODO)"); disable_window_updates(); select_window(wid); clear_window(); std::string title = _name; title << ": " << frame_name; set_window_title(title.c_str()); // clear_resize_window(); try { if (mindisplay) { bboxes &bb = dgui.display(detect, frame, frame_name.c_str(), frame_id, 0, 0, zoom, display_min, display_max, wid, _name.c_str(), display_transp); copy_bboxes(bb); // make a copy of bounding boxes } else { // extract & display boxes bboxes &bb = dgui.display_inputs_outputs(detect, frame, frame_name.c_str(), frame_id, 0, 0, zoom, display_min, display_max, wid, _name.c_str(), display_in_min, display_in_max, display_transp, display_wmax); // make a copy of bounding boxes copy_bboxes(bb); } } catch(ebl::eblexception &e) { // detection failed eblwarn("detection failed: " << e); clear_bboxes(); } enable_window_updates(); } if (display_states) { dgui.display_current(detect, frame, wid_states, NULL, zoom); select_window(wid); } if (save_video && display) { std::string fname = viddir; fname += frame_name; save_window(fname.c_str()); if (!silent) mout << "saved " << fname << std::endl; } #endif if (!silent) mout << "processing done for frame " << frame_name << std::endl; // bootstrapping if (conf.exists_true("bootstrapping")) { boot.fprop(detect, frame_name); // add multiple scales if positives and scales are defined if (conf.exists("gt_scales") && boot.extract_positives()) { std::vector<double> scales = string_to_doublevector(conf.get_cstring("gt_scales")); for (uint s = 0; s < scales.size(); ++s) { double f = scales[s]; // downsample input by f detect.set_resolution(f); detect.init(frame.get_idxdim(), frame_name.c_str()); detect.fprop(frame, frame_name.c_str(), frame_id); boot.fprop(detect, frame_name, false, f); } detect.set_scaling_original(); detect.init(frame.get_idxdim(), frame_name.c_str()); } copy_bootstrapping(boot.get_all(), boot.get_bball()); #ifdef __GUI__ // display groundtruth if (conf.exists_true("display_bootstrapping")) dgui.display_groundtruth(detect, frame, boot.get_gtall(), boot.get_gtclean(), boot.get_gtrest(), boot.get_bbpos(), boot.get_bbneg(), boot.get_pos(), boot.get_neg(), 0, 0, zoom, display_min, display_max); #endif } total_saved = detect.get_total_saved(); ms = tpass.elapsed_milliseconds(); if (!silent) { mout << bbs.pretty_short(detect.get_labels()); mout << "processing=" << ms << " ms (" << tpass.elapsed() << ")" << std::endl; } DEBUGMEM_PRETTY("after detection"); // switch 'updated' flag on to warn we just added new data set_out_updated(); // display sleep if (display_sleep > 0) { mout << "sleeping for " << display_sleep << "ms." << std::endl; millisleep(display_sleep); } if (conf.exists("save_max") && detect.get_total_saved() > conf.get_uint("save_max")) break ; // limit number of detection saves } mout << "detection finished. Execution time: " << toverall.elapsed()<<std::endl; // free variables if (net) delete net; if (ans) delete ans; } eblcatcherror(); }
int main (int argc, char *argv[]) { /* These have been moved from global to local variables */ /* this reduces binary size and improves code structure. RP */ /* Also size of home_page and help_page reduced from 257. RP 11-mar-04 */ char home_page[20] = "index.htm"; char help_page[20] = "help.htm"; char base_dir[257]; char *showcommand = 0; char *oldscreen; int oldcursorx = wherex (), oldcursory = wherey (); int i; /* counter for loop */ int forcemono = 0, fancyscheme = 0; int AsciiExtendedChars = 1; int codepage = 0; cat = catopen("htmlhelp", 0); if (getenv ("HELPPATH") == NULL) { get_base_dir (base_dir, argv[0]); strcat (base_dir, "..\\help\\"); /* default location */ if (lang_add(base_dir, home_page) != 0) { char testpath[257]; get_base_dir (base_dir, argv[0]); strcat (base_dir, "..\\help\\"); /* bookshelf location */ strcpy(testpath, base_dir); strcat(testpath, home_page); if (checkForFile(testpath) != 0) { get_base_dir (base_dir, argv[0]); /* try same dir as exe */ strcpy(testpath, base_dir); strcat(testpath, home_page); if (checkForFile(testpath) != 0) { *base_dir = '\0'; /* try current dir */ strcpy(testpath, home_page); if (checkForFile(testpath) != 0) { get_base_dir (base_dir, argv[0]); strcat (base_dir, "..\\help\\"); } } } } } else { strcpy (base_dir, getenv ("HELPPATH")); if (lang_add(base_dir, home_page) != 0) { strcpy (base_dir, getenv ("HELPPATH")); if (base_dir[0] != '\0') { if (base_dir[strlen(base_dir)-1] != '\\' && base_dir[strlen(base_dir)-1] != '/'); strcat (base_dir, "\\"); } } } if (getenv ("HELPCMD")) { if (strstr (getenv ("HELPCMD"), "/A")) AsciiExtendedChars = 0; if (strstr (getenv ("HELPCMD"), "/M")) forcemono = 1; if (strstr (getenv ("HELPCMD"), "/F1")) fancyscheme = 1; if (strstr (getenv ("HELPCMD"), "/F2")) fancyscheme = 2; } for (i = 1; i < argc; i++) { if (argv[i][0] == '/') { switch (argv[i][1]) { default: printf ("%s -- %s\n", hcatInvArg, argv[i] + 1); printf ("%s\n", hcatHowGetUsage); break; case '?': show_usage (); return 0; case 'a': case 'A': if (argv[i][2] == 0) AsciiExtendedChars = 0; break; case 'c': case 'C': codepage = atoi(argv[i]+2); if (codepage == 0) { printf("%s (/Cnnn)\n", hcatCodepagePlease); printf("%s:\n%s\n", hcatCodepagesSupported, supportedCodepages); return 0; } break; case 'f': case 'F': fancyscheme = atoi(argv[i] + 2); if (fancyscheme < 1 || fancyscheme > 2) fancyscheme = 1; break; case 'h': case 'H': if (argv[i][2] == 0) /* Only put /h or /H */ { printf ("%s\n", hcatInvArg); printf ("%s\n", hcatHowGetUsage); return 0; } else { strncpy(help_page, argv[i] + 2, 14); } break; case 'l': case 'L': strcat (base_dir, argv[i] + 2); checkForFile (base_dir); get_home_page (home_page, base_dir); get_base_dir (base_dir, base_dir); break; case 'm': case 'M': if (argv[i][2] == '\0') forcemono = 1; else { printf ("%s -- %s\n", hcatInvArg, argv[i] + 1); printf ("%s\n", hcatHowGetUsage); return 0; } break; case 'o': /* Override index file path/name */ case 'O': strcpy (base_dir, argv[i] + 2); if (lang_add(base_dir, home_page) != 0) { strcpy (base_dir, argv[i] + 2); checkForFile (base_dir); get_home_page (home_page, base_dir); get_base_dir (base_dir, base_dir); } } } else if (showcommand == 0) { showcommand = malloc (strlen (argv[i]) + 11); if (!showcommand) { printf ("%s\n", hcatMemErr); return 0; } sprintf (showcommand, "#%s", argv[i]); } else { printf ("%s\n", hcat2ManyTopics); printf ("%s\n", hcatHowGetUsage); return 0; } } if (fancyscheme && forcemono) { printf ("%s\n", hcatFwithN); printf ("%s\n", hcatHowGetUsage); return 0; } /* detect (or force) the codepage to select UTF-8 and entity substition support */ if (selectCodepage(codepage) != codepage && codepage > 0) { printf("%s\n", hcatCodepageNotSupported); printf("%s:\n%s\n", hcatCodepagesSupported, supportedCodepages); return 0; } /* initialise user interface */ conio_init (forcemono); if (forcemono == 0) { oldscreen = malloc (W * H * 2); if (oldscreen) save_window (X, Y, W, H, oldscreen); } if (MonoOrColor == COLOR_MODE && fancyscheme == 0) { TEXT_COLOR = C_TEXT_COLOR; BOLD_COLOR = C_BOLD_COLOR; ITALIC_COLOR = C_ITALIC_COLOR; BORDER_BOX_COLOR = C_BORDER_COLOR; BORDER_TEXT_COLOR = C_BORDER_TEXT_COLOR; LINK_COLOR = C_LINK_COLOR; LINK_HIGHLIGHTED_COLOR = C_LINK_HIGHLIGHTED_COLOR; } else if (MonoOrColor == COLOR_MODE && fancyscheme == 1) { TEXT_COLOR = F1_TEXT_COLOR; BOLD_COLOR = F1_BOLD_COLOR; ITALIC_COLOR = F1_ITALIC_COLOR; BORDER_BOX_COLOR = F1_BORDER_COLOR; BORDER_TEXT_COLOR = F1_BORDER_TEXT_COLOR; LINK_COLOR = F1_LINK_COLOR; LINK_HIGHLIGHTED_COLOR = F1_LINK_HIGHLIGHTED_COLOR; } else if (MonoOrColor == COLOR_MODE && fancyscheme == 2) { TEXT_COLOR = F2_TEXT_COLOR; BOLD_COLOR = F2_BOLD_COLOR; ITALIC_COLOR = F2_ITALIC_COLOR; BORDER_BOX_COLOR = F2_BORDER_COLOR; BORDER_TEXT_COLOR = F2_BORDER_TEXT_COLOR; LINK_COLOR = F2_LINK_COLOR; LINK_HIGHLIGHTED_COLOR = F2_LINK_HIGHLIGHTED_COLOR; } else { TEXT_COLOR = M_TEXT_COLOR; BOLD_COLOR = M_BOLD_COLOR; ITALIC_COLOR = M_ITALIC_COLOR; BORDER_BOX_COLOR = M_BORDER_COLOR; BORDER_TEXT_COLOR = M_BORDER_TEXT_COLOR; LINK_COLOR = M_LINK_COLOR; LINK_HIGHLIGHTED_COLOR = M_LINK_HIGHLIGHTED_COLOR; } if (AsciiExtendedChars == 0) { strcpy (Border22f, "+-+( )+-+"); strcpy (Border22if, "+-+( )+-+"); BarBlock1 = '.'; BarBlock2 = '#'; } show_mouse (); move_mouse (80, 25); drawmenu (); html_view (showcommand, base_dir, home_page, help_page); free (showcommand); hide_mouse (); if ((oldscreen != 0) && (forcemono == 0)) { load_window (X, Y, W, H, oldscreen); free (oldscreen); } conio_exit (); gotoxy (oldcursorx, oldcursory); return 0; }
NOCONSOLE_MAIN_QTHREAD(int, argc, char**, argv) { #else MAIN_QTHREAD(int, argc, char**, argv) { #endif /* NOCONSOLE */ #else int main(int argc, char **argv) { ERROR_MSG("QT not found, install and recompile."); #endif /* __GUI__ */ try { if (!parse_args(argc, argv)) return -1; // variables range.push_back(-1.0); // default range min range.push_back(1.0); // default range max string conf_fname, diff_fname; // show mat images list<string> *argmats = new list<string>(); list<string>::iterator i; for (int i = 1; i < argc; ++i) { // check for options try { if (!strcmp(argv[i], "-conf")) { ++i; if (i >= argc) throw 0; conf_fname = argv[i]; } else if (!strcmp(argv[i], "-diff")) { ++i; if (i >= argc) throw 0; diff_fname = argv[i]; } else if (!strcmp(argv[i], "-zoom")) { ++i; if (i >= argc) throw 0; zoom = (float) atof(argv[i]); } else if (!strcmp(argv[i], "-maxwidth")) { ++i; if (i >= argc) throw 0; maxwidth = (int) atoi(argv[i]); } else if (!strcmp(argv[i], "-video")) { video = true; } else if (!strcmp(argv[i], "-print")) { print = true; } else if (!strcmp(argv[i], "-interleaved")) { interleaved = true; } else if (!strcmp(argv[i], "-save_individually")) { save_individually = true; } else if (!strcmp(argv[i], "-filename")) { show_filename = true; } else if (!strcmp(argv[i], "-range")) { range.clear(); ++i; if (i >= argc) throw 0; string s = argv[i]; int k = 0; while (s.size()) { uint j; for (j = 0; j < s.size(); ++j) if (s[j] == ',') break ; string s0 = s.substr(0, j); if (j >= s.size()) s = ""; else s = s.substr(j + 1, s.size()); range.push_back(atof(s0.c_str())); k++; } cout << "Fixing input range to " << range[0] << " .. " << range[1] << endl; fixed_range = true; } // enqueue file names else { cout << argv[i] << endl; argmats->push_back(argv[i]); } } catch (int err) { cerr << "input error: "; switch (err) { case 0: cerr << "expecting string after " << argv[i-1]; break; case 1: cerr << "expecting integer after " << argv[i-1]; break; case 2: cerr << "unknown parameter " << argv[i-1]; break; case 3: cerr << "unknown channel mode " << argv[i-1]; break; default: cerr << "undefined error"; } cerr << endl << endl; return false; } } // load configuration in conf mode if (conf_fname.size() > 0) { conf = new configuration(conf_fname); if (!conf->exists("root2")) { string dir = dirname(conf_fname.c_str()); cout << "Looking for trained files in: " << dir << endl; conf->set("root2", dir.c_str()); conf->resolve(); } // enable auto range by default in conf mode if (!fixed_range) autorange = true; } // diff mode, just print matrices differences if (!diff_fname.empty()) { i = argmats->begin(); idx<double> m1 = load_matrix<double>((*i).c_str()); idx<double> m2 = load_matrix<double>(diff_fname); if (!m1.same_dim(m2.get_idxdim())) { eblerror("cannot compare matrices of different dimensions " << m1 << " and " << m2); return -1; } idx_sub(m1, m2); double sum = idx_sum(m1); cout << "sum(m1 - m2) = " << sum << endl; return 0; } // display first matrix/image i = argmats->begin(); if (!video) { if (!load_display(i, true, argmats)) { ERROR_MSG("failed to load image(s)"); return -1; } } // explore working directory for more images only if a // single file was passed if (argmats->size() == 1) explore = true; #ifdef __GUI__ #ifdef __BOOST__ // list all other mat files in image directory string dir = argv[1]; string imgname, tmpname; size_t pos = dir.find_last_of('/'); if (pos == string::npos) { imgname = dir; dir = "./"; } else { // it contains a directory imgname = dir.substr(pos + 1, dir.size() - pos + 1); dir = dir.substr(0, pos); } list<string> *mats = argmats; if (explore) mats = find_fullfiles(dir, IMAGE_PATTERN_MAT, NULL, true, false); // video mode if (video) { string out; out << "video_" << tstamp(); mkdir_full(out); uint j = 0; for (i = mats->begin(); i != mats->end(); ++i, ++j) { cout << "video mode: displaying " << *i << endl; if (!load_display(i, true, mats)) { ERROR_MSG("failed to load image(s)"); return -1; } millisleep(3000); ostringstream fname; fname << out << "/" << setfill('0') << setw(4) << j << "_" << ebl::basename(i->c_str()) << ".png"; save_window(fname.str().c_str()); cout << "video mode: saved " << fname.str() << endl; } } else { // interactive mode if ((mats) && (mats->size() >= 1)) { // find current position in this list for (i = mats->begin(); i != mats->end(); ++i) { tmpname = ebl::basename(i->c_str()); if (!imgname.compare(tmpname)) break ; } if (i == mats->end()) i = mats->begin(); // loop and wait for key pressed while (1) { millisleep(50); int key = gui.pop_key_pressed(); // next/previous images only if not everuything is already displayed if (mats->size() > nh * nw) { if ((key == Qt::Key_Space) || (key == Qt::Key_Right)) { // show next image for (uint k = 0; k < nw * nh; ++k) { i++; if (i == mats->end()) { i = mats->begin(); } } load_display(i, true, mats); } else if ((key == Qt::Key_Backspace) || (key == Qt::Key_Left)) { // show previous image for (uint k = 0; k < nw * nh; ++k) { if (i == mats->begin()) i = mats->end(); i--; } load_display(i, true, mats); } } if (key == Qt::Key_I) { // show info show_info = !show_info; if (show_info) show_help = false; load_display(i, false, mats); } else if (key == Qt::Key_A) { // enable autorange autorange = !autorange; if (autorange) cout << "Enabling automatic input range." << endl; else cout << "Disabling automatic input range." << endl; load_display(i, false, mats); } else if (key == Qt::Key_H) { // show help show_help = !show_help; if (show_help) show_info = false; load_display(i, false, mats); } else if (key == Qt::Key_Y) { // increase number of images shown on height axis if (nh * nw < mats->size()) nh++; load_display(i, false, mats); } else if (key == Qt::Key_T) { // decrease number of images shown on height axis nh = (std::max)((uint) 1, nh - 1); load_display(i, false, mats); } else if (key == Qt::Key_X) { // increase number of images shown on width axis if (nh * nw < mats->size()) nw++; load_display(i, false, mats); } else if (key == Qt::Key_Z) { // decrease number of images shown on width axis nw = (std::max)((uint) 1, nw - 1); load_display(i, false, mats); } else if (key == Qt::Key_0) { // show only channel 0 chans = 0; load_display(i, false, mats); cout << "Showing channel 0 only." << endl; } else if (key == Qt::Key_1) { // show only channel 1 chans = 1; load_display(i, false, mats); cout << "Showing channel 1 only." << endl; } else if (key == Qt::Key_2) { // show only channel 2 chans = 2; load_display(i, false, mats); cout << "Showing channel 2 only." << endl; } else if (key == Qt::Key_9) { // show all channels chans = -1; load_display(i, false, mats); cout << "Showing alls channel." << endl; } } } } // free objects if (mats) delete mats; #endif /* __BOOST__ */ #endif /* __GUI__ */ if (argmats) delete argmats; if (conf) delete conf; } catch(string &err) { ERROR_MSG(err.c_str()); } millisleep(500); // TODO: this lets time for window to open, fix this issue return 0; }
void html_view (const char *target, char *base_dir, char *home_page, const char *help_page) { struct eventState *pes = 0; char *p, *q; char fullpath[257]; char target_name[257]; char *after_base_dir; int pleaseLoad = 1; if (pesListInitialise () == FAIL) return; if (target == 0) *target_name = 0; else strcpy (target_name, target); strcpy (fullpath, base_dir); while (1) { if (pleaseLoad) { if (*target_name == 0 || *target_name == '#') { strcpy (fullpath, base_dir); /* Cosmetic: since default home_page is in ..\help clear the .. and take a directory of the base directory if possible. When files aren't found, the error msgs will look better: */ if (home_page[0] == '.' && home_page[1] == '.' && *base_dir != 0) { char *forwardslash, *backwardslash; char *lastchar; lastchar = fullpath + strlen (fullpath) - 1; if (*lastchar == '\\' || *lastchar == '/') *lastchar = 0; forwardslash = strrchr (fullpath, '/'); backwardslash = strrchr (fullpath, '\\'); after_base_dir = (forwardslash > backwardslash) ? forwardslash : backwardslash; if (after_base_dir == 0) after_base_dir = fullpath; strcpy (after_base_dir, home_page + 2); } else { after_base_dir = fullpath + strlen (fullpath); strcat (after_base_dir, home_page); } q = target_name; } else { after_base_dir = fullpath + strlen (fullpath); for (q = target_name, p = after_base_dir; (*q != 0) && (*q != '#'); q++, p++) *p = *q; *p = 0; } if (pes) if (pes->hidden) pes = pesListBackward (); /* The following strange combination of an if and a ? is there to compare pes->filename and fullpath, so as not to create the pes if the desired file is already the current page. But if pes is 0, then it can't be the current page, and also there is nothing to compare. So if pes is 0, we wish to create the pes for sure - hence the ': 1' condition. -RP */ if (pes ? stricmp (pes->filename, fullpath) : 1) { /* Attempt to create a new pes in the list */ if ((pes = pesListAdd (fullpath, home_page)) != 0) { preparepes (pes); } else { readFileError(after_base_dir); if ((pes = pesListCurrent ()) == 0) return; q = NULL; } } if (q != 0) pes->link_text = (*q != 0) ? q : 0; else pes->link_text = 0; } *after_base_dir = 0; /* Truncate fullpath to just base_dir */ switch (html_view_internal (pes, base_dir, home_page)) { case NAVIGATE_BACK: pes->seek_base = backBookmark(pes); if (pes->seek_base) { pes->seek_cnt = -1; pes->clink = NULL; pleaseLoad = 0; break; } save_window (X, Y, W, H - 3, pes->screen_buf); if ((pes = pesListBackward ()) == 0) { pesListDestroy (); return; } pes->left_was_pressed = 0; load_window (X, Y, W, H - 3, pes->screen_buf); pleaseLoad = 0; break; case NAVIGATE_LINK: save_window (X, Y, W, H - 3, pes->screen_buf); if (pes->text_holder != 0) { /* Start the target_name off with the current files' path */ char *forwardslash, *backwardslash; strcpy (target_name, pes->filename); /* Find the last / or \ and truncate the string */ forwardslash = strrchr (target_name, '/'); backwardslash = strrchr (target_name, '\\'); p = (forwardslash > backwardslash) ? forwardslash : backwardslash; if (p != NULL) *p = 0; else *target_name = 0; /* Clip off directories, if the target goes 'up' the directory tree with ".."s. */ while ((strncmp (pes->text_holder, "..", 2) == 0) && (p != NULL)) { forwardslash = strrchr (target_name, '/'); backwardslash = strrchr (target_name, '\\'); p = (forwardslash > backwardslash) ? forwardslash : backwardslash; if (p != NULL) { *p = 0; /* modify target name */ /* Cut out the .. by copying backwards */ /* first make sure the string isn't just ".." */ if (strlen (pes->text_holder) >= 3) { p = pes->text_holder; while (p[2] != 0) { *p = p[3]; /* fixed. changed from 2 to 3. 9-MAR-04 RP */ ++p; } } else /* treat as just "index.htm" */ strcpy (pes->text_holder, "index.htm"); } } /* Minor fix: changed || into && here - RP 2004 */ if ((*(pes->text_holder) != '/') && (*(pes->text_holder) != '\\') && (target_name[strlen (target_name)] != '/') && (target_name[strlen (target_name)] != '\\') && *target_name != 0) strcat (target_name, "\\"); strcat (target_name, pes->text_holder); /* Since the target link is relative to the present link, there is no need for the fullpath to contain the base directory: */ *fullpath = 0; } else *target_name = 0; pleaseLoad = 1; *pes->text_holder = 0; break; case NAVIGATE_FORWARD: pes->seek_base = forwardBookmark(pes); if (pes->seek_base) { pes->seek_cnt = -1; pes->clink = NULL; pleaseLoad = 0; break; } save_window (X, Y, W, H - 3, pes->screen_buf); if ((pes = pesListForward ()) != 0) load_window (X, Y, W, H - 3, pes->screen_buf); else pes = pesListCurrent (); pes->left_was_pressed = 0; pleaseLoad = 0; break; case NAVIGATE_HOME: save_window (X, Y, W, H - 3, pes->screen_buf); *fullpath = 0; *target_name = 0; pleaseLoad = 1; break; case NAVIGATE_HELP: save_window (X, Y, W, H - 3, pes->screen_buf); /* help_page NOT relative to current page, but to base directory: */ strcpy (fullpath, base_dir); strcpy (target_name, help_page); pleaseLoad = 1; break; case NAVIGATE_EXIT: pesListDestroy (); return; case NAVIGATE_REFRESH: strcpy (target_name, pes->filename); *fullpath = 0; pes = pesListBackward (); pleaseLoad = 1; break; case NAVIGATE_SEARCH: save_window (X, Y, W, H - 3, pes->screen_buf); if ((pes = helpsearch (pes, base_dir, home_page)) != NULL) { pesListDeleteForwards (); preparepes (pes); pes->link_text = 0; *fullpath = 0; } else pes = pesListCurrent (); pleaseLoad = 0; break; default: pleaseLoad = 0; } } /* END while(1) */ }
int html_view_internal (struct eventState *pes, char *base_dir, char *home_page) { int i; if (pes->link_text != 0) { statusbar (hcatStatusLooking); if (*pes->link_text == '#') { char *anchor; if (strnicmp (pes->link_text + 1, HTMLHELP_INTERNAL_SEARCHLINK, strlen (HTMLHELP_INTERNAL_SEARCHLINK)) == 0) { /* Internal search engine link */ anchor = pes->body_start + atoi (pes->link_text + strlen (HTMLHELP_INTERNAL_SEARCHLINK) + 1); } else { sprintf (pes->text_holder, "<a name=\"%.*s\"", link_length (pes->link_text + 1), pes->link_text + 1); anchor = strstr (pes->body_start, pes->text_holder); } if (anchor) { /* Locate start of line. */ while (anchor != pes->body_start && *anchor != '\n') anchor--; if (*anchor == '\n') anchor++; /* Move to this line, just near top of screen */ if (!pes->first_time) addBookmark(pes); pes->seek_base = anchor; pes->seek_cnt = -1; pes->clink = 0; /* RP - Added 5.3.2 */ pes->link_text = 0; *pes->text_holder = 0; statusbar (NULL); return NAVIGATE_DONT; } else { int triedasfile = 0; int tryexact = 1; sprintf (pes->text_holder, "%.*s", link_length (pes->link_text + 1), pes->link_text + 1); strlwr (pes->text_holder); write_string (TEXT_COLOR, X + strlen(hcatStatusLooking) + 3, TY, hcatStatusEscape); do { pes->p = pes->body_start; while ((pes->p = strstr (pes->p, "<a")) != 0) { static struct event ev; get_event (&ev, EV_KEY | EV_NONBLOCK); if (ev.ev_type == EV_KEY && ev.key == 27) { pes->link_text = 0; show_error(hcatUserAborted); return NAVIGATE_DONT; } pes->p = strchr (pes->p, '>'); if (pes->p) { ++(pes->p); if ((strnicmp(pes->p, pes->text_holder, strlen (pes->text_holder)) == 0) && (pes->p[strlen(pes->text_holder)] == '<' || !tryexact)) { while (pes->p != pes->body_start && strncmp (pes->p, "<a", 2)) pes->p--; pes->p = strstr (pes->p, "href="); if (pes->p != 0) { pes->p += 6; if (*pes->p == '\"') pes->p++; if (*pes->p == '#') break; if (prepare_link (pes)) { if (tryexact == 0) show_error(hcatNoExactFound); return NAVIGATE_LINK; } } } } } if (triedasfile == 0) { int undostrcat = strlen (base_dir); if (base_dir[strlen (base_dir) - 1] != '\\' && base_dir[0] != 0) strcat (base_dir, "\\"); strcat (base_dir, pes->text_holder); if (checkForFile (base_dir)) { /* Didn't work */ base_dir[undostrcat] = '\0'; } else { if (pes->first_time) pes->hidden = 1; get_home_page (home_page, base_dir); get_base_dir (base_dir, base_dir); return NAVIGATE_HOME; } triedasfile = 1; } else { /* don't try to match end with the < */ if (tryexact) { tryexact = 0; } else { pes->p = pes->text_holder + strlen (pes->text_holder) - 1; if (*pes->p > 'a') --(*pes->p); else *pes->p = 0; } } } while (*(pes->text_holder) != 0); } statusbar (NULL); sprintf (pes->text_holder, "%s '%.*s'", hcatCouldntFind, link_length (pes->link_text + 1), pes->link_text + 1); show_error (pes->text_holder); pes->link_text = 0; *(pes->text_holder) = 0; return NAVIGATE_DONT; } else if (prepare_link (pes)) return NAVIGATE_LINK; pes->link_text = 0; } if (pes->first_time) { drawmenu(); save_window (X, Y, W, H, pes->screen_buf); pes->first_time = 0; } if (pes->seek_cnt != 0) { if (pes->seek_cnt <= 0) { i = -pes->seek_cnt; pes->p = pes->seek_base - 1; if (*pes->p == '\n') pes->p--; for (; (pes->p != pes->body_start); pes->p--) if (*pes->p == '\n') { i--; if (i == 0) { pes->p++; break; } } pes->top = pes->p; } else if (pes->seek_cnt > 0) { i = pes->seek_cnt; pes->p = pes->seek_base; for (; pes->p != pes->body_end; pes->p++) if (*pes->p == '\n') { i--; if (i == 0) { pes->p++; break; } } if (pes->p == pes->body_end) { pes->seek_base = pes->body_end - 1; pes->seek_cnt = -1; return NAVIGATE_DONT; } pes->top = pes->p; } pes->seek_cnt = 0; } if (pes->maxtop != 0) pes->barpos = ((pes->top - pes->body_start) * BARLEN) / pes->maxtop; else pes->barpos = BARLEN - 1; if (pes->barpos >= BARLEN || pes->barpos < 0) /* <0 fix - RP */ pes->barpos = BARLEN - 1; if (pes->bar_hooked) { pes->seek_base = pes->top; if (pes->forced_barpos == 0) { pes->top = pes->body_start; pes->barpos = 0; } else if (pes->forced_barpos == BARLEN - 1 && pes->barpos != pes->forced_barpos) { pes->old_barpos = pes->barpos; pes->seek_base = pes->body_end; pes->seek_cnt = -N; return NAVIGATE_DONT; } else if (pes->forced_barpos < pes->barpos && pes->forced_barpos < pes->old_barpos) { pes->old_barpos = pes->barpos; pes->seek_cnt = -1; return NAVIGATE_DONT; } else if (pes->forced_barpos > pes->barpos && pes->forced_barpos > pes->old_barpos) { pes->old_barpos = pes->barpos; pes->seek_cnt = +1; return NAVIGATE_DONT; } } pes->old_barpos = pes->barpos; if (pes->top != pes->old_top) pes->force_redraw = 1; /* ------ Display processing ------------------------------------ */ displayProcess (pes); /* ------ Event processing -------------------------------------- */ return processEvents (pes); }
MAIN_QTHREAD(int, argc, char **, argv) { // macro to enable multithreaded gui #else int main(int argc, char **argv) { // regular main without gui #endif try { // check input parameters if ((argc != 2) && (argc != 3) ) { cerr << "warning: wrong number of parameters." << endl; cerr << "usage: detect <config file> [directory or file]" << endl; // return -1; } #ifdef __LINUX__ feenableexcept(FE_DIVBYZERO | FE_INVALID); // enable float exceptions #endif // load configuration configuration conf(argv[1], true, true, false); if (conf.exists_true("fixed_randomization")) cout << "Using fixed seed: " << fixed_init_drand() << endl; else cout << "Using random seed: " << dynamic_init_drand(argc, argv) << endl; if (!conf.exists("root2") || !conf.exists("current_dir")) { string dir; dir << dirname(argv[1]) << "/"; cout << "Looking for trained files in: " << dir << endl; conf.set("root2", dir.c_str()); conf.set("current_dir", dir.c_str()); } conf.set("run_type", "detect"); // tell conf that we are in detect mode conf.resolve(); // manual call to resolving variable bool silent = conf.exists_true("silent"); if (conf.exists_true("show_conf") && !silent) conf.pretty(); // output synchronization bool sync = conf.exists_true("sync_outputs"); mutex out_mutex; mutex_ostream mutout(std::cout, &out_mutex, "Thread M"); mutex_ostream muterr(std::cerr, &out_mutex, "Thread M"); ostream &mout = sync ? mutout : cout; ostream &merr = sync ? muterr : cerr; bootstrapping<t_net> boot(conf); // output dir string outdir = detection_thread<t_net>::get_output_directory(conf); mout << "Saving outputs to " << outdir << endl; // save conf to output dir string cname = outdir; cname << filename(argv[1]); if (conf.write(cname.c_str())) mout << "Wrote configuration to " << cname << endl; // load classes of network idx<ubyte> classes(1,1); vector<string> sclasses; try { // try loading classes names but do not stop upon failure load_matrix<ubyte>(classes, conf.get_cstring("classes")); } catch(string &err) { merr << "warning: " << err << endl; } sclasses = ubyteidx_to_stringvector(classes); t_bbox_saving bbsaving = bbox_none; if (conf.exists("bbox_saving")) bbsaving = (t_bbox_saving) conf.get_int("bbox_saving"); bboxes boxes(bbsaving, &outdir, mout, merr); uint ipp_cores = 1; if (conf.exists("ipp_cores")) ipp_cores = conf.get_uint("ipp_cores"); ipp_init(ipp_cores); // limit IPP (if available) to 1 core bool save_video = conf.exists_true("save_video"); bool save_detections = conf.exists_true("save_detections"); int height = -1; int width = -1; if (conf.exists("input_height")) height = conf.get_int("input_height"); if (conf.exists("input_width")) width = conf.get_int("input_width"); bool input_random = conf.exists_true("input_random"); uint npasses = 1; char next_on_key = 0; if (conf.exists("next_on_key")) { next_on_key = conf.get_char("next_on_key"); mout << "Press " << next_on_key << " to process next frame." << endl; } uint skip_frames = conf.try_get_uint("skip_frames", 0); if (conf.exists("input_npasses")) npasses = conf.get_uint("input_npasses"); string viddir; if (save_video) { viddir << outdir << "video/"; mkdir_full(viddir); } bool precomputed_boxes = conf.exists("bbox_file"); uint save_bbox_period = conf.try_get_uint("save_bbox_period", 500); idxdim crop(1, 1, 1); if (conf.exists("input_crop")) crop = string_to_idxdim(conf.get_string("input_crop")); string cam_type; #ifdef __LINUX__ // default camera for linux if not defined cam_type = "v4l2"; #endif if (conf.exists("camera")) cam_type = conf.get_string("camera"); // allocate threads uint nthreads = 1; bool updated = false; idx<ubyte> detframe; // frame returned by detection thread uint frame_id = 0; svector<midx<t_net> > all_samples, samples; // extracted samples bboxes all_bbsamples, bbsamples; // boxes corresponding to samples if (conf.exists("nthreads")) nthreads = (std::max)((uint) 1, conf.get_uint("nthreads")); list<detection_thread<t_net>*> threads; list<detection_thread<t_net>*>::iterator ithreads; idx<uint> total_saved(nthreads); idx_clear(total_saved); mout << "Initializing " << nthreads << " detection threads." << endl; for (uint i = 0; i < nthreads; ++i) { detection_thread<t_net> *dt = new detection_thread<t_net>(conf, &out_mutex, NULL, NULL, sync); threads.push_back(dt); dt->start(); } // image search can be configured with a search pattern const char *fpattern = IMAGE_PATTERN_MAT; if (conf.exists("file_pattern")) fpattern = conf.get_cstring("file_pattern"); // initialize camera (opencv, directory, shmem or video) idx<ubyte> frame(std::max(height, 1), std::max(width, 1), 3); camera<ubyte> *cam = NULL, *cam2 = NULL; if (!strcmp(cam_type.c_str(), "directory")) { string dir; if (argc >= 3) // read input dir from command line dir = argv[2]; else if (conf.exists("input_dir")) dir = conf.get_string("input_dir"); // given list list<string> files; if (conf.exists("input_list")) { files = string_to_stringlist(conf.get_string("input_list")); cam = new camera_directory<ubyte>(dir.c_str(), height, width, input_random, npasses, mout, merr, fpattern, &files); } else // given directory only cam = new camera_directory<ubyte>(dir.c_str(), height, width, input_random, npasses, mout, merr, fpattern, &files); } else if (!strcmp(cam_type.c_str(), "opencv")) cam = new camera_opencv<ubyte>(-1, height, width); #ifdef __LINUX__ else if (!strcmp(cam_type.c_str(), "v4l2")) cam = new camera_v4l2<ubyte>(conf.get_cstring("device"), height, width, conf.exists_true("camera_grayscale"), conf.exists_true("camera_rgb")); else if (!strcmp(cam_type.c_str(), "mac")) cam = new camera_mac<ubyte>(conf.get_cstring("device"), height, width, conf.exists_true("camera_grayscale"), conf.exists_true("camera_rgb")); else if (!strcmp(cam_type.c_str(), "mcams")) { vector<string> devices = conf.get_all_strings("device"); cam = new camera_mcams<ubyte>(conf, devices, height, width, conf.exists_true("camera_grayscale"), conf.exists_true("camera_rgb")); } #endif #ifdef __KINECT__ else if (!strcmp(cam_type.c_str(), "kinect")) cam = new camera_kinect<ubyte>(height, width); #endif else if (!strcmp(cam_type.c_str(), "shmem")) cam = new camera_shmem<ubyte>("shared-mem", height, width); else if (!strcmp(cam_type.c_str(), "video")) { if (argc >= 3) cam = new camera_video<ubyte> (argv[2], height, width, conf.get_uint("input_video_sstep"), conf.get_uint("input_video_max_duration")); else eblerror("expected 2nd argument"); } else if (!strcmp(cam_type.c_str(), "datasource")) { cam = new camera_datasource<ubyte,int>(conf); } else eblerror("unknown camera type, set \"camera\" in your .conf"); // a camera directory may be used first, then switching to regular cam if (conf.exists_true("precamera")) cam2 = new camera_directory<ubyte>(conf.get_cstring("precamdir"), height, width, input_random, npasses, mout, merr, fpattern); if (conf.exists_true("camera_grayscale")) cam->set_grayscale(); if (conf.exists_true("silent")) cam->set_silent(); // answer variables & initializations bboxes bb; // gui #ifdef __GUI__ bool bkey_msg = false; // display key message bool display = conf.exists_bool("display"); bool show_parts = conf.exists_true("show_parts"); bool bbox_show_conf = !conf.exists_false("bbox_show_conf"); bool bbox_show_class = !conf.exists_false("bbox_show_class"); // mindisplay = conf.exists_bool("minimal_display"); uint display_sleep = 0; if (conf.exists("display_sleep")) display_sleep = conf.get_uint("display_sleep"); // display_states = conf.exists_bool("display_states"); // uint qstep1 = 0, qheight1 = 0, qwidth1 = 0, // qheight2 = 0, qwidth2 = 0, qstep2 = 0; // if (conf.exists_bool("queue1")) { // qstep1 = conf.get_uint("qstep1"); // qheight1 = conf.get_uint("qheight1"); // qwidth1 = conf.get_uint("qwidth1"); } // if (conf.exists_bool("queue2")) { // qstep2 = conf.get_uint("qstep2"); // qheight2 = conf.get_uint("qheight2"); // qwidth2 = conf.get_uint("qwidth2"); } // wid_states = display_states ? new_window("network states"):0; // night_mode(); uint wid = display ? new_window("eblearn object recognition") : 0; night_mode(); float display_transp = 0.0; if (conf.exists("display_bb_transparency")) display_transp = conf.get_float("display_bb_transparency"); detector_gui<t_net> dgui(conf.exists_true("show_extracted")); #endif // timing variables timer tpass, toverall, tstop; uint cnt = 0; bool stop = false, finished = false; // loop toverall.start(); while (!finished) { // check for results and send new image for each thread uint i = 0; finished = true; for (ithreads = threads.begin(); ithreads != threads.end(); ++ithreads, ++i) { // do nothing if thread is finished already if ((*ithreads)->finished()) continue ; finished = false; // a thread is not finished string processed_fname; uint processed_id = 0; // retrieve new data if present bool skipped = false; updated = (*ithreads)->get_data (bb, detframe, *(total_saved.idx_ptr() + i), processed_fname, &processed_id, &samples, &bbsamples, &skipped); if (skipped) cnt++; // a new skipped frame was received // save bounding boxes if (updated) { idxdim d(detframe); if (boot.activated()) bb.clear(); if (bbsaving != bbox_none) { if (!silent) mout << "Adding " << bb.size() << " boxes into new group: " << processed_fname << " with id " << processed_id << endl; boxes.new_group(d, &processed_fname, processed_id); boxes.add(bb, d, &processed_fname, processed_id); if (cnt % save_bbox_period == 0) boxes.save(); // avoid sample accumulation if not using bootstrapping if (boot.activated()) mout << "Received " << samples.size() << " bootstrapping samples." << endl; } if (conf.exists_true("bootstrapping_save")) { all_samples.push_back_new(samples); all_bbsamples.push_back_new(bbsamples); } // datasource mode, check and log answers if (dynamic_cast<camera_datasource<ubyte,int>*>(cam)) { camera_datasource<ubyte,int>* dscam = (camera_datasource<ubyte,int>*) cam; dscam->log_answers(bb); } cnt++; // display processed frame #ifdef __GUI__ if (display) { select_window(wid); disable_window_updates(); clear_resize_window(); set_window_title(processed_fname.c_str()); uint h = 0, w = 0; // display frame with resulting boxes dgui.display_minimal (detframe, bb, ((*ithreads)->pdetect ? (*ithreads)->pdetect->get_labels() : sclasses), h, w, 1, 0, 255, wid, show_parts, display_transp, bbox_show_class, bbox_show_conf, &bbsamples); // display extracted samples if (boot.activated()) { dgui.display_preprocessed (samples, bbsamples, ((*ithreads)->pdetect ? (*ithreads)->pdetect->get_labels() : sclasses), h, w, 1, -1, 1); } enable_window_updates(); if (save_video && display) { string fname; fname << viddir << processed_fname; save_window(fname.c_str()); if (!silent) mout << "saved " << fname << endl; } } // sleep display if (display_sleep > 0) { mout << "sleeping for " << display_sleep << "ms." << endl; millisleep(display_sleep); } #endif if (!silent) { // output info uint k = cnt, tot = cam->size() - cnt; // progress variables if (conf.exists("save_max")) tot = conf.get_uint("save_max"); if (!silent) { if (save_detections) { mout << "total_saved=" << idx_sum(total_saved); if (conf.exists("save_max")) mout << " / " << tot; mout << endl; } } if (boot.activated()) mout << "total_bootstrapping=" << all_samples.size() << endl; mout << "remaining=" << (cam->size() - cnt) << " elapsed=" << toverall.elapsed(); if (cam->size() > 0) mout << " ETA=" << toverall.eta(cnt, cam->size()); if (conf.exists("save_max") && save_detections) { k = idx_sum(total_saved); mout << " save_max_ETA=" << toverall.eta(k, tot); } mout << endl; mout << "i=" << cnt << " processing: " << tpass.elapsed_ms() << " fps: " << cam->fps() << endl; // save progress if (!conf.exists_false("save_progress")) job::write_progress(k, tot); } } // check if ready if ((*ithreads)->available()) { if (stop) (*ithreads)->ask_stop(); // stop but let thread finish else { // grab a new frame if available if (cam->empty()) { stop = true; tstop.start(); // start countdown timer (*ithreads)->ask_stop(); // ask this thread to stop millisleep(50); } else { #ifdef __GUI__ int key = gui.pop_key_pressed(); // if thread has already received data, wait for next key if ((*ithreads)->fed() && next_on_key) { if ((int)next_on_key != key && (int)next_on_key != key + 32) { if (!bkey_msg) mout << "Press " << next_on_key << " to process next frame." << endl; bkey_msg = true; continue ; // pause until key is pressed } else { mout << "Key pressed (" << key << ") allowing next frame to process." << endl; bkey_msg = false; tpass.restart(); } } #endif bool frame_grabbed = false; frame_id = cam->frame_id(); // if the pre-camera is defined use it until empty if (cam2 && !cam2->empty()) frame = cam2->grab(); else { // empty pre-camera, use regular camera if (skip_frames > 0) cam->skip(skip_frames); // skip frames if skip_frames > 0 if (cam->empty()) continue ; if (precomputed_boxes && !save_video) cam->next(); // move to next frame but without grabbing else if (dynamic_cast<camera_directory<ubyte>*>(cam)) { cam->grab_filename(); // just get the filename, no data } else { // actually grab the frame frame = cam->grab(); frame_grabbed = true; // cropping if (crop.nelements() > crop.order()) { cout << "cropping frame from " << frame; for (uint i = 0; i < crop.order(); ++i) if (crop.dim(i) > 1) frame = frame.narrow(i, crop.dim(i), 0); cout << " to " << frame << endl; } } } // send new frame to this thread string ffname = cam->frame_fullname(); string fname = cam->frame_name(); if (frame_grabbed) { while (!(*ithreads)->set_data(frame, ffname, fname, frame_id)) millisleep(5); } else { while (!(*ithreads)->set_data(ffname, fname, frame_id)) millisleep(5); } // we just sent a new frame tpass.restart(); } } } } if ((conf.exists("save_max") && !stop && idx_sum(total_saved) > conf.get_uint("save_max")) || (boot.activated() && (intg) all_samples.size() > boot.max_size())) { mout << "Reached max number of detections, exiting." << endl; stop = true; // limit number of detection saves tstop.start(); // start countdown timer } // sleep a bit between each iteration millisleep(5); // check if stop countdown reached 0 if (stop && tstop.elapsed_minutes() >= 20) { cerr << "threads did not all return 20 min after request, stopping" << endl; break ; // program too long to stop, force exit } } // saving boxes if (bbsaving != bbox_none) boxes.save(); mout << "Execution time: " << toverall.elapsed() << endl; if (save_video) cam->stop_recording(conf.exists_bool("use_original_fps") ? cam->fps() : conf.get_uint("save_video_fps"), outdir.c_str()); // saving bootstrapping if (conf.exists_true("bootstrapping_save") && boot.activated()) boot.save_dataset(all_samples, all_bbsamples, outdir, classes); // free variables if (cam) delete cam; for (ithreads = threads.begin(); ithreads != threads.end(); ++ithreads) { if (!(*ithreads)->finished()) (*ithreads)->stop(); // stop thread without waiting delete *ithreads; } #ifdef __GUI__ if (!conf.exists_true("no_gui_quit") && !conf.exists("next_on_key")) { mout << "Closing windows..." << endl; quit_gui(); // close all windows mout << "Windows closed." << endl; } #endif job::write_finished(); // declare job finished mout << "Detection finished." << endl; // evaluation of bbox if (conf.exists_true("evaluate") && conf.exists("evaluate_cmd")) { string cmd; cmd << "cd " << outdir << " && " << conf.get_string("evaluate_cmd"); int res = std::system(cmd.c_str()); if (res != 0) cerr << "bbox evaluation failed with command " << cmd << endl; } } eblcatcherror(); return 0; }