LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux Mint
User Name
Password
Linux Mint This forum is for the discussion of Linux Mint.

Notices

Reply
 
Search this Thread
Old 08-05-2010, 05:03 AM   #1
badriinvenkat
Member
 
Registered: Jul 2010
Posts: 39

Rep: Reputation: 15
Unhappy 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
 
Old 08-05-2010, 06:52 AM   #2
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,063

Rep: Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106
Quote:
Originally Posted by badriinvenkat View Post
now i need to open an image file present in my hard disk using c-programme
As with your previous questions, I don't know how to interpret the above question. You should try to start your threads with a clearer description of what you're trying to do and what part of it you don't understand.

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.

Last edited by johnsfine; 08-05-2010 at 06:59 AM.
 
1 members found this post helpful.
Old 08-05-2010, 06:59 AM   #3
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,094
Blog Entries: 2

Rep: Reputation: 111Reputation: 111
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.
 
1 members found this post helpful.
Old 08-05-2010, 07:35 AM   #4
badriinvenkat
Member
 
Registered: Jul 2010
Posts: 39

Original Poster
Rep: Reputation: 15
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
 
Old 08-05-2010, 07:36 AM   #5
badriinvenkat
Member
 
Registered: Jul 2010
Posts: 39

Original Poster
Rep: Reputation: 15
the format of the files stored will be in a different format and i need it to be in jpeg
 
Old 08-05-2010, 07:47 AM   #6
zirias
Member
 
Registered: Jun 2010
Posts: 361

Rep: Reputation: 59
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.
 
Old 08-05-2010, 07:52 AM   #7
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,063

Rep: Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106Reputation: 1106
Quote:
Originally Posted by badriinvenkat View Post
the format of the files stored will be in a different format and i need it to be in jpeg
Do I understand you correctly? You want to:

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.
 
Old 08-05-2010, 08:50 AM   #8
badriinvenkat
Member
 
Registered: Jul 2010
Posts: 39

Original Poster
Rep: Reputation: 15
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"

Last edited by badriinvenkat; 08-05-2010 at 08:54 AM.
 
Old 08-05-2010, 08:15 PM   #9
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,094
Blog Entries: 2

Rep: Reputation: 111Reputation: 111
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
 
1 members found this post helpful.
Old 08-06-2010, 01:52 AM   #10
badriinvenkat
Member
 
Registered: Jul 2010
Posts: 39

Original Poster
Rep: Reputation: 15
#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'
 
Old 08-06-2010, 07:34 AM   #11
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,094
Blog Entries: 2

Rep: Reputation: 111Reputation: 111
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
 
1 members found this post helpful.
Old 08-07-2010, 02:16 AM   #12
badriinvenkat
Member
 
Registered: Jul 2010
Posts: 39

Original Poster
Rep: Reputation: 15
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
 
Old 08-07-2010, 07:55 AM   #13
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,094
Blog Entries: 2

Rep: Reputation: 111Reputation: 111
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
 
Old 08-07-2010, 04:04 PM   #14
badriinvenkat
Member
 
Registered: Jul 2010
Posts: 39

Original Poster
Rep: Reputation: 15
@ 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)

Last edited by badriinvenkat; 08-07-2010 at 04:06 PM.
 
Old 08-07-2010, 11:11 PM   #15
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,094
Blog Entries: 2

Rep: Reputation: 111Reputation: 111
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 ""
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Thanks to this forum for solving wireless problem barnet1 LinuxQuestions.org Member Intro 1 04-26-2008 03:39 PM
I have a problem solving addiction dohpaz General 8 05-25-2007 12:27 PM
Need help solving this internet problem Please banner Linux - General 7 06-28-2005 06:44 PM
Best language for numerical problem solving? halfhaggis Programming 3 05-26-2004 02:11 AM
Partition problem solving... true_atlantis Linux - General 5 10-30-2003 12:16 PM


All times are GMT -5. The time now is 04:33 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration