Difference between revisions of "Template:Linux-RK3399MIPICamera"

From FriendlyELEC WiKi
Jump to: navigation, search
(updated by API)
(updated by API)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
===Work with MIPI Camera OV13850 and MIPI WDR Camera OV4689 Under Linux===
+
===Using Camera on Linux (MIPI Camera OV13850 & OV4689, and webcam logitect C920)===
 
Hardware Setting:
 
Hardware Setting:
 
The Camera module can be connected to a MIPI port:<br />
 
The Camera module can be connected to a MIPI port:<br />
Line 6: Line 6:
 
[[File:T4-mipi-single-camera.jpg|frameless|500px]]<br>
 
[[File:T4-mipi-single-camera.jpg|frameless|500px]]<br>
 
  | NanoPi-M4 =
 
  | NanoPi-M4 =
 +
[[File:M4-mipi-single-camera.jpg|frameless|500px]]<br>
 +
| NanoPi-M4V2 =
 +
[[File:M4-mipi-single-camera.jpg|frameless|500px]]<br>
 +
| NanoPi-M4B =
 
[[File:M4-mipi-single-camera.jpg|frameless|500px]]<br>
 
[[File:M4-mipi-single-camera.jpg|frameless|500px]]<br>
 
  | NanoPi-NEO4 =  
 
  | NanoPi-NEO4 =  
Line 17: Line 21:
 
-->
 
-->
  
FriendlyELEC provides a test script "gst-camera.sh" to test a camera's functions. You can run it in a commandline to test picture taking and video recording. <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:
 
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/
 
git clone https://github.com/friendlyarm/gst-camera-sh.git
 
git clone https://github.com/friendlyarm/gst-camera-sh.git
sudo cp gst-camera-sh/gst-camera.sh `which gst-camera.sh`
+
sudo cp gst-camera-sh/*.sh /usr/bin/
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
There are three scripts:<br />
 +
gst-camera.sh: preview, photo and video of a single camera <br />
 +
dual-camera.sh: preview two cameras <br />
 +
stop-gst-camera.sh: stop preview<br />
 +
<br />
 +
 
====Options in "gst-camera.sh"====
 
====Options in "gst-camera.sh"====
 
::{| class="wikitable"
 
::{| class="wikitable"
Line 38: Line 49:
 
|-
 
|-
 
| -x || Using the rkximagesink plugin, the preview image will be output to the X11 window for the FriendlyDesktop and Lubuntu systems
 
| -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
 
| -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 and OV4689 and pass the appropriate parameters to 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.
  
 
====Usage of gst-camera.sh====
 
====Usage of gst-camera.sh====
Line 51: Line 64:
 
* '''Picture Taking'''
 
* '''Picture Taking'''
 
You can run the following command to take a picture and save it as a "1.jpg" file,
 
You can run the following command to take a picture and save it as a "1.jpg" file,
::{| class="wikitable"
+
<syntaxhighlight lang="bash">
|-
+
gst-camera.sh -a photo -o 1.jpg
|Camera || Command
+
</syntaxhighlight>
|-
+
 
| OV13850 || gst-camera.sh -a photo -o 1.jpg
+
|-
+
| OV4689 || gst-camera.sh -a photo -o 1.jpg
+
|}
+
 
* '''Preview and Record'''
 
* '''Preview and Record'''
You can run the following command to preview and record video and save your video to a "1.ts" file. Hardware encoding is activated when it is recording video.
+
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
Line 72: Line 81:
 
Here is the complete gsteamer command you will see:
 
Here is the complete gsteamer command you will see:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
gst-launch-1.0 rkisp num-buffers=512 io-mode=4 path-iqf=/etc/cam_iq/${XMLFILE} \
+
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 \
+
     video/x-raw,format=NV12,width=1280,height=720,framerate=30/1 ! \
    ! tee name=t t. ! queue ! kmssink t. ! queue ! mpph264enc \
+
        mpph264enc ! queue ! h264parse ! mpegtsmux ! \
    ! queue ! h264parse ! mpegtsmux ! filesink location=1.ts
+
        filesink location=/tmp/camera-record.ts
 
</syntaxhighlight>
 
</syntaxhighlight>
The ${XMLFILE} variable may be rk-ov13850.xml or rk-ov4689.xml, depending on the camera model you are connected to.
 
  
====gst-launch-1.0 parameter description====
+
* '''Preview dual camera'''
Preview ov13850 camera on FriendlyDesktop:
+
Connect two mipi cameras, or one mipi camera and one usb camera (tested only: Logitech C920 pro), call the following command:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
gst-launch-1.0 rkisp device=/dev/video0 sensor-id=1 io-mode=4 path-iqf=/etc/cam_iq/rk-rk-ov13850.xml ! video/x-raw,format=NV12,width=1280,height=720,framerate=30/1 ! rkximagesink
+
dual-camera.sh
 
</syntaxhighlight>
 
</syntaxhighlight>
Preview ov4689 camera on FriendlyDesktop:
+
Note: It is recommended to test this on FriendlyDesktop.
 +
 
 +
====gst-launch-1.0 parameter description====
 +
Preview camera on FriendlyDesktop:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
gst-launch-1.0 rkisp device=/dev/video0 sensor-id=1 io-mode=4 path-iqf=/etc/cam_iq/rk-ov4689.xml ! 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
 
Important parameters
Line 93: Line 104:
 
|parameter || description
 
|parameter || description
 
|-
 
|-
| device || If only one camera is connected, no matter which CSI interface is connected, the device (selfpath) used for preview is /dev/video0, and the device (mainpath) used for photographing is /dev/video2, if 2 cameras are connected at the same time. The camera nodes corresponding to the CSI1 interface are /dev/video0 and /dev/video2, and CSI2 corresponds to /dev/video4 and /dev/video6, Note: When taking pictures, io-mode needs to be specified as 1.
+
| device || preview device(selfpath): /dev/video1 and /dev/video5, picture device(mainpath): /dev/video0 and /dev/video4, webcam device: /dev/video8
 
|-
 
|-
| sensor-id || If only one camera is connected, the sensor-id is 1 regardless of which CSI interface is connected. If two cameras are connected at the same time, the camera of the CSI1 interface is 1, and the camera of the CSI2 interface is 5.
+
| io-mode || 1: memory map, 4:dmabuf
 
|-
 
|-
| path-iqf || Specify the camera's tuning xml file. When the camera is OV4689, you need to specify /etc/cam_iq/rk-ov4689.xml. When the camera is OV13850, you need to specify /etc/cam_iq/rk-rk-ov13850.xml.
+
| rkximagesink/glimagesink/kmssink || rkximagesink for FriendlyDesktop, kmssink for FriendlyCore, glimagesink for webcam on FriendlyDesktop
|-
+
| rkximagesink or kmssink || rkximagesink for FriendlyDesktop, will display on X11 window, kmssink for FriendlyCore, directly display on the screen
+
 
|}
 
|}
 +
 +
====Access the camera in OpenCV====
 +
MIPI camera:
 +
<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 camera:
 +
<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 />
 +
Please refer to the sample code here for details:https://github.com/friendlyarm/install-opencv-on-friendlycore/tree/rk3399/examples<br />
 +
<br />
  
 
====Camera application tutorial: Push video stream====
 
====Camera application tutorial: Push video stream====
Please refre this guide: [[RTMP-For-RK3399]]<br />
+
Please refre this guide: [[How to setup RTMP server on NanoPC-T4]]<br />
  
 
====Reference resource====
 
====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

Latest revision as of 06:35, 27 November 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
  • Preview dual camera

Connect two mipi cameras, or one mipi camera and one usb camera (tested only: Logitech C920 pro), call the following command:

dual-camera.sh

Note: It is recommended to test this on FriendlyDesktop.

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: How to setup RTMP server on NanoPC-T4

1.6 Reference resource

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