Receiving JPEG packet from camera


 
Thread Tools Search this Thread
Top Forums Programming Receiving JPEG packet from camera
# 8  
Old 12-21-2010
When looking at image properties in firefox, image size in not defined.

How do you specify the image size for file?

Here is some debug info from identify on jpeg header.

Code:
# identify -verbose 2010-12-21_09-21-29.jpg
Image: 2010-12-21_09-21-29.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Class: DirectClass
  Geometry: 320x240
  Type: TrueColor
  Endianess: Undefined
  Colorspace: RGB
  Channel depth:
    Red: 8-bits
    Green: 8-bits
    Blue: 8-bits
  Channel statistics:
    Red:
      Min: 0 (0)
      Max: 255 (1)
      Mean: 126.909 (0.497684)
      Standard deviation: 76.9182 (0.30164)
    Green:
      Min: 0 (0)
      Max: 208 (0.815686)
      Mean: 6.00544 (0.0235508)
      Standard deviation: 11.4396 (0.0448613)
    Blue:
      Min: 0 (0)
      Max: 255 (1)
      Mean: 8.88395 (0.034839)
      Standard deviation: 17.7563 (0.0696327)
  Colors: 1556
  Rendering intent: Undefined
  Resolution: 1029x1543
  Units: Undefined
  Filesize: 4.6kb
  Interlace: None
  Background color: white
  Border color: #DFDFDF
  Matte color: grey74
  Page geometry: 320x240+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 50
  Orientation: Undefined
  JPEG-Colorspace: 2
  JPEG-Sampling-factors: 2x2,1x1,1x1
  Signature: 7afd494edfe783dded28011ccd4d1405166cf6f193e1e58a0ec891ac53e2dc53
  Tainted: False
  Version: ImageMagick 6.2.8 10/20/10 Q16 file:/usr/share/ImageMagick-6.2.8/doc/index.html
identify: Corrupt JPEG data: 6 extraneous bytes before marker 0xc0 `2010-12-21_09-21-29.jpg'.
identify: Premature end of JPEG file `2010-12-21_09-21-29.jpg'.
identify: Corrupt JPEG data: premature end of data segment `2010-12-21_09-21-29.jpg'.

# 9  
Old 12-21-2010
You don't need to research or guess the number of bytes. The operating system is quite probably telling you how many bytes you got from the camera, but you're not using it, or using it incorrectly. The parts of the code you've shown us, so far, have nothing to with reading the data, just writing it. For that matter, it's run in a loop which you've never shown us, which might have things wrong in it too.

None of the information on your corrupted output file will help tell us what's wrong in code we've never seen.

In short: We can't fix your code because you didn't show it to us. Please post your code. All of it.
# 10  
Old 12-23-2010
code is to long to put, but I think problem is with bitstream and way it constructs jpeg.

using fread to fwrite from on jpeg to another jpeg works, but
I am using read from serial device and using fwrite to jpeg file,
which seems to be causing the stream problem.

basics of main code to grab packets as they come in from serial:
Code:
fd = open(DEVICE, O_RDWR | O_NOCTTY |O_NDELAY);
res = read(fd,buf, BUFSIZE);
buf[res] = 0;
parse(buf,res);

parse code for each packet is basically
Code:
void parse(unsigned char *buff, size_t ss){
  // puts it into a buffer and sends each byte to fwrite
  for(i=0;i < ss ; i++){
    b = buff[i];
    // case statement here
    //when packet has data from jpeg send
    BlockW(&b); 
  }
}

Code:
void BlockW(unsigned char *b){
  FILE *fp;
  fp = fopen(filename, "ab");
  fwrite(b, sizeof(unsigned char), sizeof(unsigned char), fp);
  fclose(fp);
}

I actually found a website that has the exact same corrupted looking jpeg pictures as the ones that are created from code.

ImpulseAdventure - Fix Corrupt JPEG Photos!

Seems to be a stream issue, how would I create the fread to fwrite stream using read to fwrite, which seems to not put the stream correctly.
# 11  
Old 12-23-2010
That's a bit more helpful. You've opened the device with O_NDELAY, this means read might sometimes return -1, telling you to try again later. When this happens your code will still write something, even though it shouldn't.

Quote:
Seems to be a stream issue, how would I create the fread to fwrite stream using read to fwrite, which seems to not put the stream correctly.
You have to use read() for handling a device file.

Code:
int fd = open(DEVICE, O_RDWR | O_NOCTTY |O_NDELAY);
int out=open("outfile", O_CREAT|O_WRONLY, 0660);

while(1)
{
        ssize_t off=0;
        ssize_t res = read(fd,buf, BUFSIZE);
        // Ignore when read didn't get anything
        if(res < 0)
                continue;
        else if(res == 0) // should your app expect EOF?
        {
                fprintf(stderr, "EOF?\n");
                break;
        }

        fprintf(stderr, "Read %d bytes\n", (int)res);
        // buf[res] = 0; why null-terminate what's not a string?
        //parse(buf,res); we're not in pascal anymore

        // We can probably write everything at once.  when we don't,
        // just write the bits that didn't get written yet.
        while(off < res)
        {
                ssize_t w=write(outfd, buf+off, res-off);
                if(w > 0)
                        off += w;
                else
                {
                        perror("write error");
                        break;
                }
                fprintf(stderr, "Wrote %d bytes\n", (int)w);
        }
}

close(out);
close(fd);

In summary: Always check the return value of everything.
# 12  
Old 01-06-2011
Problem Solved

Packets where coming in blocks with headers and check sum data, and needed to be calculated and parsed.

Headache is gone Smilie , feel pretty good now. Smilie
# 13  
Old 01-06-2011
...nothing we'd ever have guessed without seeing all your code Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Packet loss coming with big packet size ping

(5 Replies)
Discussion started by: Vishal_dba
5 Replies

2. Shell Programming and Scripting

renaming jpeg files

Hi guys im currently trying to write a script which includes rename files and this is the part where i fail i have a list of files eg and i want to rename them so any help really would be appreciated Cheers dunryc (7 Replies)
Discussion started by: dunryc
7 Replies

3. Programming

Receiving broadcast packets using packet socket

Hello I try to send DHCP RENEW packets to the network and receive the responses. I broadcast the packet and I can see that it's successfully sent using Wireshark. But I have difficulties receiving the responses.I use packet sockets to catch the packets. I can see that there are responses to my... (0 Replies)
Discussion started by: xyzt
0 Replies

4. Shell Programming and Scripting

makefile to convert .jpeg to .png thumnails

Hello! I'm desperately trying to write a makefile that converts and scales jpeg files to png files in subdirectories I want to use netpbm, so I just need the commands: anytopnm pnmscale pnmtopng For various reasons i want to use a makefile. This is the first time i use the make tool... (1 Reply)
Discussion started by: henningbaer
1 Replies

5. Programming

How to insert JPEG on each side of the cube using openGL in C

Hi, how to insert JPEG on each side of the cube using OpenGL in C language.. i have a program for cube.. guide me ,,, any answer will valuable.. (3 Replies)
Discussion started by: Ravikishore
3 Replies

6. UNIX Desktop Questions & Answers

problem with camera ID 0c45:613b Microdia Win2 PC Camera Ubuntu

Hi to all Like in the subject, i got the problem with camera ID 0c45:613b Microdia Win2 PC Camera under Ubuntu. When i plug in camera to USB, Ubuntu put in sn9c102 module, but on this site Linux Kernel Driver Database: CONFIG_USB_GSPCA_SONIXJ: SONIX JPEG USB Camera Driver is information that... (0 Replies)
Discussion started by: m0z4rt
0 Replies

7. IP Networking

Problem Receiving the first OSPF packet

I trying to send and receive OSPF packets. I am using RAW Sockets(socket(AF_INET, SOCK_RAW, IPPROTO_OSPF)) to do this. I am successfully able to send an OSPF Hello packet however I am not able to receive a OSPF packet if I have not sent an OSPF packet earlier on the RAW SOCKET. Scenario: ... (3 Replies)
Discussion started by: cosmic_egg
3 Replies

8. UNIX for Dummies Questions & Answers

how do I view a jpeg?

I use gv or ggv to view a .pdf, or .ps file. What will allow me to see a jpeg file? If it matters, I'm using xterm on a PowerBook G4. (0 Replies)
Discussion started by: dsstamps
0 Replies

9. UNIX for Advanced & Expert Users

Jpeg viewer on SunOS 5.8

I was wondering what program can i use instead of mozilla to view a picture on a sun solaris system running SunOS 5.8. To view a pic i'm currently doing it this way: xterm -sb -fn screen-bold -g 60x30+0-0 -title '%s window - pls quit window upon completion ' -e mozilla file:///usr/sailing.JPG ... (4 Replies)
Discussion started by: wisher115
4 Replies

10. UNIX for Dummies Questions & Answers

Convert Jpeg to useable Unix Pics

I'm running a Sunblade 1500 with 2 XVR-100 video cards. I have Xinerama runing as well. Desktop is CDE. Can someone help me in converting Jpeg pictures so that I can use them as backdrops? Is there a way to make the picture come on both monitors instead of streaching it across both? Thanks. (1 Reply)
Discussion started by: HSTheDuck
1 Replies
Login or Register to Ask a Question