一、v4l2 獲取和配置攝像頭程式示例:
#include #include #include #include #include #include #include #includeint fd;
const char *input_dev = "/dev/video0";
const char *qctrl_name = null;
int qctrl_value = 0;
struct v4l2_capability cap;
struct v4l2_queryctrl qctrl;
static void print_qctrl(struct v4l2_queryctrl *qctrl)
printf("%-14s : id=%08x, type=%d, minimum=%d, maximum=%d\n"
"\t\t value = %d, step=%d, default_value=%d\n",
qctrl->name, qctrl->id, qctrl->type, qctrl->minimum, qctrl->maximum,
ctrl.value, qctrl->step, qctrl->default_value);
}static void print_menu(struct v4l2_querymenu *menu)
static int set_qctrl(struct v4l2_queryctrl *qctrl)
static void deal_qctrl(struct v4l2_queryctrl *qctrl)
static void qctrl_get(int id)}}
}}int main(int argc, char **argv)
fd = open(input_dev, o_rdwr);
if (fd < 0)
printf("open video '%s' success\n", input_dev);
ret = ioctl(fd, vidioc_querycap, &cap);
if (ret < 0)
if ((cap.capabilities & v4l2_cap_video_capture) == 0)
for (i = v4l2_cid_base; i < v4l2_cid_lastp1; i++)
for (i = v4l2_cid_private_base; i < v4l2_cid_private_base+25; i++)
printf("close video\n");
close(fd);
}
二、程式執行說明:
本程式是攝像頭引數獲取和配置的示例程式,所以系統必須帶有攝像頭驅動程式及攝像頭感測器
程式引數說明:
不帶任何引數,則顯示攝像頭可配置的引數,即其當前配置值
三、帶兩個引數,第乙個是要配置選項的名稱,第二項為其對應的值。
四、程式原理說明:
本程式可簡要使用如下序列說明其執行過程:
1. fd = open(input_dev, o_rdwr); 開啟 /dev/video0 裝置
2. ret = ioctl(fd, vidioc_querycap, &cap); 獲取攝像頭裝置的能力,例如照相、輸出、vbi、調頻什麼的。這裡只需照相能力
3. ioctl(fd, vidioc_queryctrl, &qctrl); 通過id來列舉出取攝像頭的queryctrl,這個結構體用來描述攝像頭的某個具體引數選項的(亮度、色度、**度什麼的), 包括id, 名稱、型別、極值和預設值。
4. ioctl(fd, vidioc_querymenu, &menu); 如果上面獲取的queryctrl型別是選單型別的,可使用該步驟來列出所有的選單項名稱。 這一步不是必須的,只是為了讓人更清除的知道queryctrl中每個值代表著什麼含義。例如 "light frequency filter" 這個選項的取值範圍是 0~2, 3個選單項說明其3個值的用途。
5. ioctl(fd, vidioc_s_ctrl, &ctrl) 和 ioctl(fd, vidioc_g_ctrl, &ctrl) 分別是設定和獲取引數項當前值的介面,只需指出要配置引數項的id即可。
五、以上幾個所涉及的介面體可在 /usr/include/linux/videodev2.h 檔案中找到
/*
* controls
*/struct v4l2_control ;
/* used in the vidioc_queryctrl ioctl for querying controls */
struct v4l2_queryctrl ;
/* used in the vidioc_querymenu ioctl for querying menu items */
struct v4l2_querymenu ; /*
* driver capabilities
*/struct v4l2_capability ;
v4l2攝像頭驅動
環境 硬體 radxa rock開發板,藍色妖姬t998無驅攝像頭 系統 lubuntu 3月15號韌體,v4l2 其實我只是把草根老師的部落格 改了些引數 1.攝像頭的模式由o rdwr o nonblock改為o rdwr,若不改,會報dq buf的bug 3.n buffer中途會莫名其妙改變...
USB攝像頭驅動配置及V4L2程式設計
摘要 學位授予單位 燕山大學 學位級別 碩士 學位授予年份 2011 其實uboot啟動映像主要是在原來的zimage前加上乙個他要0x40的tag,告訴uboot一些關於核心啟動的資訊。在arch arm boot makefile 62行開始有命令和規則 quiet cmd uimage uim...
v4l2在幀緩衝區預覽攝像頭
在應用層通過v4l2 api將採集的攝像頭資料yuv轉為rgb後寫到幀緩衝區達到預覽攝像頭的目的,程式執行後切換到tty下就可以看到。我的螢幕是bgra格式的,這點要注意,不同螢幕格式不同,不同r,g,b的偏移通過修改 0x00 24 r0 16 g0 8 b0 0 中的順序即可 include i...