arm linux 识别新硬盘_嵌入式Linux系列第13篇:USB摄像头拍照
1.引言
本篇介紹USB攝像頭的使用,實現的功能是通過攝像頭進行拍照,生成jpg格式圖片。
2.環(huán)境介紹
2.1.硬件
1) NUC972開發(fā)板
2) USB攝像頭
2.2.軟件
1) Uboot繼續(xù)使用之前文章用的,無須改動。
2) Kernel在上一篇基礎上,要做一定的修改,用來支持USB攝像頭識別。
3) Rootfs在上一篇用Buildroot生成的基礎上,無須改動。
3.內核配置
Linux 內核中已經包含了USB攝像頭的驅動,只要勾選上相關配置即可。
Device Drivers -->
Multimedia support --->
[*] Cameras/video grabbers support
V4L2 int device (DEPRECATED)
[*] Media USB Adapters --->
USB Video Class (UVC)
[*] UVC input events device support (NEW)
GSPCA based webcams (NEW) --->
USB Philips Cameras
[ ] USB Philips Cameras verbose debug (NEW)
[*] USB Philips Cameras input events device support (NEW)
CPiA2 Video For Linux
USB ZR364XX Camera support
USB Syntek DC1125 Camera support
USB Sensoray 2255 video capture device
USB SN9C1xx PC Camera Controller support (DEPRECATED)
[*] V4L platform devices --->
配置完,保存,編譯,之后下載到板子里。
插入USB攝像頭,打印信息如下:
說明驅動已經OK了。
4.libjpeg庫安裝
之前buildroot編出來的根文件系統(tǒng)里是有jpeglib庫的,版本是libjpeg.so.9.1.0,由于我們應用程序依賴的版本是8.0,所以單獨編譯了一個。
步驟如下:
1) 解壓jpegsrc.v8b.tar.gz
2) 進入到解壓后的jpeg-8b目錄里,執(zhí)行
./configure CC=arm-linux-gcc LD=arm-linux-ld --host=arm-linux --prefix=/home/topsemic/nuc972/toolchain/arm_linux_4.8/usr --exec-prefix=/home/topsemic/nuc972/toolchain/arm_linux_4.8/usr
其中:
–prefix參數是強制設定install之后生成文件的存放目錄,這里將其放到了交叉編譯工具鏈文件夾的/usr 目錄下,放到這里的原因是因為后面編譯應用程序時會在交叉工具鏈的目錄下查找相關的庫。
topsemic@topsemic-virtual-machine:~/nuc972/tool/jpeg-v8b/jpeg-8b$ ./configure CC=arm-linux-gcc LD=arm-linux-ld --host=arm-linux --prefix=/home/topsemic/nuc972/toolchain/arm_linux_4.8/usr --exec-prefix=/home/topsemic/nuc972/toolchain/arm_linux_4.8/usr
3)make 編譯
topsemic@topsemic-virtual-machine:~/nuc972/tool/jpeg-v8b/jpeg-8b$ make
4)最后make install
topsemic@topsemic-virtual-machine:~/nuc972/tool/jpeg-v8b/jpeg-8b$ make install
在/home/topsemic/nuc972/toolchain/arm_linux_4.8/usr/lib下生成相應的庫。
注:之前buildroot生成的文件系統(tǒng)里其實已經有了libjpeg,在上面可以看到文件為libjpeg.so.9.1.0,或者我們登陸到板子上
find / -name "libjpeg*" 查找下,在/usr/lib目錄下也可以看到
這三者的關系是:
使用ls -al 查看
其中l(wèi)ibjpeg.so 和libjpeg.so.9是軟連接文件,相當于windows下的快捷方式,如果我們在winscp下查看,可以看到他們的圖標上有個箭頭
真正使用的庫文件是libjpeg.so.9.2.0
5)我們需要將新編譯的libjpeg庫放到板子上,方法是先把板子上原有的三個文件刪掉,然后通過winscp拷貝libjpeg.so.8.0.2到板子的/usr/lib目錄下,
最后使用ln -s 源文件 目標文件 命令,新建兩個軟連接
5.應用程序
應用程序的編譯步驟如下:
1) 進入到v4l2_demo目錄
2) make編譯
3) 生成的可執(zhí)行文件是bin目錄下的mainapp
4) 將其放到板子里,運行結果如下:
# ./mainapp
----------- connected --------------
v4l2_open function open /dev/video0 success!
driver: uvcvideo
card: USB2.0 PC CAMERA
bus_info: usb-nuc970-ehci-2
version: 199276
capabilities: 84000001
Device /dev/video0: supports capture.
Device /dev/video0: supports streaming.
fmt.type: 1
pix.pixelformat: YUYV
pix.width: 640
pix.height: 480
pix.field: 1
Frame buffer 5: address = 0xb6c88000, length = 614400
Frame buffer 5: address = 0xb6bf2000, length = 614400
Frame buffer 5: address = 0xb6b5c000, length = 614400
Frame buffer 5: address = 0xb6ac6000, length = 614400
Frame buffer 5: address = 0xb6a30000, length = 614400
open /dev/video success!
------------- 0
call yuyv_to_rgb function
yuyv_to_rgb function excute OK!
2222222
333333
44444
555555
666666
777777
path3=./jpeg1.jpg 1
8888888
9999999
程序在不斷的拍攝并保存圖像,圖像名稱為jpegx.jpeg(x為1,2,3 依次增加)
6.結束語
本篇為大家介紹了Linux下USB攝像頭的簡單使用,歡迎大家多交流。
TopSemic 讓芯片使用更簡單
總結
以上是生活随笔為你收集整理的arm linux 识别新硬盘_嵌入式Linux系列第13篇:USB摄像头拍照的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 咖喱粉的生熟比例是多少?
- 下一篇: 香蕉上为什么长斑点?