示例#1
0
//-----------------------------------------------------------------------------
// Function: lookForwardMatch()
//-----------------------------------------------------------------------------
bool CSourceContentMatcher::lookForwardMatch(QString const& text)
{
    int index = 0;
    int toolTipIndex = 0;
    return (lastMatchType_ != MATCH_NONE &&
            enumerateMatches(text, 0, index, 0, toolTipIndex) == lastMatchType_);
}
示例#2
0
//-----------------------------------------------------------------------------
// Function: fillWithContent()
//-----------------------------------------------------------------------------
bool CSourceContentMatcher::fillWithContent(QString const& text, TextContentAssistWidget& assist,
                                          int& startIndex, QString& toolTipText, int& toolTipIndex)
{
    curAssist_ = &assist;

    toolTipText.clear();    
    lastMatchType_ = enumerateMatches(text, &CSourceContentMatcher::addMatchToAssist,
                                       startIndex, &toolTipText, toolTipIndex);

    curAssist_->sortItems();

    return (lastMatchType_ != MATCH_NONE);
}
示例#3
0
// my main function
int main(int argc, char** argv)
{
  // Main Variables
  int i, j;
  time_t t1, t2, t3, t4, t5, t6, t7, renderTime, deallocateTime;

  if (argc != 2) {
    fatal_error("usage: %s <PATH_FOR_IMAGES>", argv[0]);
  }

  // ************************TIME CHECKPOINT 1: Initialization****************************
  (void) time(&t1);
  printf("Starting Checkpoint 1 - initialization...\n");

  // Variables
  int file_count = 0;
  char** filenames = NULL;
  struct pData* poses = NULL;

  FILE *poseFile;
  char poseFilename[strlen(argv[1]) + strlen("poses.txt")];
  sprintf(poseFilename, "%sposes.txt", argv[1]);
    
  poseFile = fopen(poseFilename, "r");

  if (poseFile != NULL) {
    int c, step = 0;    
    while (file_count < NUM_IMAGES) {
      filenames = (char **) realloc(filenames, (file_count+1) * sizeof(char *));
      poses = (struct pData*) realloc(poses, (file_count+1) * sizeof(struct pData));

      if ((step % STEP) == 0) {
	initialize(poseFile, poses, filenames, file_count);
	file_count++;
	step++;
      } else {
	while((c = fgetc(poseFile)) != '\n');
	step++;
      }
    }      
  }

  // ************************TIME CHECKPOINT 2: Loading Image Data***************************
  (void) time(&t2);
  printf("Starting Checkpoint 2 - loading images from directory...\n");

  // Variables
  int image_count = 0;
  IplImage** images = NULL;

  images = (IplImage**) malloc(file_count * sizeof(IplImage*));
  // ERROR check allocation
  if (images == NULL) {
    fatal_error("allocating memory for images");
  }

  // load images
  memset(images, 0, file_count*sizeof(IplImage*));  
  image_count = loadImages(argv[1], filenames, file_count, images);

  // Release the memory for filenames.  Not needed anymore.
  free(filenames);

  // ************************TIME CHECKPOINT 3: Finding Features*****************************
  (void) time(&t3);
  printf("Starting Checkpoint 3 - finding features in each image...\n");

  // Step 1: generate features form images
  generateFeatures(images, image_count);

  // ************************TIME CHECKPOINT 4: Calculating Homographies*********************
  (void) time(&t4);
  printf("Starting Checkpoint 4 - matching images...\n");

  // A match represents a homography between two images
  int match_count = 0;
  CvMat** matches = (CvMat **) malloc(image_count * image_count * sizeof(CvMat*));

  // ERROR check allocation
  if (matches == NULL) {
    fatal_error("allocating memory for matches");
  }

  // Calculate homographies
  memset(matches, 0, image_count*image_count*sizeof(CvMat*));  
  match_count = enumerateMatches(images, image_count, matches);

  // ************************TIME CHECKPOINT 5: Calculating Norms of Homographies************
  (void) time(&t5);
  printf("Starting Checkpoint 5 - calculating norms of homography...\n");

  // The confidence is a measurement of similarity between images (i.e. norm of homography)
  double* confidences = (double*) calloc(match_count, sizeof(double));

  // ERROR check allocation
  if (confidences == NULL) {
    fatal_error("allocating memory for confidences");
  }
  
  calculateNorms(confidences, matches, image_count, match_count);

  // ************************TIME CHECKPOINT 6: Generating Best Homographies************
  (void) time(&t6);
  printf("Starting Checkpoint 6 - Generating best homographies...\n");

  // Variables
  int* bestMatchedIndex = (int*) calloc(image_count, sizeof(int));
  generateBestHomographies(bestMatchedIndex, image_count, confidences);

  // ************************Render Checkpoint: Rendering Scene****************************
  (void) time(&renderTime);
  printf("Starting Render Checkpoint - Rendering...\n");

  // Variables
  IplImage* viewport;
  clock_t currtime;
  int key;
  
  myScene = (struct scene*) malloc(sizeof(struct scene));
  initScene(0, myScene, poses, image_count);

  cvNamedWindow("Scene", 1);
  cvMoveWindow("Scene", 560, 200);

  rightClicked = 0;
  leftClicked = 0;
  middleClicked = 0;
  mousePosX = 0;
  mousePosY = 0;
  cvSetMouseCallback("Scene", mouseHandler, 0);
  viewport = cvCreateImage(cvSize(WINDOW_WIDTH, WINDOW_HEIGHT), IPL_DEPTH_8U, 3);
  
  while(1) {
    currtime = clock();

    if (!OPTION) {
      cvSetZero(viewport);
      //cvReleaseImage(&viewport);
      //viewport = cvCreateImage(cvSize(WINDOW_WIDTH, WINDOW_HEIGHT), IPL_DEPTH_8U, 3);
    }

    renderScene(images, matches, bestMatchedIndex, viewport, poses);
    cvShowImage("Scene", viewport);

    key = cvWaitKey(10);
    if (key == 'e' || key == 'E' || key == 27) {
      printf("EXITING!!!\n");
      break;
    } else if (key == 'r' || key == 'R') {
      initScene(0, myScene, poses, image_count);
    }else if (OPTION) {
      updateSceneKey(key);
    } 

    //if (DEBUG) 
      printf("time for frame: %.2lf\n", (((double) 1.0*clock()) - currtime) / CLOCKS_PER_SEC);
  }
  cvReleaseImage(&viewport);
  
  // ************************DEALLOCATION CHECKPOINT: Deallocating Memory******************
  (void) time(&deallocateTime);
  printf("Starting Deallocation Checkpoint - Deallocating...\n");

  // free allocated data 
  // free CHECKPOINT 7
  free(myScene);

  // free CHECKPOINT 6
  free(bestMatchedIndex);

  // free CHECKPOINT 5
  free(confidences);

  // free CHECKPOINT 3 and 4
  for (i = 0; i < match_count; i++) {
    cvReleaseMat(&matches[i]);
  }
  free(matches);  
  
  // free CHECKPOINT 2
  for (i = 0; i < image_count; i++) {
    cvReleaseImage(&images[i]);
  }
  free(images);

  // free CHECKPOINT 1
  free(poses);
 
  // Print Statistics
  printf("\n");
  printf("Number of images: %d\n", image_count);
  printf("Time for initialization: %.2lf\n", difftime(t2,t1));
  printf("Time to load data: %.2lf\n", difftime(t3,t2));
  printf("Time to generate features: %.2lf\n", difftime(t4,t3));
  printf("Time to generate matches: %.2lf\n", difftime(t5,t4));
  printf("Time to generate confidence/norms: %.2lf\n", difftime(t6, t5));
  printf("Time to search for optimal homographies: %.2lf\n", difftime(renderTime, t6));
  printf("Time for rendering: %.2lf\n", difftime(deallocateTime,renderTime));
  printf("Total Time: %.2lf\n", difftime(deallocateTime, t1));
     
  return 0;

}