Word Verification Reader, Update #2

I spent most of today consuming far more calories than I ought to have, and only a little bit of time improving the rectangle-ish-area-detection algorithm. What I've got now is the ability to find horizontal lines which start anywhere directly under the base line (where the first base line would be the top-most line on the 'f'). I've also finished adding the ability to find "branches" - places where there are multiple lines which start under a single base line (like where the 'v' touches the right side of the horizontal line on the 'f'. I'll need to improve my explore() function a bit to be able to support recursion, and then add an additional outer-loop to repeat the process until all pixels of the bitmap are accounted for.

This image depicts the end points of the lines to which the 'f' can be reduced. The image, which is ascii art, can not depict sub-pixel resolution, so things appear a little jagged. That won't be the case, ultimately. Once all of the bitmap is processed into lines, those lines will be smoothed to better represent the original curves of the letters, and then the comparison between those final lines and the pre-defined descriptions of the letters of the alphabet (which I have yet to create) can begin.


Although the libjpeg documentation was some of the best I have ever seen, it lacked example code demonstrating how to decompress a jpeg image into a two-dimensional array ... although it had a few examples that were fairly close. Here is what I came up with, which is acceptable for my needs, but certainly not every need.

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <jpeglib.h>
#include <jerror.h>

int
main (int argc, const char * argv[])
{
  FILE * file;
  int rows, cols, line_size;
  struct jpeg_decompress_struct cinfo;
  struct jpeg_error_mgr jerr;
  unsigned char *pixel_buf, *pixel_ptr;

  file = fopen("/path/to/image.jpg", "rb");
  cinfo.err = jpeg_std_error(&jerr);
  jpeg_create_decompress(&cinfo);
  jpeg_stdio_src(&cinfo, file);

  (void) jpeg_read_header(&cinfo, TRUE);
  (void) jpeg_start_decompress(&cinfo);

  rows = cinfo.output_height;
  cols = cinfo.output_width;

  line_size = cinfo.output_width * cinfo.output_components;
  pixel_buf = pixel_ptr = (unsigned char *)malloc(line_size * rows);

  bzero(pixel_buf, rows * line_size);

  while (cinfo.output_scanline < rows) {
    (void) jpeg_read_scanlines(&cinfo, (JSAMPARRAY)&pixel_ptr, 1);
    pixel_ptr += line_size;
  }
 
  jpeg_finish_decompress(&cinfo);
  jpeg_destroy_decompress(&cinfo);

  fclose(file);
  free(pixel_buf);
  
  return 0;
}

And on an unrelated note: I have not yet formed a theory regarding an observation that I make every year, around this time. That observation is this: the drivers suck to an unusual extent. Every day that I've driven this past week, I've encountered an unusual number of idiots trying to kill me - and not just during the crazy, day-time shopping hours leading up to Christmas ... but at night as well. Maybe it is a combination of crazy shoppers and drunk party-goers. But that's hardly a sufficient theory.

On the drive to lunch this morning, as I was exiting the highway (285 E at Ashford Dunwoody; a two-lane exit) the guy in the right of the two lanes (driving an ugly, red pickup, *you know who you are*) started drifting into the left lane (where I was). Then he honked at me ... and not a polite honk or anything that I might be able to construe as friendly ... it was a good two or three second honk. And after making the turn onto Ashford Dunwoody, he followed it up with a glare. I know, because I glared back, and then he turned away and didn't glare any longer.

Subscribe to A garage sale for your mind

Don’t miss out on the latest posts. Sign up now to get access to the library of members-only posts.
[email protected]
Subscribe