コード例 #1
0
ファイル: padder.hpp プロジェクト: 2php/eblearn
 void padder<T>::mirror(idx<T> &in, idx<T> &padded) {
   idx<T> tmp, tmp2;
   int i;
   // mirror border left
   for (i = std::max(0, (int) (ncol - in.dim(1) / 2)); i < ncol; ++i) {
     tmp2 = in.narrow(1, 1, ncol - i - 1);
     tmp = padded.narrow(1, 1, i);
     tmp = tmp.narrow(2, in.dim(2), ncol);
     idx_copy(tmp2, tmp);
   }
   // mirror border right
   for (i = std::max(0, (int) (ncol - in.dim(1) / 2)); i < ncol; ++i) {
     tmp2 = in.narrow(1, 1, in.dim(1) - ncol - 1 + i);
     tmp = padded.narrow(1, 1, padded.dim(1) - 1 - i);
     tmp = tmp.narrow(2, in.dim(2), ncol);
     idx_copy(tmp2, tmp);
   }
   // mirror border top using out as input
   for (i = std::max(0, (int) (nrow - in.dim(2) / 2)); i < nrow; ++i) {
     tmp2 = padded.narrow(2, 1, nrow + nrow - i - 1);
     tmp = padded.narrow(2, 1, i);
     idx_copy(tmp2, tmp);
   }
   // mirror border bottom using out as input
   for (i = std::max(0, (int) (nrow - in.dim(2) / 2)); i < nrow; ++i) {
     tmp2 = padded.narrow(2, 1, padded.dim(2) - nrow * 2 - 1 + i);
     tmp = padded.narrow(2, 1, padded.dim(2) - 1 - i);
     idx_copy(tmp2, tmp);
   }    
 }
コード例 #2
0
ファイル: padder.hpp プロジェクト: 1292765944/MobileDemo
idx<T> image_region_to_rect(idx<T> &im, const rect<int> &r, uint oheight,
                            uint owidth, rect<int> *cropped,
                            uint dh, uint dw)
{
    // TODO: check that rectangle is within image
    if (im.order() != 2 && im.order() != 3)
        eblerror("expected a 2d or 3d input but got " << im);
    idxdim d(im);
    d.setdim(dh, oheight);
    d.setdim(dw, owidth);
    idx<T> res(d);

    float hcenter = r.h0 + (float)r.height / 2; // input height center
    float wcenter = r.w0 + (float)r.width / 2; // input width center
    // // limit centers to half the width/height away from borders
    // // to handle incorrect regions
    // hcenter = MIN((float)im.dim(dh) - (float)r.height/2,
    //            std::max((float)r.height/2, hcenter));
    // wcenter = MIN((float)im.dim(dw) - (float)r.width/2,
    //            std::max((float)r.width/2, wcenter));
    float h0 = hcenter - (float)oheight / 2; // out height offset in input
    float w0 = wcenter - (float)owidth / 2; // out width offset in input
    float h1 = hcenter + (float)oheight / 2;
    float w1 = wcenter + (float)owidth / 2;
    int gh0 = (int)std::max(0, (int)MIN(im.dim(dh), h0)); // input h offset
    int gw0 = (int)std::max(0, (int)MIN(im.dim(dw), w0)); // input w offset
    int gh1 = (int)std::max(0, (int)MIN(im.dim(dh), h1));
    int gw1 = (int)std::max(0, (int)MIN(im.dim(dw), w1));
    int h = gh1 - gh0 + std::max(0, -r.h0); // out height narrow
    int w = gw1 - gw0 + std::max(0, -r.w0); // out width narrow
    int fh0 = (int)std::max(0, (int)(gh0 - h0)); // out height offset narrow
    int fw0 = (int)std::max(0, (int)(gw0 - w0)); // out width offset narrow

    // narrow original image
    int hmin = std::max(0, std::min((int)res.dim(dh) - fh0,
                                    std::min((int)im.dim(dh) - gh0, h)));
    int wmin = std::max(0, std::min((int)res.dim(dw) - fw0,
                                    std::min((int)im.dim(dw) - gw0, w)));
    // clear result image
    idx_clear(res);
    if (hmin != 0 && wmin != 0)  // only copy if overlap with image
    {
        idx<T> tmpim = im.narrow(dh, hmin, gh0);
        tmpim = tmpim.narrow(dw, wmin, gw0);
        // narrow target image
        idx<T> tmpres = res.narrow(dh, hmin, fh0);
        tmpres = tmpres.narrow(dw, wmin, fw0);
        // copy original to target
        idx_copy(tmpim, tmpres);
    }
    // set cropped rectangle to region in the output image containing input
    if (cropped)
    {
        cropped->h0 = fh0;
        cropped->w0 = fw0;
        cropped->height = hmin;
        cropped->width = wmin;
    }
    return res;
}
コード例 #3
0
ファイル: dataset.cpp プロジェクト: 2php/eblearn
 void jitter::set(const idx<t_jitter> &j) {
   s = j.get(0);
   h = (int) j.get(1);
   w = (int) j.get(2);
   r = j.get(3);
   idx_copy(j, jitts);
 }
コード例 #4
0
ファイル: ebl_cost.hpp プロジェクト: athuls/gsra
 void euclidean_module<T1,T2,Tstate1,Tstate2>::
 fprop(Tstate1 &in1, Tstate2 &label, Tstate1 &energy) {
   idx<T1> target = targets.select(0, label.x.get());
   idx_copy(target, in2.x);
   // squared distance between in1 and target
   idx_sqrdist(in1.x, in2.x, energy.x);
   idx_dotc(energy.x, 0.5, energy.x); // multiply by .5
 }
コード例 #5
0
ファイル: ebl_cost.hpp プロジェクト: athuls/gsra
  double euclidean_module<T1,T2,Tstate1,Tstate2>::
  infer2(Tstate1 &i1, Tstate2 &infered_label, 
	 infer_param &ip, Tstate2 *label, Tstate1 *energy) {
    infered_label.x.set(0);
    Tstate1 tmp;
    idx_bloop1(e, energies, T1) {
      fprop(i1, infered_label, tmp);
      idx_copy(tmp.x, e);
      infered_label.x.set(infered_label.x.get() + 1);
    }
コード例 #6
0
ファイル: tracking_thread.hpp プロジェクト: athuls/gsra
  bool tracking_thread<Tnet>::get_data(vector<bbox*> &bboxes2,
				       idx<ubyte> &frame2, idx<ubyte> &tpl2) {
    // lock data
    pthread_mutex_lock(&mutex_out);
    // only read data if it has been updated
    if (!out_updated) {
      // unlock data
      pthread_mutex_unlock(&mutex_out);
      return false;
    }
    // clear bboxes
    for (ibox = bboxes2.begin(); ibox != bboxes2.end(); ++ibox) {
      if (*ibox)
	delete *ibox;
    }
    bboxes2.clear();
    // copy bboxes pointers (now responsible for deleting them).
    for (ibox = bboxes.begin(); ibox != bboxes.end(); ++ibox) {
      bboxes2.push_back(*ibox);
    }
    // check frame is correctly allocated, if not, allocate.
    if (frame2.order() != frame.order()) 
      frame2 = idx<ubyte>(frame.get_idxdim());
    else if (frame2.get_idxdim() != frame.get_idxdim())
      frame2.resize(frame.get_idxdim());
    // copy frame
    idx_copy(frame, frame2);    
    // check tpl is correctly allocated, if not, allocate.
    if (tpl2.order() != tpl.order()) 
      tpl2 = idx<ubyte>(tpl.get_idxdim());
    else if (tpl2.get_idxdim() != tpl.get_idxdim())
      tpl2.resize(tpl.get_idxdim());
    // copy tpl
    idx_copy(tpl, tpl2);    
    // reset updated flag
    out_updated = false; 
    // unlock data
    pthread_mutex_unlock(&mutex_out);
    // confirm that we copied data.
    return true;
  }
コード例 #7
0
ファイル: matlab.hpp プロジェクト: athuls/gsra
  void matlab::read_cast_matrix(mxArray *var, idx<T> &m) {
#ifdef __MATLAB__
    // allocate a temporary matrix with same type as original matrix type
    idx<Tmatlab> tmp(m.get_idxdim());
    // load data
    void *data = mxGetData(var);
    // copy to idx 
    memcpy(m.idx_ptr(), (Tmatlab*) data, m.nelements() * sizeof (Tmatlab));
    // copy-cast
    idx_copy(tmp, m);
#endif
  }
コード例 #8
0
ファイル: padder.hpp プロジェクト: 2php/eblearn
 void image_paste_center(idx<T> &in, idx<T> &out) {
   if (in.order() != 3 || out.order() != 3)
     eblerror("expected 3d idx but got " << in << " and " << out);
   int d0 = 1;
   int d1 = d0 + 1;
   intg ci = in.dim(d0) - out.dim(d0);
   intg cj = in.dim(d1) - out.dim(d1);
   intg xci = (int) (ci / 2);
   intg xcj = (int) (cj / 2);
   idx<T> i = in.narrow(d0, out.dim(d0), xci);
   i = i.narrow(d1, out.dim(d1), xcj);
   idx_copy(i, out);
 }
コード例 #9
0
ファイル: spDataSource.hpp プロジェクト: athuls/gsra
void spLabeledDataSource<I,L>::fprop(state_spidx *state, Idx<L> *label) {
	state->resize(
			(data->order() > 1)? data->dim(1) : -1,
			(data->order() > 2)? data->dim(2) : -1,
			(data->order() > 3)? data->dim(3) : -1,
			(data->order() > 4)? data->dim(4) : -1,
			(data->order() > 5)? data->dim(5) : -1,
			(data->order() > 6)? data->dim(6) : -1,
			(data->order() > 7)? data->dim(7) : -1);

	spIdx<I> y = data->select(0, index);
	idx_copy(y, state->x);
	Idx<L> y2 = labels->select(0, index);
	label->set(y2.get());
}
コード例 #10
0
ファイル: padder.hpp プロジェクト: 2php/eblearn
 void padder<T>::pad(idx<T> &in, idx<T> &out) {
   // allocate padded buffer
   idxdim d = in;
   d.setdim(1, d.dim(1) + nrow + nrow2);
   d.setdim(2, d.dim(2) + ncol + ncol2);
   if (out.get_idxdim() != d)
     out.resize(d);
   idx_clear(out);
   // copy in to padded buffer
   idx<T> tmp = out.narrow(1, in.dim(1), nrow);
   tmp = tmp.narrow(2, in.dim(2), ncol);
   idx_copy(in, tmp);
   if (bmirror)
     mirror(in, out);
 }
コード例 #11
0
ファイル: padder.hpp プロジェクト: 2php/eblearn
 idx<T> padder<T>::pad(idx<T> &in) {
   // allocate padded buffer
   idxdim d = in;
   d.setdim(1, d.dim(1) + nrow + nrow2);
   d.setdim(2, d.dim(2) + ncol + ncol2);
   idx<T> out(d);
   idx_clear(out);
   // copy in to padded buffer
   idx<T> tmp = out.narrow(1, in.dim(1), nrow);
   tmp = tmp.narrow(2, in.dim(2), ncol);
   idx_copy(in, tmp);
   if (bmirror)
     mirror(in, out);
   // return result
   return out;
 }
コード例 #12
0
ファイル: detection_thread.hpp プロジェクト: 2php/eblearn
bool detection_thread<T>::set_data(idx<ubyte> &frame2,
                                   std::string &fullname,
                                   std::string &name, uint id) {
  // lock data (non blocking)
  if (!mutex_in.trylock())
    return false;
  // check frame is correctly allocated, if not, allocate.
  if (frame2.order() != uframe.order())
    uframe = idx<ubyte>(frame2.get_idxdim());
  else if (frame2.get_idxdim() != uframe.get_idxdim())
    uframe.resize(frame2.get_idxdim());
  idx_copy(frame2, uframe);	// copy frame
  frame_loaded = true;        // frame is loaded
  frame_fullname = fullname;
  frame_name = name;		// copy name
  frame_id   = id;		// copy frame_id
  in_updated = true;		// reset updated flag
  bavailable = false;		// declare thread as not available
  bfed       = true;		// data has been fed at least once
  mutex_in.unlock();		// unlock data
  return true;		// confirm that we copied data.
}
コード例 #13
0
ファイル: tracking_thread.hpp プロジェクト: athuls/gsra
  void tracking_thread<Tnet>::execute() { 
    try {
      // configuration
      string    cam_type   = conf.get_string("camera");
      int       height     = conf.get_int("input_height");
      int       width      = conf.get_int("input_width");
      bool      save_video = conf.exists_bool("save_video");
      bool      display    = conf.exists_bool("tracking_display");
      // initialize camera (opencv, directory, shmem or video)
      camera<ubyte> *cam = NULL;
      if (!strcmp(cam_type.c_str(), "directory")) {
	if (arg2) cam = new camera_directory<ubyte>(arg2, height,width);
	else eblerror("expected 2nd argument");
      } 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);
#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 (arg2)
	  cam = new camera_video<ubyte>
	    (arg2, height, width, conf.get_uint("input_video_sstep"),
	     conf.get_uint("input_video_max_duration"));
	else eblerror("expected 2nd argument");
      } else eblerror("unknown camera type");
      if (save_video)
	cam->start_recording();
      // other variables
      bool updated = false;
      bbox *b = new bbox;
      vector<bbox*> bb;
#ifdef __OPENCV__
      IplImage *iplframe = NULL;
      IplImage *ipltpl = NULL;
#endif
      // main loop
      while(!cam->empty()) {
	try {
	  frame = cam->grab();
	  // send new frame to vision_thread and check if new data was output
	  dt.set_data(frame);
	  updated = dt.get_data(bb, detframe);
	  // update target position if vision thread ready
	  if (updated) {
	    // find bbox with max confidence
	    if (bb.size() > 0) {
	      double maxconf = -5.0;
	      uint maxi = 0;
	      for (uint i = 0; i < bb.size(); ++i)
		if (bb[i]->confidence > maxconf) {
		  maxconf = bb[i]->confidence;
		  maxi = i;
		}
	      //	      cout << "found bbox" << endl;
	      b = bb[maxi];
	      if (b) {
		// update template
		idx<ubyte> tmptpl = detframe.narrow(0, b->height, b->h0);
		tmptpl = tmptpl.narrow(1, b->width, b->w0);
		tpl = idx<ubyte>(tmptpl.get_idxdim());
		idx_copy(tmptpl, tpl);
	      }
	    }
	  } else { // tracking (only when we didnt just receive an update)
#ifdef __OPENCV__
	    iplframe = idx_to_iplptr(frame);
	    ipltpl = idx_to_iplptr(tpl);
	    CvPoint minloc, maxloc;
	    double minval, maxval;
	    // vector<CvPoint> found;
	    // vector<double> confidences;
	    // FastMatchTemplate(*iplframe, *ipltpl, &found, &confidences, 1, false,
	    // 			5, 1, 15);
	    //      CvRect searchRoi;
	    //      cvSetImageROI( searchImage, searchRoi );
	    // vector<CvPoint>::iterator p = found.begin();
	    // vector<double>::iterator c = confidences.begin();
	    // for ( ; p != found.end() && c != confidences.end(); ++p, ++c) {
	    // 	gui << at(p->x, p->y) << *c;
	    // }
	    IplImage *tm = cvCreateImage(cvSize(frame.dim(1)  - tpl.dim(1)  + 1,
						frame.dim(0) - tpl.dim(0) + 1 ),
					 IPL_DEPTH_32F, 1 );
	    cvMatchTemplate(iplframe, ipltpl, tm, CV_TM_SQDIFF_NORMED);
	    cvMinMaxLoc(tm, &minval, &maxval, &minloc, &maxloc, 0);
	    //	    gui << at(minloc.y, minloc.x) << "M";
	    b->class_id = -42; // tell that this bbox is result of tracking
	    b->h0 = minloc.y;
	    b->w0 = minloc.x;
	    //	    cout << "maxloc h: " << maxloc.y << " w: " << maxloc.x << " minloc h:" << minloc.y << " w: " << minloc.x << endl;
#endif
	  }
	  // make a copy of found bounding boxes
	  copy_bboxes(bb);
	  // switch 'updated' flag on to warn we just added new data
	  set_out_updated();
	  // display
	  if (display)
	    draw(b);
	} catch (string &err) {
	  cerr << err << endl;
	}
      }
      if (save_video)
	cam->stop_recording(conf.exists_bool("use_original_fps") ?
			    cam->fps() : conf.get_uint("save_video_fps"));
      if (cam) delete cam;
    } catch(string &err) { eblerror(err.c_str()); }
  }
コード例 #14
0
ファイル: detection_thread.hpp プロジェクト: 2php/eblearn
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();
}
コード例 #15
0
ファイル: detection_thread.hpp プロジェクト: 2php/eblearn
bool detection_thread<T>::get_data(bboxes &bboxes2, idx<ubyte> &frame2,
                                   uint &total_saved_, std::string &frame_name_,
                                   uint *id, svector<midx<T> > *samples,
                                   bboxes *bbsamples, bool *skipped) {
  // lock data
  mutex_out.lock();
  // only read data if it has been updated
  if (!out_updated) {
    // unlock data
    mutex_out.unlock();
    return false;
  }
  // data is updated, but just to tell we skipped the frame
  if (frame_skipped) {
    if (skipped) *skipped = true;
    frame_skipped = false;
    // reset updated flag
    out_updated = false;
    // declare thread as available
    bavailable = true;
    // unlock data
    mutex_out.unlock();
    return false;
  }
  if (skipped) *skipped = false;
  // clear bboxes
  bboxes2.clear();
  bboxes2.push_back_new(bbs);
  bbs.clear(); // no use for local bounding boxes anymore, clear them
  // check frame is correctly allocated, if not, allocate.
  if (frame2.order() != uframe.order())
    frame2 = idx<ubyte>(uframe.get_idxdim());
  else if (frame2.get_idxdim() != uframe.get_idxdim())
    frame2.resize(uframe.get_idxdim());
  // copy frame
  idx_copy(uframe, frame2);
  // set total of boxes saved
  total_saved_ = total_saved;
  // set frame name
  frame_name_ = frame_name;
  // set frame id
  if (id) *id = frame_id;
  // overwrite samples
  if (samples) {
    samples->clear();
    samples->push_back_new(returned_samples);
    returned_samples.clear();
  }
  if (bbsamples) {
    bbsamples->clear();
    bbsamples->push_back_new(returned_samples_bboxes);
    returned_samples_bboxes.clear();
  }
  // reset updated flag
  out_updated = false;
  // declare thread as available
  bavailable = true;
  // unlock data
  mutex_out.unlock();
  // confirm that we copied data.
  return true;
}
コード例 #16
0
ファイル: idxIO.hpp プロジェクト: athuls/gsra
 void read_cast_matrix(FILE *fp, idx<T2> &out) {
   idx<T> m(out.get_idxdim());
   read_matrix_body(fp, m);
   idx_copy(m, out);
 }