7 Replies - 1544 Views - Last Post: 02 April 2013 - 11:42 AM Rate Topic: -----

#1 JDeveloper.  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 31-August 11

How to read jpeg image using C in 2D Array !

Posted 01 April 2013 - 12:57 PM

Hello i'm working on project that convert image to text [OCR] but my doctor asked for manual algorithm so i can't use opencv or something like that but any suggestion will be great too for OCR in C ! and now i'm trying to read a jpeg using C language and convert that image to 2D Array like this one :

int A[10][10] ={
				{250,249,222,233,244,20,244,244,244,244},
				{250,249,222,233,19,20,244,244,244,244},
				{250,249,222,18,244,19,244,244,244,244},
				{250,249,222,233,244,17,244,244,244,244},
				{250,249,222,233,244,18,244,244,244,244},
				{250,249,222,233,244,10,244,244,244,244},
				{250,249,222,233,244,20,244,244,244,244},
				{250,249,222,233,244,19,244,244,244,244},
				{250,249,222,233,244,20,244,244,244,244},
				{250,249,222,233,244,18,244,244,244,244},
			   };


but the 10x10 will depend on the height and the width of the image
i tried alot of libraries GDAL, Jpeglib ..etc but nothing worked
i finished my code on the above matrix but now it must load an image from desktop for example or any directory and convert it to matrix like the above one :).

I'm really appreciate any help u can do :)

Is This A Good Question/Topic? 0
  • +

Replies To: How to read jpeg image using C in 2D Array !

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3160
  • View blog
  • Posts: 9,532
  • Joined: 05-May 12

Re: How to read jpeg image using C in 2D Array !

Posted 01 April 2013 - 04:19 PM

What do the values in the 2D array represent?
Was This Post Helpful? 0
  • +
  • -

#3 JDeveloper.  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 31-August 11

Re: How to read jpeg image using C in 2D Array !

Posted 01 April 2013 - 05:03 PM

View PostSkydiver, on 01 April 2013 - 04:19 PM, said:

What do the values in the 2D array represent?

It will represent the pixels of the jpg RGB or greylevel JPG [in other words IMAGE DATA]

This post has been edited by JDeveloper.: 01 April 2013 - 05:03 PM

Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5641
  • View blog
  • Posts: 12,359
  • Joined: 16-October 07

Re: How to read jpeg image using C in 2D Array !

Posted 01 April 2013 - 05:39 PM

Jpeg is a horrid choice is your goal is to start the real work after you've read the image. It's lossy compression, so probably not would you'd want in OCR, anyhow.

After a raw pixel dump, something from the Netpbm family would be a choice. Indeed, some formats are actually C code. A close runner up would be BMP.
Was This Post Helpful? 0
  • +
  • -

#5 JDeveloper.  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 31-August 11

Re: How to read jpeg image using C in 2D Array !

Posted 02 April 2013 - 12:51 AM

View Postbaavgai, on 01 April 2013 - 05:39 PM, said:

Jpeg is a horrid choice is your goal is to start the real work after you've read the image. It's lossy compression, so probably not would you'd want in OCR, anyhow.

After a raw pixel dump, something from the Netpbm family would be a choice. Indeed, some formats are actually C code. A close runner up would be BMP.


The problem that my camera capture only JPEG images so i have to work on JPEG but now i'm writing the code for my pc for testing before burning it on the chip .
Was This Post Helpful? 0
  • +
  • -

#6 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 710
  • View blog
  • Posts: 2,033
  • Joined: 20-March 10

Re: How to read jpeg image using C in 2D Array !

Posted 02 April 2013 - 01:41 AM

OCR is quite involved,

I have done this myself.

What I did was look at open source c libraries and basically interpreted what they did

a good open source library can be found here

http://code.google.c.../tesseract-ocr/

Regards

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#7 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5641
  • View blog
  • Posts: 12,359
  • Joined: 16-October 07

Re: How to read jpeg image using C in 2D Array !

Posted 02 April 2013 - 07:09 AM

My mistake. You are willing to use a library? So, what have you tried?

I'd start with something like:
#include <stdio.h>
#include <jpeglib.h>
#include <stdlib.h>

// gcc -ljpeg ...

typedef unsigned char Pixel;

typedef struct {
	unsigned int width, height;
	Pixel *data;
} RawImage;

Pixel getGreyScaleFromRGB(unsigned char r, unsigned char g, unsigned char B)/>;
RawImage *createRawImage(unsigned int width, unsigned int height);
void saveRawImage(RawImage *, const char *filename);
void freeRawImage(RawImage **);
RawImage *loadRawImageFromJpeg(const char *filename);
RawImage *loadRawImage(const char *filename);
Pixel getPixel(RawImage *, int x, int y);
void setPixel(RawImage *, int x, int y, Pixel);



The library I'd choose would be libjpeg mostly because it's standard.

If your format is YUV you'll probably just have to read three bytes and keep only the first (Y) for grey scale, which sounds like what you're after.

Also, you could just use something like imagemagick to translate your format and do transformations. Then, take it from there.
Was This Post Helpful? 0
  • +
  • -

#8 JDeveloper.  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 31-August 11

Re: How to read jpeg image using C in 2D Array !

Posted 02 April 2013 - 11:42 AM

View Postbaavgai, on 02 April 2013 - 07:09 AM, said:

My mistake. You are willing to use a library? So, what have you tried?

I'd start with something like:
#include <stdio.h>
#include <jpeglib.h>
#include <stdlib.h>

// gcc -ljpeg ...

typedef unsigned char Pixel;

typedef struct {
	unsigned int width, height;
	Pixel *data;
} RawImage;

Pixel getGreyScaleFromRGB(unsigned char r, unsigned char g, unsigned char B)/>/>;
RawImage *createRawImage(unsigned int width, unsigned int height);
void saveRawImage(RawImage *, const char *filename);
void freeRawImage(RawImage **);
RawImage *loadRawImageFromJpeg(const char *filename);
RawImage *loadRawImage(const char *filename);
Pixel getPixel(RawImage *, int x, int y);
void setPixel(RawImage *, int x, int y, Pixel);



The library I'd choose would be libjpeg mostly because it's standard.

If your format is YUV you'll probably just have to read three bytes and keep only the first (Y) for grey scale, which sounds like what you're after.

Also, you could just use something like imagemagick to translate your format and do transformations. Then, take it from there.


I tried to use this library but i will try with the above code again :)
the problem is i'm trying to write my code from scratch for my own usebut i don't know where can i begin read the jpeg :S !
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1