示例#1
0
文件: main.cpp 项目: thacdtd/PGLCM
int main(int argc, char** argv){

std::ofstream outputFile; 

  /* Deals with optional argument (ie. output file) */ 
  switch (argc){
  case (4):
    output = &std::cout; 
    cerr<<"No output file, using standard output."<<endl; 
    break;       
  case (5): 
    outputFile.open(argv[4]); 
    if(outputFile.fail()){
      std::cerr<<"Error opening file : "<<argv[4]<<"."<<std::endl;
      exit(EXIT_FAILURE); 
    }
    output = &outputFile; 
    break; 
  default :
    cout << "Usage = " << argv[0] << "<nor/gra/norwTSs> <input file name> <absolute support threshold> <output file>" << endl ;
		cout << "nor : Normal frequent definition" << endl;
		cout << "gra : GRAAK frequent definition" << endl;
		cout << "norwTSs : Normal frequent definition with computing transaction sequences" << endl;
    exit(EXIT_FAILURE);     
  }

		cout<<"\n     -----Debut du programm------       " << endl;

		// Recover arguments
		string freType = argv[1] ;
		char* inputFileName = argv[2] ;
		float threshold = atof(argv[3]) ;
		string so = "n";//argv[4] ;


		DBMain * dbmain = LoadBase(inputFileName);

        TimeTracker tt;
        tt.Start();
        
		GLCM glcm = GLCM();
		glcm.GLCMAlgo(dbmain,threshold,freType,so,*output);
        
        double ts = tt.Stop();
		cout<<"------------FIN----------"<<endl;
		glcm.PrintNoClosed();
        cout << "Total: " << setw(5) << ts << " sec" << endl;

        ostringstream ost;
        ost << getpid ();
        string cmd="ps -p "+ost.str ()+" -o rss";
        cout << "Total Memory usage : " << endl;
        //system(cmd.c_str());
        delete dbmain;

	return 0;
}
示例#2
0
    double run() {
      Setup(lattice).setup();
      Solver solver(lattice);

      TimeTracker tt;
      tt.start();
      solver.run();
      tt.stop();

      return tt.elapsedSeconds();

    }
示例#3
0
// Very simple
void greedy() {

  TimeTracker tt;

  tt.start();

  // Could be optimized a LOT
  bool changed;
  do{
    changed = false;
    for(node_ptr n = lattice.begin(); n != lattice.end(); ++n) {
      if(n->gain > 0) {
	flipNode<3>(n);
	changed = true;
      }
    }
  }while(changed);

  tt.stop();

  cout << "Greedy finished in " << tt.asString() << "." << endl;
}
示例#4
0
template <int nd, typename Kernel> void run_benchmark(char mode, size_t edge_size, size_t random_seed) {

  typedef typename Indexer<nd>::index_vect index_vect;
  
  vector<dtype> X;

  ImageOptions opt;

  construct_random_bitmap<nd>(X, edge_size, opt, 10000 + random_seed);

  index_vect dimensions(edge_size); 

  // Now run it...
  TimeTracker tt;

  tt.start();
  _LatticeEnergy<nd, Kernel, dtype> le_qbp(dimensions);
  GraphCutEnergyWrapper<nd> le_gc(dimensions);

  make<nd>(&le_qbp, &le_gc, mode, opt, X, edge_size);

  tt.stop();

  cout << "Time taken in setup = " << tt.asString() << "." << endl;


  cout << "Starting LatticeEnergy version." << endl;
  tt.reset();
  tt.start();
  le_qbp.run();
  tt.stop();
  cout << "Time taken in QBP optimization = " << tt.asString() << "." << endl;

  cout << "Starting GraphCuts version." << endl;
  tt.reset();
  tt.start();
  le_gc.run();
  tt.stop();
  cout << "Time taken in GC optimization = " << tt.asString() << "." << endl;

  size_t n_pos = 0;
  size_t n_neg = 0;
  size_t fpos_mismatch_count = 0;
  size_t fneg_mismatch_count = 0;
  
  for(IndexIterator<nd> idxit(dimensions); !idxit.done(); ++idxit) {
    bool q_on  = le_qbp.on(idxit.coords());
    bool gc_on = le_gc.on(idxit.coords());

    if(!q_on && gc_on)
      ++fneg_mismatch_count;

    if(q_on && !gc_on)
      ++fpos_mismatch_count;

    ++(q_on ? n_pos : n_neg);
  }
  
  if( (fneg_mismatch_count + fpos_mismatch_count) != 0) {
    cout << "WARNING: mismatch count between QBP and GC is " 
	 << (fneg_mismatch_count + fpos_mismatch_count) 
	 << " (false negatives = " << fneg_mismatch_count
	 << ", false positives = " << fpos_mismatch_count 
	 << ", total negatives = " << n_neg
	 << ", total positives = " << n_pos
	 << ")"
	 << "!" << endl;
  } else {
    cout << "Solutions exactly match." << endl;
  }
}
int
main(int argc, char **argv)
{
	ArgumentParser *argp = new ArgumentParser(argc, argv, "h:f:c:");

	if (argp->has_arg("h") && argp->has_arg("f"))
	// read image from file
	{
		const char *cascade_file = argp->arg("h");
		const char *image_file   = argp->arg("f");

		JpegReader *   reader = new JpegReader(image_file);
		unsigned char *buffer =
		  malloc_buffer(YUV422_PLANAR, reader->pixel_width(), reader->pixel_height());

		reader->set_buffer(buffer);
		reader->read();

		FacesClassifier *classifier =
		  new FacesClassifier(cascade_file, reader->pixel_width(), reader->pixel_height());

		classifier->set_src_buffer(buffer, reader->pixel_width(), reader->pixel_height());
		std::list<ROI> *rois = classifier->classify();

		FilterROIDraw *roi_draw = new FilterROIDraw();
		for (std::list<ROI>::iterator i = rois->begin(); i != rois->end(); ++i) {
			printf("ROI: start (%u, %u)  extent %u x %u\n",
			       (*i).start.x,
			       (*i).start.y,
			       (*i).width,
			       (*i).height);

			roi_draw->set_dst_buffer(buffer, &(*i));
			roi_draw->apply();
		}

		ImageDisplay *display = new ImageDisplay(reader->pixel_width(), reader->pixel_height());
		display->show(buffer);

		display->loop_until_quit();

		delete display;

		delete rois;
		free(buffer);
		delete reader;
		delete classifier;
	}

	else if (argp->has_arg("h") && argp->has_arg("c"))
	// get images from camera
	{
		const char *cascade_file = argp->arg("h");

		Camera *camera = NULL;
		try {
			camera = CameraFactory::instance(argp->arg("c"));
			camera->open();
			camera->start();
		} catch (Exception &e) {
			printf("Failed to open camera.\n");
			delete camera;
			return (-1);
		}

		printf("successfully opened camera: w=%d h=%d\n",
		       camera->pixel_width(),
		       camera->pixel_height());

		TimeTracker *tt              = new TimeTracker();
		unsigned int ttc_recognition = tt->add_class("Face recognition");
		unsigned int loop_count      = 0;

		IplImage *image =
		  cvCreateImage(cvSize(camera->pixel_width(), camera->pixel_height()), IPL_DEPTH_8U, 3);

		IplImage *scaled_image =
		  cvCreateImage(cvSize(camera->pixel_width() / 2, camera->pixel_height() / 2), IPL_DEPTH_8U, 3);

		FacesClassifier *classifier = new FacesClassifier(cascade_file,
		                                                  camera->pixel_width(),
		                                                  camera->pixel_height(),
		                                                  scaled_image,
		                                                  1.2 /* scale factor */,
		                                                  2 /* min neighbours */,
		                                                  CV_HAAR_DO_CANNY_PRUNING);

		unsigned char *display_buffer = (unsigned char *)malloc(camera->buffer_size());

		ImageDisplay *display =
		  new ImageDisplay(camera->pixel_width(), camera->pixel_height(), "QA Faces Classifier");

		Drawer *drawer = new Drawer();
		drawer->set_buffer(display_buffer, camera->pixel_width(), camera->pixel_height());

		SDL_Event redraw_event;
		redraw_event.type           = SDL_KEYUP;
		redraw_event.key.keysym.sym = SDLK_SPACE;

		SDL_PushEvent(&redraw_event);

		bool quit = false;
		while (!quit) {
			SDL_Event event;
			if (SDL_WaitEvent(&event)) {
				switch (event.type) {
				case SDL_QUIT: quit = true; break;

				case SDL_KEYUP:
					if (event.key.keysym.sym == SDLK_SPACE) {
						camera->capture();

						if (camera->buffer() != NULL) {
							IplImageAdapter::convert_image_bgr(camera->buffer(), image);
							cvResize(image, scaled_image, CV_INTER_LINEAR);
							memcpy(display_buffer, camera->buffer(), camera->buffer_size());

							tt->ping_start(ttc_recognition);
							std::list<ROI> *rois = classifier->classify();
							tt->ping_end(ttc_recognition);

							camera->dispose_buffer();

							bool first = true;
							for (std::list<ROI>::reverse_iterator i = rois->rbegin(); i != rois->rend(); ++i) {
								if (first) {
									drawer->set_color(127, 70, 200);
								}
								drawer->draw_rectangle(2 * i->start.x, 2 * i->start.y, 2 * i->width, 2 * i->height);
								if (first) {
									drawer->set_color(30, 30, 30);
									first = false;
								}
							}

							if (++loop_count % 15 == 0) {
								tt->print_to_stdout();
							}

							display->show(display_buffer);
						}

						SDL_PushEvent(&redraw_event);
					}

					else if (event.key.keysym.sym == SDLK_ESCAPE) {
						quit = true;
					}

					break;

				default: break;
				}
			}
		}

		camera->stop();
		camera->close();
		delete camera;
		delete display;
		delete drawer;
		free(display_buffer);
		cvReleaseImage(&image);
		cvReleaseImage(&scaled_image);
		delete tt;
	}

	else {
		printf("Usage: %s -h <Haar cascade file> -f <Image file as JPEG>\n", argv[0]);
		printf("    or %s -h <Haar cascade file> -c <Camera argument string>\n", argv[0]);
		exit(-1);
	}

	delete argp;
}
示例#6
0
int
main(int argc, char **argv)
{
  TimeTracker *tt = new TimeTracker();
  unsigned int loop_count = 0;
  unsigned int ttc_trans = tt->add_class("Tra");
  unsigned int ttc_rot = tt->add_class("Rot");
  unsigned int ttc_inv = tt->add_class("Inv");

  HomTransform ht;
  for (loop_count = 0; loop_count < 10; ++loop_count) {
    tt->ping_start(ttc_trans);
    ht.trans(1, 2, 3);
    tt->ping_end(ttc_trans);

    tt->ping_start(ttc_rot);
    ht.rotate_x(M_PI_2);
    tt->ping_end(ttc_rot);

    tt->ping_start(ttc_trans);
    ht.trans(1, 2, 3);
    tt->ping_end(ttc_trans);

    tt->ping_start(ttc_rot);
    ht.rotate_y(23);
    tt->ping_end(ttc_rot);

    tt->ping_start(ttc_trans);
    ht.trans(1, 2, 3);
    tt->ping_end(ttc_trans);

    tt->ping_start(ttc_rot);
    ht.rotate_z(M_PI_2);
    tt->ping_end(ttc_rot);

    tt->ping_start(ttc_inv);
    ht.invert();
    tt->ping_end(ttc_inv);

    tt->ping_start(ttc_inv);
    ht.invert();
    tt->ping_end(ttc_inv);
  }

  ht.print_info("HomTransform");
  HomPoint p0 = HomPoint(0.1f, 0.2f, 0.3f);
  cout << "0:  " << p0 << endl << endl << endl;

  HomPoint p = ht * p0;
  cout << "p:  " << p << endl << endl << endl;

  ht.invert().print_info("HomTransform inverted");
  p0 = ht * p;
  cout << "0': " << p0 << endl << endl << endl;

  ht.invert().print_info("HomTransform");
  tt->print_to_stdout();

  ht *= ht;

  delete tt;
}
示例#7
0
static
void
runESL(const ESLOptions& opt)
{
    TimeTracker timer;
    timer.resume();
    {
        // early test that we have permission to write to output file
        OutStream outs(opt.outputFilename);
    }

    typedef std::shared_ptr<bam_streamer> stream_ptr;
    std::vector<stream_ptr> bamStreams;

    // setup all data for main alignment loop:
    for (const std::string& afile : opt.alignFileOpt.alignmentFilename)
    {
        stream_ptr tmp(new bam_streamer(afile.c_str(),
                                        (opt.region.empty()
                                         ? NULL
                                         : opt.region.c_str())));
        bamStreams.push_back(tmp);
    }

    const unsigned bamCount(bamStreams.size());

    assert(0 != bamCount);

    // check bam header compatibility:
    if (bamCount > 1)
    {
        /// TODO: provide a better error exception for failed bam header check:
        const bam_header_t* compareHeader(bamStreams[0]->get_header());
        for (unsigned bamIndex(1); bamIndex<bamCount; ++bamIndex)
        {
            const bam_header_t* indexHeader(bamStreams[bamIndex]->get_header());
            if (! check_header_compatibility(compareHeader,indexHeader))
            {
                log_os << "ERROR: incompatible bam headers between files:\n"
                       << "\t" << opt.alignFileOpt.alignmentFilename[0] << "\n"
                       << "\t" << opt.alignFileOpt.alignmentFilename[bamIndex] << "\n";
                exit(EXIT_FAILURE);
            }
        }
    }

    // assume headers compatible after this point....

    const bam_header_t& header(*(bamStreams[0]->get_header()));
    const bam_header_info bamHeader(header);

    int32_t tid(0), beginPos(0), endPos(0);
    parse_bam_region(bamHeader,opt.region,tid,beginPos,endPos);

    const GenomeInterval scanRegion(tid,beginPos,endPos);
#ifdef DEBUG_ESL
    static const std::string log_tag("EstimateSVLoci");
    log_os << log_tag << " scanRegion= " << scanRegion << "\n";
#endif

    // grab the reference for segment we're estimating plus a buffer around the segment edges:
    static const unsigned refEdgeBufferSize(500);

    reference_contig_segment refSegment;
    getIntervalReferenceSegment(opt.referenceFilename, bamHeader, refEdgeBufferSize, scanRegion, refSegment);

    SVLocusSetFinder locusFinder(opt, scanRegion, bamHeader, refSegment);

    input_stream_data sdata;
    for (unsigned bamIndex(0); bamIndex<bamCount; ++bamIndex)
    {
        sdata.register_reads(*bamStreams[bamIndex],bamIndex);
    }

    // loop through alignments:
    input_stream_handler sinput(sdata);
    while (sinput.next())
    {
        const input_record_info current(sinput.get_current());

        if (current.itype != INPUT_TYPE::READ)
        {
            log_os << "ERROR: invalid input condition.\n";
            exit(EXIT_FAILURE);
        }

        const bam_streamer& readStream(*bamStreams[current.sample_no]);
        const bam_record& read(*(readStream.get_record_ptr()));

        locusFinder.update(read, current.sample_no);
    }

    // finished updating:
    locusFinder.flush();
    timer.stop();
    const CpuTimes totalTimes(timer.getTimes());
#ifdef DEBUG_ESL
    log_os << log_tag << " found " << locusFinder.getLocusSet().size() << " loci. \n";
    log_os << log_tag << " totalTime: ";
    totalTimes.reportHr(log_os);
    log_os << "\n";
#endif
    locusFinder.setBuildTime(totalTimes);
    locusFinder.getLocusSet().save(opt.outputFilename.c_str());
}