Join Today
+ Reply to Thread
Results 1 to 9 of 9
  1. #1

    Default My sourcecode for calling camera and geting snapshot

    I hope to call camera directly, preview and then can get snapshot.
    Code:
    #include <sys/ioctl.h>
    #include <sys/time.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include <string.h>
    #include <stdio.h>
    #include <fcntl.h>
    
    #include <linux/types.h>
    #include <linux/videodev.h>
    #include "linux/pxa_camera.h"
    
    int main(int argc, char *argv[]) {
    
      printf("camdump 0.1\n");
    
      //atexit(&myexit);
    	
    	char* buffer;
    
      struct video_capability cap;
      struct video_picture    pic;
      struct video_window     win;
      
      struct ioctl_data {
                    int val1;
                    int val2;
            };
      struct ioctl_data io_data;
    
    	int height,width,n,output;
    	int videodev = 0;
    
      // Video-Device starten und konfigurieren
      
      videodev = open("/dev/video0",O_RDONLY);
      if (videodev < 0) { perror("/dev/video0"); exit(1); }
    
      if (ioctl(videodev,VIDIOCGCAP ,&cap) < 0) { perror("VIDIOCGCAP");  exit(1); }
      if (ioctl(videodev,VIDIOCGPICT,&pic) < 0) { perror("VIDIOCGPICT"); exit(1); }
    
      width  = 320;//cap.maxwidth;
      height = 240;//cap.maxheight;
    
      io_data.val1 = CAMERA_IMAGE_FORMAT_YCBCR422_PACKED;
      io_data.val2 = CAMERA_IMAGE_FORMAT_YCBCR422_PACKED;
            if (ioctl(videodev, WCAM_VIDIOCSINFOR, &io_data)) {
                    printf("Error setting camera format.\n");
                    exit(2);
            }
    	printf("name:%s\nwidth:%d\nheight:%d\nformat:%d\n\n",cap.name,cap.maxwidth,cap.maxheight,pic.palette);
    
    	buffer = (char*)malloc(width*height*2);
    
      if (ioctl(videodev,VIDIOCGWIN,&win) < 0) { perror("VIDIOCGWIN"); exit(1); }
      win.x = win.y = 0; win.width  = width;  win.flags |= (15 << 16);
      win.clipcount = 0; win.height = height; // Framerate  ^^
      if (ioctl(videodev,VIDIOCSWIN,&win) < 0) { perror("VIDIOCSWIN"); exit(1); }
    
      if (ioctl(videodev,VIDIOCCAPTURE,STILL_IMAGE) < 0) { perror("VIDIOCCAPTURE"); exit(1); }
    
      n = read(videodev,buffer,width*height*2);
    
    	output = open("out.raw",O_RDWR|O_CREAT|O_TRUNC);
    	int i = 0;
    /*	for(; i < 320*240; i++)
    	{
    		
    		write( output, buffer+i*2+1,1); 
    		
    	}
    	*/
    	write(output,buffer,n);
    	close(output);
    
    	close(videodev);
    	free(buffer);
    	return 0;
    }

    this program run on E680i, and it can product a file out.raw which supposed to be a picture.but I have found that the file contains many block of "80 00"(view through UltraEditor"). I doubt this is not correct image data.how can I get a picture?please help!
    And I still can not preview. I think that it may be have something to do with the last problem. am I right? who can tell me the main steps for preview?

  2. #2

    Default Re: My sourcecode for calling camera and geting snapshot

    I don't think it contains any meaningful data cause once you're running the camera application, you're already accessing the device and having another application (your main) access the camera at the same time is not possible I think; it's not supported.

  3. #3
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    551

    Default Re: My sourcecode for calling camera and geting snapshot

    out.raw is the picture in raw image format..i.e., uncompressed, camera-specific image. This can be converted into jpeg or any other image though I do not know how...my sanyo camera can photograph images in raw format (.someother extension) and the software supplied with the camera can convert the raw image...but raw image was almost 2MB while the jpeg image retrieved from it was just 523KB...

    So i suppose for this camera type, there will be a way to convert the raw image into some known format..
    ** SANDMAN **
    --------------------
    Craig A.C. Gomez
    Software Engineer (Developer)
    SkillNet Solutions Inc.
    http://www.skillnetinc.com/

    THERE ARE NO STUPID QUESTIONS... BUT THERE ARE A LOT OF INQUISITIVE IDIOTS...

  4. #4

    Default Re: My sourcecode for calling camera and geting snapshot

    @mserougi
    I telnet to my E680i and run the program by :
    ./camdump
    so, I think at that time there is only one (my main) program accessing camera.

    any body have successfully take a pic through own code?

  5. #5

    Default Re: My sourcecode for calling camera and geting snapshot

    Oh I thought you meant you wanted to take a shot with the camera application that came with the phone while running your application at the same time; to like add a shot to your application without writing your own code to handle the camera.

  6. #6
    Join Date
    Sep 2005
    Location
    BorderlessLinuxWorld
    Posts
    110

    Default Re: My sourcecode for calling camera and geting snapshot

    Theres a post (with source - check first page of sticky with subject 'controlling the camera') already to capture the image in YCbCr format (and it works)!

  7. #7

    Default

    hi,

    can you please share the pxa_camera.h and other lib files used to compile the source you posted?
    i have a cygwin + crosstool set up and i cannot find the .h file

    thanks.

  8. #8
    Join Date
    Mar 2008
    Location
    just at the other end of the line.
    Posts
    879

    Default

    Hi riteshtonk,
    Did you search into the a780 or E680i kernel sources?
    Say developer, but it's so hard!

  9. #9

    Default

    hi sabrod,

    thx for the reply. I have the kernel sources of a1200 and didnt find the file there. anyways, looking at the code, i realize that the file may not be actually needed.
    i just need to replace STILL_IMAGE with constant 1

    i managed to compile the code, but when i execute to execute it, I get the following error:
    VIDIOCCAPTURE: Cannot allocate memory

    any idea what am I doing wrong here?


 
+ Reply to Thread

Similar Threads

  1. calling all mallu owners
    By desirascal in forum Indian Lounge
    Replies: 5
    Last Post: 02-12-2008, 07:23 AM
  2. Q: Problem in calling more than 30 mins
    By sathya_rajiv in forum E6 General Chat
    Replies: 9
    Last Post: 10-15-2007, 02:29 AM
  3. video snapshot???
    By Treikens in forum E6 General Chat
    Replies: 0
    Last Post: 07-28-2007, 09:06 PM
  4. Doesn't show who is calling?
    By Phenomenon in forum A1200 General Chat
    Replies: 2
    Last Post: 06-11-2007, 02:38 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Single Sign On provided by vBSSO

Search Engine Optimization by vBSEO 3.6.0 RC 1