v4l2攝像頭驅動

2021-06-22 05:13:54 字數 3722 閱讀 4837

環境:

硬體:radxa rock開發板,藍色妖姬t998無驅攝像頭

系統:lubuntu 3月15號韌體,v4l2

其實我只是把草根老師的部落格**改了些引數:

1.攝像頭的模式由o_rdwr | o_nonblock改為o_rdwr,若不改,會報dq_buf的bug

3.n_buffer中途會莫名其妙改變,所以在程式中人為賦值

程式執行後,會儲存count個bin檔案在選定目錄下。檔案內容是yuyv422的影象資料。

1.2.

#include #include #include #include #include #include #include #include #include #include #include #include "unistd.h"

typedef struct

buftype;

buftype user_buf_real;

buftype *user_buf=&user_buf_real;

int n_buffer = 0;

//鎵撳紑鎽勫儚澶磋澶?int open_camer_device()

printf("open camer %d \n",fd);

return fd;

}int init_mmap(int fd)

n_buffer = reqbuf.count; //mark reatch here

printf("n_buffer = %d\n",n_buffer);

//test_yz = calloc(reqbuf.count,sizeof(buftype));

//test

//user_buf->start =(void*)calloc(reqbuf.count,sizeof(*user_buf)); //mark-err

user_buf->start = calloc(reqbuf.count,sizeof(*user_buf));

//user_buf = (buftype*)(calloc(reqbuf.count,sizeof(*user_buf))); //mark-err

// printf("start \n");

printf("start %d \n",user_buf->start);

// if(user_buf == null)

//灝嗗唴鏍哥紦鍐插尯鏄犲皠鍒扮敤鎴瘋繘紼嬬┖闂? for(i = 0; i < reqbuf.count; i ++)

user_buf[i].length = buf.length;

user_buf[i].start =

mmap(

null,/*start anywhere*/

buf.length,

prot_read | prot_write,

map_shared,

fd,buf.m.offset

);test

printf("user_buf: %d \t start addr:%d \n",i,user_buf->start);

if(map_failed == user_buf[i].start)

} return 0;

}//鍒濆鍖栬棰戣澶?int init_camer_device(int fd)

,description = '%s'\n",

fmt.pixelformat & 0xff,(fmt.pixelformat >> 8)&0xff,

(fmt.pixelformat >> 16) & 0xff,(fmt.pixelformat >> 24)&0xff,

fmt.description);

} //鏌ヨ瑙嗛璁懼椹卞姩鐨勫姛鑳? ret = ioctl(fd,vidioc_querycap,&cap);

if(ret < 0)

printf("catability : \n");

printf("driver = %s \n",cap.driver);

printf("card = %s \n",cap.card);

//鍒ゆ柇鏄惁鏄竴涓棰戞崟鎹夎澶? if(!(cap.capabilities & v4l2_buf_type_video_capture))

//鍒ゆ柇鏄惁鏀寔瑙嗛嫻佸艦寮? if(!(cap.capabilities & v4l2_cap_streaming))

//璁劇疆鎽勫儚澶撮噰板嗘暟鎹牸寮忥紝濡傝緗噰板嗘暟鎹殑

//闀?瀹斤紝鍥懼儚鏍煎紡(jpeg,yuyv,mjpeg絳夋牸寮?

stream_fmt.type = v4l2_buf_type_video_capture;

stream_fmt.fmt.pix.width = 640;

stream_fmt.fmt.pix.height = 480;

stream_fmt.fmt.pix.pixelformat = v4l2_pix_fmt_yuyv;

stream_fmt.fmt.pix.field = v4l2_field_interlaced;

if(-1 == ioctl(fd,vidioc_s_fmt,&stream_fmt))

//鍒濆鍖栬棰戦噰板嗘柟寮?mmap)

init_mmap(fd);

return 0;

}int start_capturing(int fd)

} //寮€濮嬮噰板嗘暟鎹? type = v4l2_buf_type_video_capture;

if(-1 == ioctl(fd,vidioc_streamon,&type))

return 0;

}//灝嗛噰板嗗ソ鐨勬暟鎹斁鍒版枃浠朵腑

int process_image(void *addr,int length)

fwrite(addr,length,1,fp);

usleep(500);

fclose(fp);

return 0;

}int read_frame(int fd)

assert(buf.index < n_buffer);

//璇誨彇榪涗▼絀洪棿鐨勬暟鎹埌涓€涓枃浠朵腑

printf("buf.index: %d \n",buf.index);

process_image(user_buf[buf.index].start,user_buf[buf.index].length);

//process_image(user_buf->start,user_buf->length);

if(-1 == ioctl(fd,vidioc_qbuf,&buf))

return 1;

}int mainloop(int fd)

if(0 == r)

if(read_frame(fd))

break;

} }return 0;

}void stop_capturing(int fd)

return;

}void uninit_camer_device() }

//free(user_buf);

printf("start addr: %d \n",user_buf->start);

free(user_buf->start);

return;

}void close_camer_device(int fd)

return;

}int main()

USB攝像頭驅動配置及V4L2程式設計

摘要 學位授予單位 燕山大學 學位級別 碩士 學位授予年份 2011 其實uboot啟動映像主要是在原來的zimage前加上乙個他要0x40的tag,告訴uboot一些關於核心啟動的資訊。在arch arm boot makefile 62行開始有命令和規則 quiet cmd uimage uim...

V4L2 獲取和配置攝像頭

一 v4l2 獲取和配置攝像頭程式示例 include include include include include include include includeint fd const char input dev dev video0 const char qctrl name null i...

v4l2在幀緩衝區預覽攝像頭

在應用層通過v4l2 api將採集的攝像頭資料yuv轉為rgb後寫到幀緩衝區達到預覽攝像頭的目的,程式執行後切換到tty下就可以看到。我的螢幕是bgra格式的,這點要注意,不同螢幕格式不同,不同r,g,b的偏移通過修改 0x00 24 r0 16 g0 8 b0 0 中的順序即可 include i...