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?