OCR算法(GOCR)到32F429IDISCOVERY板

时间:2015-03-12 13:11:40

标签: algorithm ocr stm32 stm32f4discovery

我试图在32F429IDISCOVERY板上实施OCR算法(特别是GOCR算法),我仍然没有得到任何回报...... 我将RGB565格式的OV7670相机的图像记录到电路板的SDRAM中,然后转换为灰度并传递给算法本身。 从这个和其他论坛我得到的印象是GOCR是非常好的算法,它似乎在PC上工作得很好,但我不能让它在板上工作。 有没有人有实施OCR或GOCR的经验?我不确定问题出在哪里,因为它以非常奇怪的方式发生。代码几乎每次都停在算法的不同部分......

调用OCR算法:

void ocr_algorithm(char *output_str) {
  job_t job1, *job; /* fixme, dont want global variables for lib */
  job=OCR_JOB=&job1;

  int linecounter;
  const char *line;

  uint8_t r,g,b;
  uint32_t n,i,buffer;
  char *p_pic;

  uint32_t *image = (uint32_t*) SDRAM_START_ADR;

  setvbuf(stdout, (char *) NULL, _IONBF, 0);    /* not buffered */

  job_init(job); /* init cfg and db */

  job_init_image(job); /* single image */

  p_pic = malloc(IMG_ROWS*IMG_COLUMNS);

  // Converting RGB565 to grayscale
  i=0;
  for (n = 0; n < IMG_ROWS*IMG_COLUMNS; n++) {
    if (n % 2 == 0){
        buffer = image[i] & 0xFFFF;
    }
    else{
        buffer = (image[i] >> 16) & 0xFFFF;
        i++;
    }

    r = (uint8_t) ((buffer >> 11) & 0x1F);
    g = (uint8_t) ((buffer >> 5) & 0x3F);
    b = (uint8_t) (buffer & 0x1F);

    // RGB888
    r = ((r * 527) + 23) >> 6;
    g = ((g * 259) + 33) >> 6;
    b = ((b * 527) + 23) >> 6;

    // Greyscale
    p_pic[n] = 0.299*r + 0.587*g + 0.114*b;
  }

  //read_picture;
  job->src.p.p = p_pic;
  job->src.p.x = IMG_ROWS;
  job->src.p.y = IMG_COLUMNS;
  job->src.p.bpp = 1;

  /* call main loop */
  pgm2asc(job);

  //print output
  strcpy(output_str, "");
  linecounter = 0;
  line = getTextLine(&(job->res.linelist), linecounter++);

  while (line) {
    strcat(output_str, line);
    strcat(output_str, "\n");

    line = getTextLine(&(job->res.linelist), linecounter++);
  }

  free_textlines(&(job->res.linelist));

  job_free_image(job);

  free(p_pic);
}

0 个答案:

没有答案