Example #1
0
void HessianDetector::detectOctaveKeypoints(const cv::Mat &firstLevel, float pixelDistance, cv::Mat &nextOctaveFirstLevel)
{
   octaveMap = cv::Mat::zeros(firstLevel.rows, firstLevel.cols, CV_8UC1);
   float sigmaStep = pow(2.0f, 1.0f / (float) par.numberOfScales);
   float curSigma = par.initialSigma;
   blur = firstLevel;   
   cur = hessianResponse(blur, curSigma*curSigma);
   int numLevels = 1;
   
   for (int i = 1; i < par.numberOfScales+2; i++)
   {
      // compute the increase necessary for the next level and compute the next level
      float sigma = curSigma * sqrt(sigmaStep * sigmaStep - 1.0f);
      // do the blurring
      cv::Mat nextBlur = gaussianBlur(blur, sigma);
      // the next level sigma
      sigma = curSigma*sigmaStep;
      // compute response for current level
      high = hessianResponse(nextBlur, sigma*sigma);
      numLevels ++;
      // if we have three consecutive responses
      if (numLevels == 3)
      {
         // find keypoints in this part of octave for curLevel
         findLevelKeypoints(curSigma, pixelDistance);
         numLevels--;
      }      
      if (i == par.numberOfScales)
         // downsample the right level for the next octave
         nextOctaveFirstLevel = halfImage(nextBlur);
      prevBlur = blur; blur = nextBlur;
      // shift to the next response 
      low = cur; cur = high;
      curSigma *= sigmaStep;
   }
}
Example #2
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;
}