2011年5月13日 星期五

Beagleboard xM - Camera board LI-5M03

玩了一陣子LI-BCM3M1 camera board發現不管什麼解析度都只能達到5~8fps.數據相當的難看,主要原因是driver限制住了.
到chip vendor Aptina網站找mt9t112 datasheet 竟然還要簽 NDA,發信去也不鳥我...Shit.

因此轉而試試五百萬畫素的LI-5M03, Aptina 有提供datasheet
http://www.aptina.com/products/image_sensors/mt9p031i12stc/
此外更提供給BeagleBoard XM driver source code放在github,我clone了一份.
https://github.com/gigijoe/BeagleBoard-xM

mt9p031 driver我有做一些修改
其中值得一提的是Camera輸出的影像非常暗,所以我把analog gain調高

@@ -538,12 +538,19 @@
     mdelay(200);
 
     ret |= mt9p031_set_params(priv->client, pix->width, pix->height);
-   
+#if 0   
     ret |= mt9p031_reg_write(client, REG_MT9P031_GREEN_1_GAIN, 0x0051);      //Green1_gain_reg
     ret |= mt9p031_reg_write(client, REG_MT9P031_BLUE_GAIN, 0x0051);      //Blue_gain_reg
     ret |= mt9p031_reg_write(client, REG_MT9P031_RED_GAIN, 0x0051);      //Red_gain_reg
     ret |= mt9p031_reg_write(client, REG_MT9P031_GREEN_2_GAIN, 0x0051);      //Green2_gain_reg
     ret |= mt9p031_reg_write(client, REG_MT9P031_GLOBAL_GAIN, 0x0008);        //Analog Gain
+#endif
+  ret |= mt9p031_reg_write(client, REG_MT9P031_GREEN_1_GAIN, 0x0079);   //Green1_gain_reg
+  ret |= mt9p031_reg_write(client, REG_MT9P031_BLUE_GAIN, 0x0079);    //Blue_gain_reg
+  ret |= mt9p031_reg_write(client, REG_MT9P031_RED_GAIN, 0x0079);   //Red_gain_reg
+  ret |= mt9p031_reg_write(client, REG_MT9P031_GREEN_2_GAIN, 0x0079);   //Green2_gain_reg
+  ret |= mt9p031_reg_write(client, REG_MT9P031_GLOBAL_GAIN, 0x0026);    //Analog Gain



這份driver source code 要自行擺放檔案到正確的位置,以及部份檔案需要手動剪貼.
基本上不困難,我就不在此詳述.更動檔案如下

arch/arm/mach-omap2/board-omap3beagle.c
arch/arm/mach-omap2/board-omap3beagle-camera.c
drivers/media/video/mt9p031.c
drivers/media/video/mt9p031.h
drivers/media/video/Makefile
drivers/media/video/Kconfig

設定mt9p031 kernel config 為
接著重新compile kernel及module並安裝至root file system.

如果driver 順利掛上,在kernel log會看到

mt9p031 2-0048: mt9p031 chip ID 1801

根據driver source 中 README提到可以透過sysfs更改camera 參數.我實際測試卻出現錯誤@@

# cd /sys/devices/platform/i2c_omap.2/i2c-2/2-0048/
# cat gain_val 24
# echo "40" > gain_val
[ 2209.002258] mt9p031 2-0048: Error setting gain.-121
[ 2209.006988] mt9p031: Global gain write failed

Camera 測試的可用gstreamer.
不過實際測試frame rate還是無法到達30fps應該是gstreamer效率的關係,
因此我修改TI提供的demo程式來讀取camera確實就能達到30fps.
接著再把以前曾經實做過的以TI DSP encode H.264加上去,最後再輸出打包為H264RTP封包.
source code放在github

https://github.com/gigijoe/BeagleBoard-xM-video_encode_v4l2_rtp

將project抓下來後請搬到
$DVSDK/dmai_2_20_00_14/packages/ti/sdo/dmai/apps/
cd $DVSDK
make dmai

執行檔位在
dmai_2_20_00_14/packages/ti/sdo/dmai/apps/video_encode_v4l2_rtp/linux/video_encode_v4l2_rtp_dm3730.x470MV

將它複製到root filesystem中 /usr/share/ti/ti-dmai-apps/

萬事具備,執行吧

BeagleBoard xM

cd /usr/share/ti/ti-dmai-apps/
./video_encode_v4l2_rtp_dm3730.x470MV -b 2000000 -c h264enc -i /dev/video0 -o 192.168.168.93 -p 1234 -r 640x480 --benchmark

PC : IP 192.168.168.93

gst-launch udpsrc port=1234 caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264" ! rtph264depay ! ffdec_h264 ! xvimagesink


最後在透過usb ethernet 傳送影像會hang住,網路上有人發生過但還沒有答案.

http://groups.google.com/group/beagleboard/browse_thread/thread/375026c833e1308b/528751f3690c7d5b?lnk=raot

[  103.995117] ------------[ cut here ]------------
[  103.999908] WARNING: at net/sched/sch_generic.c:255 dev_watchdog+0x17c/0x280()
[  104.007202] NETDEV WATCHDOG: usb0 (smsc95xx): transmit queue 0 timed out
[  104.014099] Modules linked in: sdmak lpm_omap3530 dsplinkk cmemk bufferclass_ti omaplfb pvrsrvkm ipv6 rtc_twl rtc_core mt9p031
[  104.025756] [ ] (unwind_backtrace+0x0/0xdc) from [ ] (warn_slowpath_common+0x48/0x60)
[  104.035247] [ ] (warn_slowpath_common+0x48/0x60) from [ ] (warn_slowpath_fmt+0x24/0x30)
[  104.044921] [ ] (warn_slowpath_fmt+0x24/0x30) from [ ] (dev_watchdog+0x17c/0x280)
[  104.054199] [ ] (dev_watchdog+0x17c/0x280) from [ ] (run_timer_softirq+0x268/0x378)
[  104.063568] [ ] (run_timer_softirq+0x268/0x378) from [ ] (__do_softirq+0xf0/0x1ec)
[  104.072784] [ ] (__do_softirq+0xf0/0x1ec) from [ ] (irq_exit+0x48/0x9c)
[  104.081024] [ ] (irq_exit+0x48/0x9c) from [ ] (asm_do_IRQ+0x74/0x90)
[  104.089019] [ ] (asm_do_IRQ+0x74/0x90) from [ ] (__irq_svc+0x44/0xa8)
[  104.097076] Exception stack(0xc0603f88 to 0xc0603fd0)
[  104.102172] 3f80:                   00000000 80000013 00f9982c 00000000 c0602000 c064db9c
[  104.110412] 3fa0: c002f014 c0605e68 8002cc0c 413fc082 0000001f 00000000 c06085b8 c0603fd0
[  104.118774] 3fc0: c0045450 c0036f1c 60000013 ffffffff
[  104.123962] [ ] (__irq_svc+0x44/0xa8) from [ ] (cpu_idle+0x78/0xbc)
[  104.131866] [ ] (cpu_idle+0x78/0xbc) from [ ] (start_kernel+0x260/0x2c0)
[  104.140197] [ ] (start_kernel+0x260/0x2c0) from [<80008034>] (0x80008034)
[  104.147827] ---[ end trace 640b83e4eff706c8 ]---

我猜應該是hardware的問題,因為我用USB Wifi也會當.
目前的解法是從USB otg port接USB hub再接USB wifi.
這樣,網路就不會斷了...

Reference :
http://maxgalemin.blogspot.com/2011/04/li-5m03-camera-on-beagleboard-xm.html

http://gitorious.org/rowboat/hardware-ti-omap3/blobs/e82865bd56a086480972fecdecc6f38308c05c35/liboverlay/v4l2_utils.c

http://blogold.chinaunix.net/u/19273/showart_2254379.html

http://e2e.ti.com/support/dsp/davinci_digital_media_processors/f/100/t/7826.aspx

http://e2e.ti.com/support/dsp/omap_applications_processors/f/447/p/87922/303994.aspx






1 則留言:

  1. 請問網友用什麼方式安裝opencv2.4 在beagleboard上面,原本我用Angstrom Linux提供的image檔案使用opencv,可是這版本最新只能到opencv 2.2。

    回覆刪除