can any one help me in solving my problem with c programme
hi one and all, you people helped me a lot till now thank you so much for you help
now i need to open an image file present in my hard disk using c-programme i need to write programme for that, can any one guide me for solving this thing thank you so much |
Quote:
Your should also try to do more reading on your own and learn some of what you need. I think (from your other threads) you are trying to do a difficult project and you are asking questions about trivial parts of that project. If you try to get through the harder parts the same way, you'll take forever to finish. You can open any kind of file (it doesn't matter that it is an image file) trivially in C using fopen. But the point of opening a file must be to do something with the contents. Then the fact that it is an image file matters and which specific format of image file matters and what you want to do with the contents matters. I don't currently know how to write a program to do anything interesting with the contents of any format of image file. If I wanted to write such a program, I would first either need to learn about that image format by finding and studying online documentation of the format, or learn about available libraries of functions for reading and manipulating that format, maybe by examining open source programs that display or edit that format. |
there are a few image libraries out there for reading images, like libpng and libjpeg. I think imagemagik also has a library that knows a few different formats.
|
thanks for your replies,
i am very sorry for my un-clear description above i will describe what i am doing now, i am doing a project which is based on linux mint using gcc, i need to work on two machines one is my PC and other i need to connect it through network, and the other system is a linux based security systems which records continously, i need to grab images from that recording system and apply filtering techniques for the grabbed frame. now i need to execute a programme on my PC with mint for opening an image and apply some filtering techniques, i want to learn new things very much, so even i am new to all these things i am trying very hardly to do these things, so please help me friends thank you |
the format of the files stored will be in a different format and i need it to be in jpeg
|
Hi, it's generally a good idea trying to create some programs yourself. But this sounds a little like "reinventing the wheel", because there are excellent tools to do this sort of things, just look for imagemagick. The "convert" command is probably what you would need.
PS: Of course, if you're interested in HOW this is done, you could take a look in imagemagick's source. |
Quote:
1) Read an image file in some other format (what format?) 2) Modify the contents (some "filter") 3) Save the result in jpeg format If I misunderstood, please explain. For operations such as compressing an image into jpeg format, it is usually better to invoke an existing program, rather invoking a library function linked into your own program (and certainly rather than writing your own code to do that step). In Linux it is pretty easy for a program to invoke another program to run in a child process. I just did a google search for +linux +"convert to jpeg" to find out what programs and/or functions are available to convert other formats to jpeg. You might want to try a similar search. The first item it found was an online copy of the man page for the program cjpeg http://linux.die.net/man/1/cjpeg That looks like it would be a good choice if you want to invoke a program as a child process to do the compression into jpeg format. |
1) Read an image file in some other format (what format?)
it is a raw format and the video is stored in .flm format and i need to xtract 1 frame from that video 2) Modify the contents (some "filter") i need compress the raw format using jpeg compressioner for this i need to use jpeg library files 3) Save the result in jpeg format yaa i need to save that in jpeg format and this is all from a live recording system If I misunderstood, please explain. For operations such as compressing an image into jpeg format, it is usually better to invoke an existing program, rather invoking a library function linked into your own program (and certainly rather than writing your own code to do that step). yaaa you are right "the bad thing is i cannot install any thing on the recording system i just have the access to store the required files on the storage and i can login into that system using ssh" |
if mplayer understands flm then it should work for the frame grab and convert to jpeg
mplayer input-file -ss <position in seconds> -frames 1 -vo jpeg |
#include <stdio.h>
int main (int argc, char *argv[]){ FILE *fp; int nchars, nwords, nlines; int lastnblank; /* 0 iff the last character was a space */ char c; if(argc!=2){ printf("Usage: %s home/badri/Desktop/proj/user.jpg", argv[0]); exit(0); } if((fp=fopen(argv[1],"r"))==NULL){ perror("fopen"); exit(0); } nchars=nwords=nlines=lastnblank=0; while((c=getc(fp))!=EOF){ nchars++; if (c=='n'){ if (lastnblank) nwords++; printf("words=%d, characters=%dn", nwords, nchars); nchars=nwords=lastnblank=0; nlines++; }else{ if (((c==' ')||(c=='t'))&(lastnblank)) nwords++; lastnblank=((c!=' ')&&(c!='t')); } } printf("lines=%dn", nlines); fclose(fp); } when i am going to execute this programme using gcc the out put is like this badri@linuxmint ~/Desktop/proj $ gcc sample2.c -o out sample2.c: In function ‘main’: sample2.c:11: warning: incompatible implicit declaration of built-in function ‘exit’ sample2.c:15: warning: incompatible implicit declaration of built-in function ‘exit’ badri@linuxmint ~/Desktop/proj $ ./out Usage: ./out user.jpgbadri@linuxmint ~/Desktop/proj $ gcc sample2.c -o out sample2.c: In function ‘main’: sample2.c:11: warning: incompatible implicit declaration of built-in function ‘exit’ sample2.c:15: warning: incompatible implicit declaration of built-in function ‘exit’ badri@linuxmint ~/Desktop/proj $ ./out Usage: ./out home/badri/Desktop/proj/user.jpgbadri@linuxmint ~/Desktop/proj $ gcc sample2.cgcc sample2.c -o out sample2.c: In function ‘main’: sample2.c:11: warning: incompatible implicit declaration of built-in function ‘exit’ sample2.c:15: warning: incompatible implicit declaration of built-in function ‘exit' |
you need to #include <stdlib.h> to get the prototype for exit and you'll probably want a \n at the end of that printf
|
sorry man it is not working properly, can any one give me a sample c programme for opening an image, i was really struggling for this since 2 days, please help me friends...
thank you all |
If you look at libjpeg developement package they have an example there
Otherwise this http://www.cim.mcgill.ca/~junaed/libjpeg.php seems to be a good step by step example |
@ estabroo thanks for u r valuable reply, when i am trying to execute it
it is displaying the following errors "badri@linuxmint ~/Desktop/proj/sample $ gcc jpeg_sample.c -o out /tmp/cclJRLSI.o: In function `read_jpeg_file': jpeg_sample.c:(.text+0x82): undefined reference to `jpeg_std_error' jpeg_sample.c:(.text+0xa6): undefined reference to `jpeg_CreateDecompress' jpeg_sample.c:(.text+0xbe): undefined reference to `jpeg_stdio_src' jpeg_sample.c:(.text+0xd4): undefined reference to `jpeg_read_header' jpeg_sample.c:(.text+0xe2): undefined reference to `jpeg_start_decompress' jpeg_sample.c:(.text+0x146): undefined reference to `jpeg_read_scanlines' jpeg_sample.c:(.text+0x1ba): undefined reference to `jpeg_finish_decompress' jpeg_sample.c:(.text+0x1c8): undefined reference to `jpeg_destroy_decompress' /tmp/cclJRLSI.o: In function `write_jpeg_file': jpeg_sample.c:(.text+0x26e): undefined reference to `jpeg_std_error' jpeg_sample.c:(.text+0x292): undefined reference to `jpeg_CreateCompress' jpeg_sample.c:(.text+0x2aa): undefined reference to `jpeg_stdio_dest' jpeg_sample.c:(.text+0x2e4): undefined reference to `jpeg_set_defaults' jpeg_sample.c:(.text+0x2fa): undefined reference to `jpeg_start_compress' jpeg_sample.c:(.text+0x343): undefined reference to `jpeg_write_scanlines' jpeg_sample.c:(.text+0x361): undefined reference to `jpeg_finish_compress' jpeg_sample.c:(.text+0x36f): undefined reference to `jpeg_destroy_compress' collect2: ld returned 1 exit status" when i execute this programme programme: #include "cv.h" #include "highgui.h" int main( int argc, char** argv ) { IplImage *image; image= cvLoadImage("home/badri/Desktop/proj/user.jpg"); cvShowImage( "image" ); cvWaitKey(0); cvReleaseImage(&image); return 0; } output: badri@linuxmint ~/Desktop/proj $ gcc sample3.c -o out sample3.c:1:16: error: cv.h: No such file or directory sample3.c:2:21: error: highgui.h: No such file or directory sample3.c: In function ‘main’: sample3.c:6: error: ‘IplImage’ undeclared (first use in this function) sample3.c:6: error: (Each undeclared identifier is reported only once sample3.c:6: error: for each function it appears in.) sample3.c:6: error: ‘image’ undeclared (first use in this function) |
well on the sample one you need to include libjpeg in your compile line
gcc jpeg_sample.c -o out -ljpeg for the second one you'll need to find those header files or if they are system ones include the <> instead of "" |
All times are GMT -5. The time now is 12:22 AM. |