title: reading a UPC barcode from an image
body: <p>i need some guidance on how to get a 12 digit barcode from a bmp file, i'm completely clueless on how approach this.
  i started by reading the image into a bitmam, how can i continue?</p>
  
  <p>example: the barcode of the image below is 081034489030.
  how to i get these numbers?</p>
  
  <p><a href="https://i.stack.imgur.com/cQjhu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cQjhu.png" alt="enter image description here"></a></p>
  
  <pre><code>void part1() {
  int  width, height;
  unsigned char ** img = NULL;
  
  img = readBMP("package.bmp", &amp;height, &amp;width);
  
  }
  unsigned char**  readBMP(char* filename, int* height_r, int* width_r)
  {
  int i, j;
  FILE* f;
  fopen_s(&amp;f,filename, "rb");
  unsigned char info[54];
  fread(info, sizeof(unsigned char), 54, f); // read the 54-byte header
  
                                             // extract image height and width 
  //from header
  int width = *(int*)&amp;info[18];
  int height = *(int*)&amp;info[22];
  int pad_needed = 4 - (3 * width) % 4;   // pad calculation
  int paddedRow = 3 * width + ((pad_needed != 4) ? pad_needed : 0);
  
  unsigned char** map2d = (unsigned char**)malloc(width * sizeof(unsigned 
  char*)); // alocate memory for img 2d array
  for (i = 0; i &lt; width; i++) {
      map2d[i] = (unsigned char*)malloc(height * sizeof(unsigned char));
  }
  
  unsigned char* data = (unsigned char*)malloc(paddedRow * sizeof(unsigned 
  char));  // allocate memory for each read from file
  for (i = 0; i &lt; height; i++) {
      fread(data, sizeof(unsigned char), paddedRow, f); //read line from file
      for (j = 0; j &lt; width; j++) {
          map2d[j][i] = (int)data[3 * j]; // insert data to map2d. jump 3, 
             //becasue we need only one value of the colors (RGB)
      }
  }
  free(data);
  fclose(f);
  *width_r = width;
  *height_r = height;
  return map2d;
  }
  </code></pre>