Rock 4 SE + OV5647 Camera

It has taken me weeks to get a Rock 4 SE + OV5647 Camera working. It seems none of the documentation out there provide a clear or working set of steps, using the latest kernel and latest OS.

This post was going to be to ask for help, but I finally have something basic that works, so I thought I’d share it for anyone else interested and ask for comments. Would this make useful documentation? How could the approach be improved?

My set up is using a Rock 4 SE and a 5M Camera (OV5647 sensor). I have:

  1. Installed rockpi4-debian-stretch-desktop-arm64-20190730_2022-gpt
  2. Ran, $ rsetup > Overlays > Manage Overlays > Enable OKdo 5MP Camera
  3. Rebooted
  4. Installed v4l2-utils
    sudo apt-get update
    sudo apt-get install v4l-utils
    

List the video devices:

v4l2-ctl --list-devices
rkisp1-statistics (platform: rkisp1):
	/dev/video3
	/dev/video4

rkisp1_mainpath (platform:ff910000.rkisp1):
	/dev/video0
	/dev/video1
	/dev/video2

rkisp1 (platform:rkisp1):
	/dev/media0

List formats of /dev/video0:

v4l2-ctl -d /dev/video0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
	Type: Video Capture Multiplanar

	[0]: 'YUYV' (YUYV 4:2:2)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[1]: '422P' (Planar YUV 4:2:2)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[2]: 'NV16' (Y/CbCr 4:2:2)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[3]: 'NV61' (Y/CrCb 4:2:2)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[4]: 'YM16' (Planar YUV 4:2:2 (N-C))
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[5]: 'NV21' (Y/CrCb 4:2:0)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[6]: 'NV12' (Y/CbCr 4:2:0)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[7]: 'NM21' (Y/CrCb 4:2:0 (N-C))
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[8]: 'NM12' (Y/CbCr 4:2:0 (N-C))
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[9]: 'YU12' (Planar YUV 4:2:0)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[10]: 'YM24' (Planar YUV 4:4:4 (N-C))
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[11]: 'RGGB' (8-bit Bayer RGRG/GBGB)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[12]: 'GRBG' (8-bit Bayer GRGR/BGBG)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[13]: 'GBRG' (8-bit Bayer GBGB/RGRG)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[14]: 'BA81' (8-bit Bayer BGBG/GRGR)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[15]: 'RG10' (10-bit Bayer RGRG/GBGB)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[16]: 'BA10' (10-bit Bayer GRGR/BGBG)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[17]: 'GB10' (10-bit Bayer GBGB/RGRG)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[18]: 'BG10' (10-bit Bayer BGBG/GRGR)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[19]: 'RG12' (12-bit Bayer RGRG/GBGB)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[20]: 'BA12' (12-bit Bayer GRGR/BGBG)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[21]: 'GB12' (12-bit Bayer GBGB/RGRG)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8
	[22]: 'BG12' (12-bit Bayer BGBG/GRGR)
		Size: Stepwise 32x16 - 2592x1944 with step 8/8

Get the format details of device video0, format 0

v4l2-ctl --verbose -d /dev/video0 --get-fmt-video
VIDIOC_QUERYCAP: ok
VIDIOC_G_FMT: ok
Format Video Capture Multiplanar:
	Width/Height      : 2592/1944
	Pixel Format      : 'YUYV' (YUYV 4:2:2)
	Field             : None
	Number of planes  : 1
	Flags             :
	Colorspace        : sRGB
	Transfer Function : Rec. 709
	YCbCr/HSV Encoding: Rec. 709
	Quantization      : Full Range
	Plane 0           :
	   Bytes per Line : 5184
	   Size Image     : 10077696

List controls for /dev/video0

v4l2-ctl -d /dev/video0 -l
#or
v4l2-ctl --all

User Controls

        white_balance_automatic 0x0098090c (bool)   : default=0 value=0
                       exposure 0x00980911 (int)    : min=4 max=1964 step=1 default=1000 value=886
                 gain_automatic 0x00980912 (bool)   : default=0 value=0
                horizontal_flip 0x00980914 (bool)   : default=0 value=0 flags=modify-layout
                  vertical_flip 0x00980915 (bool)   : default=0 value=0 flags=modify-layout

Camera Controls

                  auto_exposure 0x009a0901 (menu)   : min=0 max=1 default=1 value=0
				0: Auto Mode
				1: Manual Mode

Turn auto exposure on

v4l2-ctl -d /dev/video0 -c auto_exposure=0

Capture a still

This includes capturing as yuyv and swabing to uyvy which is supported by image magic convert, the converting to png. It also includes skipping three frames, which improves the exposure for some crazy reason.

v4l2-ctl -d /dev/video0 --set-fmt-video=width=2592,height=1944,pixelformat=YUYV --stream-mmap=3 --stream-skip=3 --stream-count=1 --stream-to=test.yuyv
dd if=test.yuyv conv=swab > test.uyvy
convert -sampling-factor 4:2:2 -size 2592x1944 -depth 8 test.uyvy  test.png
1 Like