Difference between revisions of "APITestPage"

From FriendlyELEC WiKi
Jump to: navigation, search
(updated by API)
(updated by API)
Line 1: Line 1:
===Linux下使用摄像头(MIPI接口摄像头OV13850与OV4689,USB摄像头罗技C920)===
+
===Using Camera on Linux (MIPI Camera OV13850 & OV4689, and webcam logitect C920)===
摄像头连接方法:
+
Hardware Setting:
摄像头可以连接在MIPI接口,如下图所示:<br />
+
The Camera module can be connected to a MIPI port:<br />
 
{{#switch: {{{1}}}
 
{{#switch: {{{1}}}
 
  | NanoPC-T4 =
 
  | NanoPC-T4 =
[[File:T4-mipi-single-camera.jpg|frameless|600px]]<br>
+
[[File:T4-mipi-single-camera.jpg|frameless|500px]]<br>
 
  | NanoPi-M4 =
 
  | NanoPi-M4 =
[[File:M4-mipi-single-camera.jpg|frameless|600px]]<br>
+
[[File:M4-mipi-single-camera.jpg|frameless|500px]]<br>
 
  | NanoPi-NEO4 =  
 
  | NanoPi-NEO4 =  
[[File:Neo4-mipi-single-camera.jpg|frameless|600px]]<br>
+
[[File:Neo4-mipi-single-camera.jpg|frameless|500px]]<br>
 
  | #default =
 
  | #default =
 
}}
 
}}
Line 17: Line 17:
 
-->
 
-->
  
为了方便测试摄像头,我们提供了脚本可以在命令行测试摄像头的拍照和录像功能。<br />
+
FriendlyELEC provides some scripts use to test a camera's functions. You can run it in a commandline to test picture taking and video recording. <br />
你可以用以下命令更新这个脚本到最新版本:
+
You may try update this script to the lastest version by using the following commands:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
cd /tmp/
 
cd /tmp/
Line 25: Line 25:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
共有以下三个脚本:<br />
+
There are three scripts:<br />
gst-camera.sh: 单个摄像头的预览、拍照与录像 <br />
+
gst-camera.sh: preview, photo and video of a single camera <br />
dual-camera.sh: 预览两个摄像头 <br />
+
dual-camera.sh: preview two cameras <br />
stop-gst-camera.sh: 停止预览<br />
+
stop-gst-camera.sh: stop preview<br />
 
<br />
 
<br />
====gst-camera.sh 参数说明====
+
 
 +
====Options in "gst-camera.sh"====
 
::{| class="wikitable"
 
::{| class="wikitable"
 
|-
 
|-
|参数 || 功能
+
|Options || Comment
 
|-
 
|-
|  --index或-i || 选择要使用的摄像头的序号,可选值为0和1,当同时连接两个摄像头时,指定为1表示要操作第二个摄像头
+
|  --index or -i || Camera's index, it can be either 0 or 1. When two cameras are connected to a board you need to specify 1 to access the second camera.
 
|-
 
|-
|  --action或-a || 指定命令要执行的动作,可选参数为: preview、photo和video,分别对应预览、拍照和录像
+
|  --action or -a || Specify an action, it can be "preview" to preview, "photo" to take a picture or "video" to record video
 
|-
 
|-
|  --output或-o || 指定输出的文件名,用于拍照和录像时指定输出文件名
+
|  --output or -o || Specify an output file to save a picture when taking a picture or video file when recording video
 
|-
 
|-
|  --verbose或-v || 指定为yes时,会输出调用gst-launch-1.0命令的完整命令行
+
|  --verbose or -v || If it is specified as "yes" it will output the complete command when "gst-launch-1.0" is called
 
|-
 
|-
| -x || 使用rkximagesink插件,预览图像会输出到X11窗口,适用于FriendlyDesktop与Lubuntu系统
+
| -x || Using the rkximagesink plugin, the preview image will be output to the X11 window for the FriendlyDesktop and Lubuntu systems
 
|-
 
|-
|  -g || 使用glimagesink插件,预览图像会输出到X11窗口,适用于FriendlyDesktop与Lubuntu系统
+
|  -g || Using the glimagesink plugin, the preview image will be output to the X11 window for the FriendlyDesktop and Lubuntu systems
 
|-
 
|-
| -k || 使用kmssink插件,预览图像会直接输出到屏幕,适用于FriendlyCore系统
+
| -k || Using the kmssink plugin, the preview image will be output directly to the screen for the FriendlyCore system
 
|}
 
|}
  
脚本gst-camera.sh会自动识别OV13850/OV4689/罗技C920摄像头,并传递合适的参数给gst-launch-1.0。
+
The script gst-camera.sh will automatically recognize OV13850, OV4689 and C920 camera,  and then pass the appropriate parameters to gst-launch-1.0.
  
====gst-camera.sh 使用方法====
+
====Usage of gst-camera.sh====
* '''预览图像'''
+
* '''Preview'''
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
gst-camera.sh --action preview
 
gst-camera.sh --action preview
 
</syntaxhighlight>
 
</syntaxhighlight>
* '''拍照'''
+
* '''Picture Taking'''
用命令拍照一张照片,存储为文件 1.jpg:
+
You can run the following command to take a picture and save it as a "1.jpg" file,
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
gst-camera.sh -a photo -o 1.jpg
 
gst-camera.sh -a photo -o 1.jpg
 
</syntaxhighlight>
 
</syntaxhighlight>
  
* '''录像并预览'''
+
* '''Preview and Record'''
用以下命令启动录像,存储为视频文件 1.ts,录像时使用了硬件编码:
+
You can run the following command to record video and save your video to a "1.ts" file. Hardware encoding is activated when it is recording video.
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
gst-camera.sh --action video -output 1.ts
 
gst-camera.sh --action video -output 1.ts
 
</syntaxhighlight>
 
</syntaxhighlight>
 
<br />
 
<br />
* '''显示完整的命令'''
+
* '''Show Complete Command'''
加入 --verbose yes 的参数,会显示最终的 gsteamer 命令,例如:
+
If you add the "--verbose yes" option it will show a complete gsteamer command.
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
gst-camera.sh --action video --output 1.ts --verbose yes
 
gst-camera.sh --action video --output 1.ts --verbose yes
 
</syntaxhighlight>
 
</syntaxhighlight>
你会得到以下完整的 gsteamer 命令,这对你开发会有帮助:
+
Here is the complete gsteamer command you will see:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
gst-launch-1.0 rkisp num-buffers=512 device=/dev/video0 io-mode=1 ! \
 
gst-launch-1.0 rkisp num-buffers=512 device=/dev/video0 io-mode=1 ! \
Line 82: Line 83:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
====gst-launch-1.0命令行解析====
+
====gst-launch-1.0 parameter description====
在FriendlyDesktop下预览摄像头命令如下:
+
Preview camera on FriendlyDesktop:
 
<syntaxhighlight lang="bash">
 
<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
 
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>
 
</syntaxhighlight>
重要参数说明:
+
Important parameters
 
::{| class="wikitable"
 
::{| class="wikitable"
 
|-
 
|-
|参数 || 说明
+
|parameter || description
 
|-
 
|-
| device || 用于预览的device (selfpath) /dev/video1, 用于拍照的device (mainpath) /dev/video0, 如果是多路摄像头,则另一路预览(selfpath)是 /dev/video5, 另一路拍照 (mainpath)是 /dev/video4, USB摄像头一般都是 /dev/video8
+
| device || preview device(selfpath): /dev/video1 and /dev/video5, picture device(mainpath): /dev/video0 and /dev/video4, webcam device: /dev/video8
 
|-
 
|-
| io-mode || 值为1表示是memory map模式,值为4表示是dmabuf模式,一般预览用io-mode=4,拍照用io-mode=1, 在OpenCV里访问用io-mode=4
+
| io-mode || 1: memory map, 4:dmabuf
 
|-
 
|-
| rkximagesink/glimagesink/kmssink || 在X-Windows窗口中输出mipi摄像头图像时指定为rkximagesink (适用于FriendlyDesktop),如果是USB摄像头则指定为glimagesink,FriendlyCore下只能使用kmssink
+
| rkximagesink/glimagesink/kmssink || rkximagesink for FriendlyDesktop, kmssink for FriendlyCore, glimagesink for webcam on FriendlyDesktop
 
|}
 
|}
  
====在OpenCV中访问摄像头====
+
====Access the camera in OpenCV====
访问MIPI摄像头:
+
MIPI camera:
 
<syntaxhighlight lang="python">
 
<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)
 
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>
 
</syntaxhighlight>
访问USB摄像头:
+
USB camera:
 
<syntaxhighlight lang="python">
 
<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)
 
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>
 
</syntaxhighlight>
 
<br />
 
<br />
详情请参考这里的示例代码:https://github.com/friendlyarm/install-opencv-on-friendlycore/tree/rk3399/examples<br />
+
Please refer to the sample code here for details:https://github.com/friendlyarm/install-opencv-on-friendlycore/tree/rk3399/examples<br />
 
<br />
 
<br />
====摄像头应用教程: 推流至直播平台====
 
请查看这篇文档: [[RTMP-For-RK3399/zh]]<br />
 
  
====参考资源====
+
====Camera application tutorial: Push video stream====
 +
Please refre this guide: [[RTMP-For-RK3399]]<br />
 +
 
 +
====Reference resource====
 
http://blog.iotwrt.com/media/2017/10/01/camera/
 
http://blog.iotwrt.com/media/2017/10/01/camera/
 
http://www.360doc.com/content/16/1019/17/496343_599664458.shtml
 
http://www.360doc.com/content/16/1019/17/496343_599664458.shtml

Revision as of 08:42, 14 May 2019

1 Using Camera on Linux (MIPI Camera OV13850 & OV4689, and webcam logitect C920)

Hardware Setting: The Camera module can be connected to a MIPI port:


FriendlyELEC provides some scripts use to test a camera's functions. You can run it in a commandline to test picture taking and video recording.
You may try update this script to the lastest version by using the following commands:

cd /tmp/
git clone https://github.com/friendlyarm/gst-camera-sh.git
sudo cp gst-camera-sh/*.sh /usr/bin/

There are three scripts:
gst-camera.sh: preview, photo and video of a single camera
dual-camera.sh: preview two cameras
stop-gst-camera.sh: stop preview

1.1 Options in "gst-camera.sh"

Options Comment
--index or -i Camera's index, it can be either 0 or 1. When two cameras are connected to a board you need to specify 1 to access the second camera.
--action or -a Specify an action, it can be "preview" to preview, "photo" to take a picture or "video" to record video
--output or -o Specify an output file to save a picture when taking a picture or video file when recording video
--verbose or -v If it is specified as "yes" it will output the complete command when "gst-launch-1.0" is called
-x Using the rkximagesink plugin, the preview image will be output to the X11 window for the FriendlyDesktop and Lubuntu systems
-g Using the glimagesink plugin, the preview image will be output to the X11 window for the FriendlyDesktop and Lubuntu systems
-k Using the kmssink plugin, the preview image will be output directly to the screen for the FriendlyCore system

The script gst-camera.sh will automatically recognize OV13850, OV4689 and C920 camera, and then pass the appropriate parameters to gst-launch-1.0.

1.2 Usage of gst-camera.sh

  • Preview
gst-camera.sh --action preview
  • Picture Taking

You can run the following command to take a picture and save it as a "1.jpg" file,

gst-camera.sh -a photo -o 1.jpg
  • Preview and Record

You can run the following command to record video and save your video to a "1.ts" file. Hardware encoding is activated when it is recording video.

gst-camera.sh --action video -output 1.ts


  • Show Complete Command

If you add the "--verbose yes" option it will show a complete gsteamer command.

gst-camera.sh --action video --output 1.ts --verbose yes

Here is the complete gsteamer command you will see:

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

1.3 gst-launch-1.0 parameter description

Preview camera on FriendlyDesktop:

gst-launch-1.0 rkisp device=/dev/video1 io-mode=4 ! video/x-raw,format=NV12,width=1280,height=720,framerate=30/1 ! rkximagesink

Important parameters

parameter description
device preview device(selfpath): /dev/video1 and /dev/video5, picture device(mainpath): /dev/video0 and /dev/video4, webcam device: /dev/video8
io-mode 1: memory map, 4:dmabuf
rkximagesink/glimagesink/kmssink rkximagesink for FriendlyDesktop, kmssink for FriendlyCore, glimagesink for webcam on FriendlyDesktop

1.4 Access the camera in OpenCV

MIPI camera:

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)

USB camera:

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)


Please refer to the sample code here for details:https://github.com/friendlyarm/install-opencv-on-friendlycore/tree/rk3399/examples

1.5 Camera application tutorial: Push video stream

Please refre this guide: RTMP-For-RK3399

1.6 Reference resource

http://blog.iotwrt.com/media/2017/10/01/camera/ http://www.360doc.com/content/16/1019/17/496343_599664458.shtml