List,
I have been trying to search on reading an image file via C. I haven't been able to find code without libraries. However, being aware of the 'binary' mode in Windows (Turbo C++), I had read it using fopen, fread and fseek to read the header and then the contents. However, this reading was done reading individual bytes and not reading it using structures.
Apologies, ahead, because, I suspect I may be using wrong 'terms' or may have some incorrect information. (Correct me, thanks)
For example, a .bmp (grayscale image) file has first 54 bytes as header (IIRC, correct me, if I'm wrong). Somewhere within that, there's the height and width of the image.
Following the 54 bytes are the pieces of image data containing integers between 0 - 255 representing grayscale colors.
This seemed to work in Windows because I could see the results. Now, I do know that there are libraries that make this task easier in various distributions of Linux but the purpose (or requirements, If I may say) here it to read it in the same way as it was done in Windows.
Though I also do see 'b' mode in the manual page of 'man fread', but I'm doubtful about the results. If anyone has tried to read an image file or has good sample code that I can lookup, would like to have links to it. Alternately, if someone can put in a few details regarding this in a little more 'easy-to-understand' way, that would be helpful.
Thanks in advance for any help.
-- Roshan Baladhanvi
Narendra,
On Tue, Dec 29, 2009 at 10:57 AM, narendra sisodiya wrote:
use opencv
Hmm, you seemed to have missed the point. The intention is to do it using fread, fopen and fseek provided with the default 'C' (GLIBC) library.
Thanks, anyway for this, interesting to see this library for 'computer vision'.
-- Roshan Baladhanvi
On Tue, Dec 29, 2009 at 10:50 AM, Roshan kubunturos@gmail.com wrote:
List,
I have been trying to search on reading an image file via C.
Maybe you could have a look at the source code for a hex editor like okteta
Kussh
On Tue, Dec 29, 2009 at 10:50 AM, Roshan kubunturos@gmail.com wrote:
List,
I have been trying to search on reading an image file via C. I haven't been able to find code without libraries. However, being aware of the 'binary' mode in Windows (Turbo C++), I had read it using fopen, fread and fseek to read the header and then the contents. However, this reading was done reading individual bytes and not reading it using structures.
Chuck fopen and fread. Use open(2) and read(2) instead and read out the bytes into an unsigned char array. This should also work cross-platform without hassles.
Oh yeah, and chuck turbo c++ too ;)
On Tuesday 29 Dec 2009, Roshan wrote:
I have been trying to search on reading an image file via C. I haven't been able to find code without libraries. However, being aware of the 'binary' mode in Windows (Turbo C++), I had read it using fopen, fread and fseek to read the header and then the contents. However, this reading was done reading individual bytes and not reading it using structures.
Unix/Linux don't distinguish between binary and ASCII mode files. Use the same function calls as you do in Winduhs, just omit the "b" in the fopen.
Regards,
-- Raju