Example #1
0
void PedestalFitter::fit_pedestals(Shared::Image::Raw& image, std::vector<Blob>& blobs)
{
    Tools::Timer timer;
    timer.start();
    for (unsigned int i=0; i<blobs.size(); i++) {
        //fit_pedestal(image, blobs[i]);
    }
    //cout << "fitting " << blobs.size() << " pedestals took " << timer.time() << endl;
}
Example #2
0
  g++ mainTimer.cpp ../Tools/Timer.cpp -I ../Tools -o timer_test
#endif

#include <iostream>
#include <ctime>
#include "Timer.hpp"

int main()
{
  Tools::Timer t;
  t.reset();
  for (int i = 0; i < 100000; i++)
    for (jnt j = 0; j < 100000; j++)
    {}
  std::cout << t.getElapsedTime() << std::endl;
  return 0;
}
Example #3
0
void create_map( const std::string& realm, unsigned short width, unsigned short height )
{
  auto mapwriter = new MapWriter();
  INFO_PRINT << "Creating map base and solids files.\n"
             << "  Realm: " << realm << "\n"
             << "  Map ID: " << uo_mapid << "\n"
             << "  Use Dif files: " << ( uo_usedif ? "Yes" : "No" ) << "\n"
             << "  Size: " << uo_map_width << "x" << uo_map_height << "\n"
             << "Initializing files: ";
  mapwriter->CreateNewFiles( realm, width, height );
  INFO_PRINT << "Done.\n";
  Tools::Timer<> timer;
  rawmapfullread();
  rawstaticfullread();
  INFO_PRINT << "  Reading mapfiles time: " << timer.ellapsed() << " ms.\n";
  for ( unsigned short y_base = 0; y_base < height; y_base += SOLIDX_Y_SIZE )
  {
    for ( unsigned short x_base = 0; x_base < width; x_base += SOLIDX_X_SIZE )
    {
      ProcessSolidBlock( x_base, y_base, *mapwriter );
    }
    INFO_PRINT << "\rConverting: " << y_base * 100 / height << "%";
  }
  timer.stop();

  mapwriter->WriteConfigFile();
  delete mapwriter;

  INFO_PRINT << "\rConversion complete.              \n"
             << "Conversion details:\n"
             << "  Total blocks: " << empty + nonempty << "\n"
             << "  Blocks with solids: " << nonempty << " ("
             << ( nonempty * 100 / ( empty + nonempty ) ) << "%)"
             << "\n"
             << "  Blocks without solids: " << empty << " ("
             << ( empty * 100 / ( empty + nonempty ) ) << "%)"
             << "\n"
             << "  Locations with solids: " << with_more_solids << "\n"
             << "  Total number of solids: " << total_statics << "\n"
             << "  Elapsed time: " << timer.ellapsed() << " ms.\n";
}
Example #4
0
void Solver::solve()
{
    using namespace Shared::Image;
    Tools::Timer timer;
    logger.log(format("starting to solve image %s") % working_image->filename);

    timer.start();
    // setting up
    {
        shared_solution_summary.blob_names.clear();
        Shared::Image::solution_summary_for_main.share();
        shared_stats.clear(working_image->counter_stars);
        Shared::Image::stats_solver_for_main.share();
        Shared::Image::blobs_solver_for_main.share();
        update_shared();
    }

    // stats
    {
        statistician.make_display_data(*working_image);
        statistician.get_stats(*working_image);
        statistician.print_stats();
        update_shared();
    }
    autofocus_helper.extract_sobel_datapoint(*working_image);

    // blob finding
    if (!done()) {
        shared_status.stage = Status::blob_finding;
        status_solver_for_main.share();
        update_shared();

        double noise = 1.0;
        if (shared_stats.noise_known) {
            noise = shared_stats.noise;
        }
        shared_blobs.blobs.clear();
        shared_blobs.blobs = blob_finder.find_blobs(*working_image, noise);
        shared_blobs.counter_stars =  working_image->counter_stars;
        Shared::Image::blobs_solver_for_main.share();
        update_shared();
    }

    autofocus_helper.extract_brightest_blob_datapoint(*working_image, shared_blobs.blobs);

    bool solution_found = false;
    Solution solution;

    // pattern matching
    if (!done() && shared_settings.pattern_matcher_enabled) {
        shared_status.stage = Status::pattern_matching;
        status_solver_for_main.share();

        solution_found = pattern_matcher.match(shared_blobs.blobs, *working_image, solution);
        update_shared();
    }

    // refitting
    if (!done() && solution_found) {
        shared_status.stage = Status::refitting;
        status_solver_for_main.share();

        refitter.fit(solution, *working_image);

        shared_solution_summary = solution;
        shared_solution_summary.counter_stars = shared_status.counter_stars;
        shared_solution_summary.solving_time = shared_status.age.time();
        Shared::Image::solution_summary_for_main.share();

        pattern_matcher.inform_blobs_of_matches(solution);
        Shared::Image::blobs_solver_for_main.share();
    }

    // getting blob names
    if (!done() && solution_found && shared_settings.display_names) {
        shared_status.stage = Status::getting_names;
        status_solver_for_main.share();

        pattern_matcher.get_blob_names(solution);
        Shared::Image::solution_summary_for_main.share();
    }

    if (solution_found) {
        shared_status.reason_for_being_done = Status::solved;
        solution.print(logger, true);
        autofocus_helper.extract_star_datapoints(*working_image, solution);
    }
    shared_status.stage = Status::done;
    status_solver_for_main.share();
    autofocus_helper.set_fully_solved(working_image->counter_stars);

    update_shared();

    logger.log(format("total time spent solving %.3f s") % timer.time());
    logger.log(format("finished solving image %s") % working_image->filename);
    logger.flush();
}
Example #5
0
void convertImageFromGray(unsigned char* gray,
                          int width,
                          int height,
                          int dim,
                          float time,
                          FILE* fp_out,
                          bool output_image,
                          bool output_pts,
                          int searchRange)
{
    char bmpFname[100];
    Image outputImage(width, height);
    Tools::Timer timer;
    double dctTime = 0.0;
    double matchTime = 0.0;
    double convTime = 0.0;
    
    int matching;
    unsigned char glyphIndex;
    fprintf(stderr, "converting rgb frame at time %f\n", time);
    sprintf(bmpFname, "image_%0.4f.ppm", time);
    
    if (output_pts)
    {
        // write pts to output stream
        fwrite(&time, sizeof(time), 1, fp_out);
        fprintf(stderr, "output pts!\n");
    }

    for (int y = 0; y < height; y += dim)
    {
        for (int x = 0; x < width; x += dim)
        {
            // copy values into input buffer
            for (int yy = 0; yy < dim; yy ++)
            {
                for (int xx = 0; xx < dim; xx++)
                {
                    dctInput[xx][yy] = gray[(y+yy)*width + (x+xx)];
                }
            }
            
            timer.start();
#ifdef USE_1D_DCT
            dct1WithInput(dctInput, dctOutput, cos1DLookup, dim);
#else
            dctWithInput(dctInput, dctOutput, cosLookup, dim);
#endif
            dctTime += timer.getTime();
            
            timer.start();
            matching = getMatchingGlyph(dctOutput, searchRange);
            matchTime += timer.getTime();
            
            glyphIndex = (unsigned char)matching;
            
            fwrite(&glyphIndex, 1, 1, fp_out);
            
            if (output_image)
            {
                // write to png
                unsigned char *glyphString;
                int glyphPix = dim*dim;
                
                
                if (matching < 128)
                {
                    glyphString = &glyphs[matching * glyphPix];
                }
                else
                {
                    glyphString = &glyphs[(matching - 128)*glyphPix];
                }
                
                int ind;
                ind = 0;
                for (int yy = 0; yy < dim; yy ++)
                {
                    for (int xx = 0; xx < dim; xx++)
                    {
                        Pixel* pixel = outputImage.pixelAt(x+xx, y+yy);
                        
                        if ((glyphString[ind] == '0' && matching < 128) ||
                            (glyphString[ind] == '1' && matching >= 128))
                        {
                            pixel->rgb[0] = 0;
                            pixel->rgb[1] = 0;
                            pixel->rgb[2] = 0;
                        }
                        else
                        {
                            pixel->rgb[0] = 1.0;
                            pixel->rgb[1] = 1.0;
                            pixel->rgb[2] = 1.0;
                        }
                        
                        ind++;
                    }
                }
            }
        }
    }
    if (output_image)
    {
        outputImage.writePPM(bmpFname);
    }
    
    fprintf(stderr, "dct time %lf match time %lf conversion time %lf\n", dctTime, matchTime, convTime);
}
Example #6
0
int main(int argc, char * const argv[]) {
    // initialize
    int c;
    int frame_size = C64_FRAME_SIZE;
    int output_port = 99999;
    FILE* fp = stdin;
    int ip[4] = {127, 0, 0, 1};
    
    while ((c = getopt(argc, argv, "t:p:i:a:")) != -1)
    {
        if (c == 't')
        {
            if (strcmp(optarg, "c64") == 0)
            {
                frame_size = C64_FRAME_SIZE;
            }
            else if (strcmp(optarg, "pet") == 0)
            {
                frame_size = PET_FRAME_SIZE;
            }
            else if (strcmp(optarg, "pet40") == 0)
            {
                frame_size = PET_40_FRAME_SIZE;
            }
        }
        else if (c == 'p')
        {
            output_port = atoi(optarg);
        }
        else if (c == 'i')
        {
            fp = fopen(optarg, "rb");
        }
        else if (c == 'a') // ip address
        {
            sscanf(optarg, "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3]);
        }
    }
    
    Frame frame(frame_size);
    Tools::Timer timer;
    NetPort port(ip[0],ip[1],ip[2],ip[3],5555,output_port);
    NetPort timeListenerPort(127,0,0,1,5556,output_port);
    
    unsigned char temp[2000];
    
    float start_pts = -1;
    double external_offset = 0.0;
    while (frame.read(fp))
    {
        fprintf(stderr, "pts: %f\n", frame.pts());
        if (start_pts < 0.0)
        {
            start_pts = frame.pts();
            timer.start();
        }
        
        float rel_pts = frame.pts() - start_pts;
        
        // get current time
        double currentTime = timer.getTime() + external_offset;
        fprintf(stderr, "current time: %lf timer %lf offset %lf\n", currentTime, timer.getTime(), external_offset);
        while (currentTime < rel_pts)
        {
            float sleepTimeUs = (rel_pts - currentTime) * 1000000.0;
            
            // check for timer update
            uint32_t nTimeUs = 0;
            int ret = timeListenerPort.recv((unsigned char*)&nTimeUs, sizeof(uint32_t));
            if (ret == sizeof(uint32_t))
            {
                uint32_t timeUs = ntohl(nTimeUs);
                printf("got time update: %d at time %lf\n", timeUs, timer.getTime());
                
                double ext_time = (double)timeUs / 1000000.0;
                external_offset = ext_time - timer.getTime();
            }
            
            if (sleepTimeUs > 1.0)
            {
                usleep(sleepTimeUs);
            }
            
            currentTime = timer.getTime() + external_offset;
        }
        
        fprintf(stderr, "sending frame at time %lf relpts %f error %f\n", currentTime, rel_pts, currentTime-rel_pts);
        
        // write data to output
        //fwrite(frame.data, 1, C64_FRAME_SIZE, fp_out);
        //memcpy(temp, frame.data(), frame.dataSize());
        int ret = port.send(frame.data(), frame.dataSize());
        //int ret = port.send(temp, 2000);
        //printf("send returned %d op %d %d %d %d %d\n", ret, ip[0], ip[1], ip[2], ip[3], output_port);
    }
    
    if (fp != stdin)
    {
        fclose(fp);
    }
    
    return 0;
}
Example #7
0
int main(int argc, const char * argv[]) {
    // insert code here...
    //std::cout << "Hello, World!\n";
    
    Palette c64palette(c64_colors, num_64_colors);
    Ditherer* ditherer = Ditherer::createC64Ditherer();
    
    const char* dirname = argv[1];
    const char* outdirname = argv[2];
    const char* out64fname = argv[3];
    
    int index = 0;
    char thisfname[256];
    char nextfname[256];
    char outfname[256];
    unsigned char* c64frame = NULL;
    
    FILE* fp = fopen(out64fname, "wb");
    NetPort port(192,168,1,25,99998,99999);
    Tools::Timer frameTimer;
    
    frameTimer.start();
    for (index = 1; index < 9999; index++)
    {
        // check if file can be opened
        sprintf(thisfname, "%s/%04d.ppm", dirname, index);
        sprintf(nextfname, "%s/%04d.ppm", dirname, index+1);
        
        wait_for_file(nextfname);
        printf("%s\n", thisfname);
        
        // open image
        Image inputImage(thisfname);
        int imWidth = inputImage.getWidth();
        int imHeight = inputImage.getHeight();
        Image halfImage(inputImage, imWidth/2, imHeight);
        
        Image* dithered = ditherer->createDitheredImageFromImageWithPalette(halfImage, c64palette);
        C64Image* c64im = (C64Image*)dithered;
        
        /*
        // test - output to new ppm
        sprintf(outfname, "%s/%04d.ppm", outdirname, index);
        Image fullImage(*dithered, imWidth, imHeight);
        fullImage.writePPM(outfname);
        */
        
        int c64FrameSize = c64im->getC64FrameSize();
        if (!c64frame)
        {
            c64frame = (unsigned char*)malloc(sizeof(unsigned char) * c64FrameSize);
        }
        float time = (float)index / 8.0;
        c64im->getC64Frame(c64frame, time);
        fwrite(c64frame, 1, c64FrameSize, fp);
        
        float thisTime = frameTimer.getTime();
        printf("pts %f, time %f\n", time, thisTime);
        while (thisTime < time)
        {
            float diff = time - thisTime;
            float usec = diff * 1000000.0;
            usleep(usec);
            thisTime = frameTimer.getTime();
        }
        // send bytes to port
        port.send(&c64frame[4], 9216);
        
        delete dithered;
    }
    fclose(fp);
    
    return 0;
}