Difference between revisions of "APITestPage"

From FriendlyELEC WiKi
Jump to: navigation, search
(updated by API)
(updated by API)
 
(163 intermediate revisions by the same user not shown)
Line 1: Line 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:<br />
 
{{#switch: {{{1}}}
 
| NanoPC-T4 =
 
[[File:T4-mipi-single-camera.jpg|frameless|500px]]<br>
 
| NanoPi-M4 =
 
[[File:M4-mipi-single-camera.jpg|frameless|500px]]<br>
 
| NanoPi-NEO4 =
 
[[File:Neo4-mipi-single-camera.jpg|frameless|500px]]<br>
 
| #default =
 
}}
 
  
<!--
+
{{RockchipUnbrick|NanoPC-T4}}
M4-mipi-dual-camera.jpg
+
T4-mipi-dual-camera.jpg
+
-->
+
 
+
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">
+
cd /tmp/
+
git clone https://github.com/friendlyarm/gst-camera-sh.git
+
sudo cp gst-camera-sh/*.sh /usr/bin/
+
</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"====
+
::{| class="wikitable"
+
|-
+
|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.
+
 
+
====Usage of gst-camera.sh====
+
* '''Preview'''
+
<syntaxhighlight lang="bash">
+
gst-camera.sh --action preview
+
</syntaxhighlight>
+
* '''Picture Taking'''
+
You can run the following command to take a picture and save it as a "1.jpg" file,
+
<syntaxhighlight lang="bash">
+
gst-camera.sh -a photo -o 1.jpg
+
</syntaxhighlight>
+
 
+
* '''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.
+
<syntaxhighlight lang="bash">
+
gst-camera.sh --action video -output 1.ts
+
</syntaxhighlight>
+
<br />
+
* '''Show Complete Command'''
+
If you add the "--verbose yes" option it will show a complete gsteamer command.
+
<syntaxhighlight lang="bash">
+
gst-camera.sh --action video --output 1.ts --verbose yes
+
</syntaxhighlight>
+
Here is the complete gsteamer command you will see:
+
<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 parameter description====
+
Preview camera on 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>
+
Important parameters
+
::{| class="wikitable"
+
|-
+
|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
+
|}
+
 
+
====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====
+
Please refre this guide: [[RTMP-For-RK3399]]<br />
+
 
+
====Reference resource====
+
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.