2.9.2. Camera

Video can be captured on the AM62x using either a USB UVC camera or a MIPI CSI-2 compliant camera. The camera driver is based on the Video for Linux 2 (V4L2) API. Examples are given below to show video capturing by a USB camera as well as a CSI-2 camera.

2.9.2.1. USB UVC Camera

Plug in a USB UVC compliant camera and boot the EVM to Linux. Use the v4l2-ctl command to verify the camera is detected:

# v4l2-ctl --list-devices
    Video Capture 4 (usb-xhci-hcd.1.auto-1.1):
    /dev/video0
    /dev/video1
    /dev/media0

GStreamer can be used to capture the video. The captured video can be simultaneously sent to the HDMI display if a display is connected. Below is an example of using GStreamer to stream video (make sure to change videoX to the actual video device number):

# gst-launch-1.0 v4l2src device="/dev/videoX" ! video/x-raw, width=640, height=480 ! kmssink driver-name=tidss

Note

If any demo is running and using the HDMI display, it may be necessary to stop the demo before streaming:

# /etc/init.d/weston stop

The captured video can also be stored to a file and played out on the host PC. Instead of using kmssink as the GStreamer sink, a file sink can be used, for example:

# gst-launch-1.0 v4l2src num-buffers=50 device="/dev/videoX" ! video/x-raw, width=640, height=480 ! filesink location=cam-cap.yuv

Then the captured file can be played out on the host PC using an application such as mplayer:

$ mplayer -demuxer rawvideo -rawvideo w=640:h=480:format=yuy2 cam-cap.yuv

2.9.2.2. CSI-2 Camera

AM62x supports MIPI CSI-2 compliant cameras. The AM62x SK EVM has a CSI-2 camera connector that is compatible with the Raspberry Pi A & B Camera.

Connect a CSI-2 Camera to the EVM

The CSI-2 camera connector is located at the bottom side of the EVM. A CSI-2 camera can be connected to the EVM as shown below:

../_images/Academy_Eval_ov5640_am62x_sk.png

Apply Device Tree Overlay

Since any camera sensor can be connected to the EVM, the base dtb in the Processor SDK does not include the device tree node for any particular camera sensor. Therefore, the device tree node for a particular sensor should be added in as an overlay. The Processor SDK contains a pre-built device tree overlay for the OV5640 camera sensor, as shown below:

# ls /boot/*ov5640.dtbo -l
-rw-r--r-- 1 root root     2033 May  2 20:03 k3-am625-sk-csi2-ov5640.dtbo

The device tree overlay can be applied in one of the following two ways:

  1. Open file /run/media/mmcblk1p1/uEnv.txt and add the following line at the end of the file if it’s not already there, and then reboot the EVM:

name_overlays=k3-am625-sk-csi2-ov5640.dtbo
  1. Reboot the EVM and stop at U-Boot prompt, and add the following environment variable:

=>setenv name_overlays k3-am625-sk-csi2-ov5640.dtbo
=>saveenv
=>boot

Verify the Camera Is Detected

Boot the EVM to Linux and use the v4l2-ctl --list-devices command to verify the camera is detected. The command should return something similar to below:

# v4l2-ctl --list-devices
j721e-csi2rx (platform:30102000.ticsi2rx):
        /dev/video0
        /dev/video1
        /dev/video2
        /dev/video3
        /dev/media0

The above command displays multiple video nodes (/dev/videoX). Each of these video nodes corresponds to a logical stream of data. If the OV5640 camera is the only connected CSI-2 camera, then the first node under j721e-csi2rx is used.

Capture Video

The same commands used for capturing video via a USB camera, shown earlier, can be used for CSI-2 cameras as well. For example, the following command captures video and displays it through an HDMI display:

# gst-launch-1.0 v4l2src device="/dev/video0" ! video/x-raw , width=640, height=480 ! kmssink driver-name=tidss