BIG_T 发表于 2010-11-16 09:10:03

linux下ov9650摄像头抓图实现

经过几天的疑惑反复摸索,终于我摸索出来了。看来学东西的过程真的很重要,资料也很重要阿。
首先要说一下linux下ov9650初始化数据那里虽然写的是SXGA但实际应该读取的分辨率并不是1280*1024。而是320*240。有点太小了,接下来我会试试改改驱动。采出来是565模式的存储成bmp是要转化的。下面是我自己抓图代码,抓完之后转化成bmp图像。
int writebmp(unsigned short *bmp,int height,int width,char *filepath)
{
    int i,j,size;
    int fd;
    struct tagBITMAPFILEHEADER bfhead;
    struct tagBITMAPINFOHEADER binfohead;
    size=height*width;

    bfhead.bfSize=0x36+size*2;
    bfhead.bfLeft=0;
    bfhead.bfOffBits=0x36;

    binfohead.biSize=0x28;
    binfohead.bmpWidth=width;
    binfohead.bmpHeight=height;
    binfohead.biPlanes=1;
    binfohead.bicolors=0x10;
    binfohead.isCompressed=0;
    binfohead.biMapSize=size*2;
    binfohead.biHorizontal=0x0b13;
    binfohead.biVertical=0x0b13;
    binfohead.biusedcolors=0;
    binfohead.biimportcolors=0;
   
    fd=open(filepath,O_CREAT |O_RDWR);
    write(fd,"BM",2);
    i=write(fd,&bfhead,sizeof(struct tagBITMAPFILEHEADER));
    printf("Write filehead %dbytes\n",i);
    i=write(fd,&binfohead,sizeof(struct tagBITMAPINFOHEADER));
    printf("Write infohead %dbytes\n",i);
    i=write(fd,bmp,size*2);
    printf("Write bitmap %dbytes\n",i);
    lseek(fd,SEEK_SET,4);
    close(fd);
        return 1;
}

int main(int argc, char **argv)

{
int fd1,fd2;
unsigned short temp;
int nread,i,j,nwrite;
//int width,height;
unsigned long size1,size2;
unsigned char *y,*u,*v;
unsigned char r,g,b;
char file1name[]="/dev/camera";
unsigned short buff1,buff2;
unsigned short bmp;

size1=WIDTH*HEIGHT*2;/*如果认为是SXGA格式应该读的格式*/
fd1=open("/dev/camera",O_RDONLY);//|O_NONBLOCK

nread=read(fd1,buff1,size1);
/*这里由SXGA模式565转化为555*/
for(i=0;i<HEIGHT;i++)
   for(j=0;j<WIDTH;j++)
        {

        *(bmp+i*WIDTH+j)=((buff1&0xf800)>>1)|((buff1&0x07c0)>>1)|((buff1&0x1f));
       
        //printf("%x\t",*(bmp+i*WIDTH+j));
        }

i=HEIGHT,j=WIDTH;
writebmp(bmp, i, j,"bmp320sxgatest2");


}

自己做的图像头
struct tagBITMAPFILEHEADER{

    unsigned long bfSize;
    unsigned long bfLeft;
    unsigned long bfOffBits;

};
/*bmp图像的位图信息头*/
struct tagBITMAPINFOHEADER{
    unsigned long biSize;
    unsigned long bmpWidth;
    unsigned long bmpHeight;
    unsigned short biPlanes;
    unsigned short bicolors;
    unsigned long isCompressed;
    unsigned long biMapSize;
    unsigned long biHorizontal;
    unsigned long biVertical;
    unsigned long biusedcolors;
    unsigned long biimportcolors;
};

machoe 发表于 2010-11-16 10:38:03

帮你顶一个啊........................

天嵌_support1 发表于 2010-11-16 15:36:31

1# BIG_T


不错,学习了

lkcumt 发表于 2011-1-3 21:57:06

楼主的全部代码能给我发一份吗,我正研究这个,还无头绪。信箱:lkcumt@qq.com。谢谢。

glqinhan 发表于 2011-1-7 14:06:36

好东西,谢谢楼主

lkcumt 发表于 2011-1-7 18:46:36

为什么RGB565格式的不能存成bmp的?楼主能说一下原因吗?

mutou1991 发表于 2011-1-16 13:30:16

学习一下吧努力啊

jsjs2002 发表于 2012-2-2 15:38:51

只是贴个程序是没什么用处的,编程的算法或者思路才是最重要的。还有想改分辨率的确是修改OV9650的驱动,把原版的320 240改成你自己想要的就好。

亚瑟王 发表于 2012-2-6 11:28:52

亲。
RGB565要变成bmp图片,需要添加bmp的文件头等信息,然后还要设置bmp为16位色。如果bmp为24位色,还需要转换RGB565为RGB888。

it1988 发表于 2012-2-28 10:22:48

本帖最后由 it1988 于 2012-4-1 20:21 编辑

mark一下。
Linux下保存BMP图片。

hejia2012 发表于 2012-7-18 16:24:20

不错,值得学习,我正在做这个东西

kingwyt163 发表于 2012-9-20 10:52:14

楼主,能把源码发我一份吗,455184022@qq.com,谢谢了

kingwyt163 发表于 2012-9-20 10:52:51

jsjs2002 发表于 2012-2-2 15:38 static/image/common/back.gif
只是贴个程序是没什么用处的,编程的算法或者思路才是最重要的。还有想改分辨率的确是修改OV9650的驱动,把 ...

弱弱的问一句,OV9650的驱动在哪修改?
页: [1]
查看完整版本: linux下ov9650摄像头抓图实现