reading from and saving as bmp+image processing in OpenGL... a lot of q's

How do u implement a hough transform on OpenGL?
that brings me to another question… are there any API’s to convert OpenGL images to .bmp (etc) … and to read from a rendered image???
How about reading frame buffers at run time (or real time).

Do you mean ‘hue’ ?
OpenGL has no provisions for doing that…you have to do it yourself, and so it’s not really an OpenGL question - I would answer but don’t know off hand how that’s implemented.

to read the contents of a frame buffer, use glReadPixels in conjunction with glReadBuffer() to set the buffer you want to read from (front,back,etc…).

what’s an OpenGL image? a rendered scene? something residing in the frame buffer?

for a screenshot i recommend creating a true color tga file, which is as simple as:

void ScreenToTGA(int W, int H) {
 FILE		*out = fopen("screenshot.tga", "w");
 short		TGAhead[] = {0, 2, 0, 0, 0, 0, W, H, 24};
 char		pixel_data[3*W*H];

 fwrite(&TGAhead, sizeof(TGAhead), 1, out);
 glReadBuffer(GL_FRONT);
 glReadPixels(0, 0, W, H, GL_BGR, GL_UNSIGNED_BYTE, pixel_data);
 fwrite(pixel_data, 3*W*H, 1, out);
 fclose(out); }

W and H are the image with/height. if you don’t like tga, you can convert it to bmp or something else with irfan view, for example.

this is how it is…
1>i need to take a seperately rendered image… save it as a bmp.
2>then read back the frame buffer,and determine vertices.
3>After this i have to do a Hough transform on it.
This is to do the edge linking (finding the lines between the points funda…)
ultimately this is teh concept behind the idea of object recognition so to say.
i hope im on the right track!!!

Well, if I’ve got it right, you first need to load the image. You need to know what’s the format of the image. Once you load it (no OpenGL required up till here, you can show it on screen either as a texture, or as a glWritePixels (or some function like that). As for edge detection, I don’t think this question really relates to OpenGL but to object recognition. Usually your image will be in memory 1 byte for Red, 1 byte for Green, 1 byte for Blue, maybe 1 byte for Alpha and then the next pixel and then the next pixel and on and on (don’t forget to change row!).

(Its so nice to have ppl replying so soon to my Query. :slight_smile: )
This work needs to be done in OpenGL.

Reading back the frame buffers is well figured out, loading format of the image is upto me.I was wishing there was already an API present to load the rendered image and to read it. …

Also saving a rendered image as anything is a mystery to me.
saw something on saving as a tiff but on Win ( :mad: ) i am on the IRIX.

Now what??

glReadPixels(0, 0, W, H, GL_BGR, GL_UNSIGNED_BYTE, pixel_data);

Once you have done this, it is no longer an OpenGL problem : the pixel_data array as the raw image info. To save in a file format,either do it yourself as mentionned above, or use one of the multiple libs available (such as DevIL etc).

Originally posted by RigidBody:
[b]for a screenshot i recommend creating a true color tga file, which is as simple as:

void ScreenToTGA(int W, int H) {
 FILE		*out = fopen("screenshot.tga", "w");
 short		TGAhead[] = {0, 2, 0, 0, 0, 0, W, H, 24};
 char		pixel_data[3*W*H];

fwrite(&TGAhead, sizeof(TGAhead), 1, out);
glReadBuffer(GL_FRONT);
glReadPixels(0, 0, W, H, GL_BGR, GL_UNSIGNED_BYTE, pixel_data);
fwrite(pixel_data, 3WH, 1, out);
fclose(out); }

W and H are the image with/height. if you don't like tga, you can convert it to bmp or something else with irfan view, for example.[/b]

Thanks for that ! :slight_smile:

you’re welcome :slight_smile: