Difference between revisions of "APITestPage"

From FriendlyELEC WiKi
Jump to: navigation, search
(updated by API)
(updated by API)
 
(164 intermediate revisions by the same user not shown)
Line 1: Line 1:
===Linux下使用摄像头(MIPI接口摄像头OV13850与OV4689,USB摄像头罗技C920)===
 
摄像头连接方法:
 
摄像头可以连接在MIPI接口,如下图所示:<br />
 
{{#switch: {{{1}}}
 
| NanoPC-T4 =
 
[[File:T4-mipi-single-camera.jpg|frameless|600px]]<br>
 
| NanoPi-M4 =
 
[[File:M4-mipi-single-camera.jpg|frameless|600px]]<br>
 
| NanoPi-NEO4 =
 
[[File:Neo4-mipi-single-camera.jpg|frameless|600px]]<br>
 
| #default =
 
}}
 
  
<!--
+
{{RockchipUnbrick|NanoPC-T4}}
M4-mipi-dual-camera.jpg
+
T4-mipi-dual-camera.jpg
+
-->
+
 
+
为了方便测试摄像头,我们提供了脚本可以在命令行测试摄像头的拍照和录像功能。<br />
+
你可以用以下命令更新这个脚本到最新版本:
+
<syntaxhighlight lang="bash">
+
cd /tmp/
+
git clone https://github.com/friendlyarm/gst-camera-sh.git
+
sudo cp gst-camera-sh/*.sh /usr/bin/
+
</syntaxhighlight>
+
 
+
共有以下三个脚本:<br />
+
gst-camera.sh: 单个摄像头的预览、拍照与录像 <br />
+
dual-camera.sh: 预览两个摄像头 <br />
+
stop-gst-camera.sh: 停止预览<br />
+
<br />
+
====gst-camera.sh 参数说明====
+
::{| class="wikitable"
+
|-
+
|参数 || 功能
+
|-
+
|  --index或-i || 选择要使用的摄像头的序号,可选值为0和1,当同时连接两个摄像头时,指定为1表示要操作第二个摄像头
+
|-
+
|  --action或-a || 指定命令要执行的动作,可选参数为: preview、photo和video,分别对应预览、拍照和录像
+
|-
+
|  --output或-o || 指定输出的文件名,用于拍照和录像时指定输出文件名
+
|-
+
|  --verbose或-v || 指定为yes时,会输出调用gst-launch-1.0命令的完整命令行
+
|-
+
|  -x || 使用rkximagesink插件,预览图像会输出到X11窗口,适用于FriendlyDesktop与Lubuntu系统
+
|-
+
|  -g || 使用glimagesink插件,预览图像会输出到X11窗口,适用于FriendlyDesktop与Lubuntu系统
+
|-
+
|  -k || 使用kmssink插件,预览图像会直接输出到屏幕,适用于FriendlyCore系统
+
|}
+
 
+
脚本gst-camera.sh会自动识别OV13850/OV4689/罗技C920摄像头,并传递合适的参数给gst-launch-1.0。
+
 
+
====gst-camera.sh 使用方法====
+
* '''预览图像'''
+
<syntaxhighlight lang="bash">
+
gst-camera.sh --action preview
+
</syntaxhighlight>
+
* '''拍照'''
+
用命令拍照一张照片,存储为文件 1.jpg:
+
<syntaxhighlight lang="bash">
+
gst-camera.sh -a photo -o 1.jpg
+
</syntaxhighlight>
+
 
+
* '''录像并预览'''
+
用以下命令启动录像,存储为视频文件 1.ts,录像时使用了硬件编码:
+
<syntaxhighlight lang="bash">
+
gst-camera.sh --action video -output 1.ts
+
</syntaxhighlight>
+
<br />
+
* '''显示完整的命令'''
+
加入 --verbose yes 的参数,会显示最终的 gsteamer 命令,例如:
+
<syntaxhighlight lang="bash">
+
gst-camera.sh --action video --output 1.ts --verbose yes
+
</syntaxhighlight>
+
你会得到以下完整的 gsteamer 命令,这对你开发会有帮助:
+
<syntaxhighlight lang="bash">
+
gst-launch-1.0 rkisp num-buffers=512 device=/dev/video0 io-mode=1 ! \
+
    video/x-raw,format=NV12,width=1280,height=720,framerate=30/1 ! \
+
        mpph264enc ! queue ! h264parse ! mpegtsmux ! \
+
        filesink location=/tmp/camera-record.ts
+
</syntaxhighlight>
+
 
+
====gst-launch-1.0命令行解析====
+
在FriendlyDesktop下预览摄像头命令如下:
+
<syntaxhighlight lang="bash">
+
gst-launch-1.0 rkisp device=/dev/video1 io-mode=4 ! video/x-raw,format=NV12,width=1280,height=720,framerate=30/1 ! rkximagesink
+
</syntaxhighlight>
+
重要参数说明:
+
::{| class="wikitable"
+
|-
+
|参数 || 说明
+
|-
+
| device || 用于预览的device (selfpath) 是 /dev/video1, 用于拍照的device (mainpath) 是 /dev/video0, 如果是多路摄像头,则另一路预览(selfpath)是 /dev/video5, 另一路拍照 (mainpath)是 /dev/video4, USB摄像头一般都是 /dev/video8
+
|-
+
| io-mode || 值为1表示是memory map模式,值为4表示是dmabuf模式,一般预览用io-mode=4,拍照用io-mode=1, 在OpenCV里访问用io-mode=4
+
|-
+
| rkximagesink/glimagesink/kmssink || 在X-Windows窗口中输出mipi摄像头图像时指定为rkximagesink (适用于FriendlyDesktop),如果是USB摄像头则指定为glimagesink,FriendlyCore下只能使用kmssink
+
|}
+
 
+
====在OpenCV中访问摄像头====
+
访问MIPI摄像头:
+
<syntaxhighlight lang="python">
+
cv.VideoCapture('rkisp device=/dev/video1 io-mode=4 ! video/x-raw,format=NV12,width=640,height=480,framerate=30/1 ! videoconvert ! appsink', cv.CAP_GSTREAMER)
+
</syntaxhighlight>
+
访问USB摄像头:
+
<syntaxhighlight lang="python">
+
cv.VideoCapture('rkisp device=/dev/video8 io-mode=4 ! videoconvert ! video/x-raw,format=NV12,width=640,height=480,framerate=30/1 ! videoconvert ! appsink', cv.CAP_GSTREAMER)
+
</syntaxhighlight>
+
<br />
+
详情请参考这里的示例代码:https://github.com/friendlyarm/install-opencv-on-friendlycore/tree/rk3399/examples<br />
+
<br />
+
====摄像头应用教程: 推流至直播平台====
+
请查看这篇文档: [[RTMP-For-RK3399/zh]]<br />
+
 
+
====参考资源====
+
http://blog.iotwrt.com/media/2017/10/01/camera/
+
http://www.360doc.com/content/16/1019/17/496343_599664458.shtml
+

Latest revision as of 09:23, 4 June 2024

1 Unbricking Method

If the ROM is not installed correctly, causing the development board to become bricked, and you might not have the opportunity to reinstall the ROM via an SD card, you need to enter Maskrom mode to unbrick it by erasing the storage device.

1.1 Windows Users

1.1.1 Download Required Files

  • Get the necessary tools: Visit here, find RKDevTool_v3.19_for_window.zip and DriverAssitant_v5.12.zip in the 05_Tools directory, and download them to your local machine.
  • Install Rockchip USB driver and RKDevTool: Extract DriverAssitant_v5.12.zip to install the Rockchip USB driver, and extract RKDevTool_v3.19_for_window.zip to obtain the Rockchip flashing tool RKDevTool.
  • Get the loader: Visit here, enter the tools directory corresponding to your CPU model, and download MiniLoaderAll.bin.

1.1.2 Enter Maskrom Mode to Erase the Storage Device

  • Connect NanoPC-T4 to your computer using a USB data cable.
  • Start RKDevTool on your computer.
  • Disconnect the power from NanoPC-T4, hold down the MASK button, connect the power, and release the button when you see Found One MASKROM Device displayed at the bottom of the interface, as shown below:

Rkdevtool found one maskrom device.png

  • Click the Advanced Function tab in the RKDevTool interface.
  • In the Boot text box, select MiniLoaderAll.bin, then click the Download button.
  • Select EMMC, click Switch Storage, then click the EraseAll button to erase the eMMC.

Rkdevtool erase emmc.png

  • At this point, NanoPC-T4 is restored to its initial state and can be normally booted via SD card or eMMC.

1.2 Linux/Mac Users

1.2.1 Download the Required Files

  • Get the necessary tools: Visit here and find upgrade_tool_v2.30_for_linux.tgz (or for Mac users, select upgrade_tool_v2.25_for_mac.tgz) in the 05_Tools directory and download it locally.
  • Get the loader: Visit here, enter the tools directory corresponding to your CPU model, and download MiniLoaderAll.bin.

1.2.2 Installation for upgrade_tool

The following commands are for Linux, with only slight differences in file and directory names for Mac users:

tar xzf upgrade_tool_v2.30_for_linux.tgz
cd upgrade_tool_v2.30_for_linux
sudo cp upgrade_tool /usr/local/sbin/
sudo chmod 755 /usr/local/sbin/upgrade_tool

1.2.3 Enter Maskrom Mode to Erase the Storage Device

  • Connect NanoPC-T4 to the computer using a USB data cable.
  • Disconnect the power from NanoPC-T4, hold down the MASK button, connect the power, and release the button after 4 seconds.
  • Check the connection with the following command:
upgrade_tool LD

A result similar to "DevNo=1 Vid=0x2207,Pid=0x350b,LocationID=13 Mode=Maskrom SerialNo=" indicates that the device has been detected.

  • Erase the eMMC with the following command:
upgrade_tool EF MiniLoaderAll.bin
  • At this point, NanoPC-T4 has been restored to its initial state and can boot the system normally via SD card or eMMC.