PDA

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



Shweta
03-22-2005, 06:53 AM
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).

Aeluned
03-22-2005, 07:09 AM
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?

RigidBody
03-22-2005, 07:12 AM
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.

Shweta
03-22-2005, 07:20 AM
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!!!

dvm
03-22-2005, 07:28 AM
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!).

Shweta
03-22-2005, 07:36 AM
(Its so nice to have ppl replying so soon to my Query. :) )
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??

ZbuffeR
03-22-2005, 08:48 AM
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 (http://openil.sourceforge.net/) etc).

jide
03-22-2005, 01:55 PM
Originally posted by RigidBody:
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.Thanks for that ! :)

RigidBody
03-22-2005, 10:46 PM
you're welcome :)