Skip to main content

Camera Object

The Camera object is used to implement image capture and processing functions for MIPI cameras. It includes several methods such as open_cam, open_vps, get_img, set_img, and close_cam. Detailed descriptions are provided below:

open_cam

【Function Description】

Opens the MIPI camera on the specified channel and configures the camera's output frame rate and resolution format.

【Function Declaration】
Camera.open_cam(pipe_id, video_index, fps, width, height, raw_height, raw_width)
【Parameter Description】
Parameter NameDescriptionValue Range
pipe_idPipeline channel ID corresponding to the cameraStarts from 0 by default; range: 0–7
video_indexHost ID corresponding to the camera; -1 indicates auto-detectionValues: -1, 0, 1, 2 (see "Host ID Selection" section for details)
fpsCamera output frame rateDepends on camera model; default: 30
widthFinal output image width of the cameraDepends on camera model; default: 1920
heightFinal output image height of the cameraDepends on camera model; default: 1080
raw_heightOriginal RAW image output height of the cameraDepends on camera model; default: 1920
raw_widthOriginal RAW image output width of the cameraDepends on camera model; default: 1080
【Usage】
#create camera object
camera = libsrcampy.Camera()

#open MIPI Camera, fps: 30, solution: 1080p
ret = camera.open_cam(0, -1, 30, 1920, 1080)
【Return Value】
Return ValueDescription
0Success
-1Failure
【Notes】

The parameters width and height support input of type list, which enables the camera to output multiple resolutions simultaneously. The list supports up to 6 scaled-down outputs, with scaling ratios in the range [1, 1/64) relative to the camera’s native resolution. Example usage:

ret = cam.open_cam(0, -1, 30, [1920, 1280], [1080, 720])

The parameters raw_height and raw_width should only be set when the camera does not use its default resolution. For example, when using an IMX477 camera and wishing to output both 4K (3840×2160) and 1080P (1920×1080) simultaneously, you can use:

cam.open_cam(0, -1, 10, [3840, 1920], [2160, 1080], 3000, 4000)

Currently supported camera resolutions are listed below:

CameraResolution
IMX2191920x1080@30fps (default)
Note!

Switching the IMX477 camera from 1080P resolution to another resolution requires a manual reset. You can perform this reset on the board by running hobot_reset_camera.py.

Note!

The S100 chip has alignment requirements for VPS output:

  • Output width must be aligned to 16 bytes.
  • Output height must be aligned to 2 bytes.

If your configured width or height does not meet these alignment requirements, an error will be reported.

【Reference Code】

None

open_vps

【Function Description】

Enables the VPS (Video Processing System) image processing functionality for the specified camera channel, supporting operations such as scaling and cropping on the input image.

【Function Declaration】
Camera.open_vps(pipe_id, proc_mode, src_width, src_height, dst_width, dst_height, crop_rect, rotate, src_size, dst_size)
【Parameter Description】
Parameter NameDescriptionValue Range
pipe_idPipeline channel ID corresponding to the cameraStarts from 0 by default; range: 0–7
proc_modeImage processing mode (supports scaling, cropping + scaling)Values 1–4: scaling, cropping + scaling
src_widthInput image widthDepends on camera output width
src_heightInput image heightDepends on camera output height
dst_widthOutput image width[1, 1/64) × input width
dst_heightOutput image height[1, 1/64) × input height
crop_rectCropping region dimensions in format [x, y]Must not exceed input image dimensions
rotateRotation angle (currently unsupported; max two channels support rotation)Values 0–3: no rotation, 90°, 180°, 270°
src_sizeReserved parameterNot required by default
dst_sizeReserved parameterNot required by default
【Usage】
#create camera object
camera = libsrcampy.Camera()

#enable vps function
ret = camera.open_vps(1, 1, 1920, 1080, 512, 512)
【Return Value】
Return ValueDescription
0Success
-1Failure
Note!
  • VPS supports up to 6 output channels and only downscaling. Scaling ratio range: [1, 1/64). Multi-channel configurations are passed via list parameters.
  • Image cropping uses the top-left corner as the origin and crops according to the specified dimensions.
  • Cropping is applied before scaling and rotation. Multi-channel configurations are passed via list parameters.
Note!

The S100 chip has alignment requirements for VPS output:

  • Output width must be aligned to 16 bytes.
  • Output height must be aligned to 2 bytes.

If your configured width or height does not meet these alignment requirements, an error will be reported.

#creat camera object
camera = libsrcampy.Camera()

#enable vps function
#input: 4k, output0: 1080p, output1: 720p
#ouput0 croped by [2560, 1440]
ret = camera.open_vps(0, 1, 3840, 2160, [1920, 1280], [1080, 720], [2560, 1440])

【Reference Code】
None

get_img

【Function Description】

Retrieves the image output from the camera object. This method must be called after open_cam or open_vps.

【Function Declaration】
Camera.get_img(module, width, height)
【Parameter Description】
Parameter NameDescriptionValue Range
moduleModule from which to retrieve the imageDefault: 2
widthWidth of the image to retrieveMust match the output width configured in open_cam or open_vps
heightHeight of the image to retrieveMust match the output height configured in open_cam or open_vps
【Usage】
cam = libsrcampy.Camera()

#open MIPI Camera, fps: 30, solution: 1080p
ret = cam.open_cam(0, 1, 30, 1920, 1080)

#wait for 1s
time.sleep(1)

#get one image from camera
img = cam.get_img(2)
【Return Value】
Return ValueDescription
0Success
-1Failure

【Notes】 This method must be called after open_cam or open_vps.

【Reference Code】
import sys, os, time

from hobot_vio import libsrcampy

def test_camera():
cam = libsrcampy.Camera()

# open MIPI camera, fps: 30, resolution: 1080p
ret = cam.open_cam(0, 1, 30, 1920, 1080)
print("Camera open_cam return:%d" % ret)

# wait for 1s
time.sleep(1)

# get one image from camera
img = cam.get_img(2)
if img is not None:
# save file
fo = open("output.img", "wb")
fo.write(img)
fo.close()
print("camera save img file success")
else:
print("camera save img file failed")

# close MIPI camera
cam.close_cam()
print("test_camera done!!!")

test_camera()

set_img

【Function Description】

Input image data into the vps module and trigger image processing.

【Function Declaration】
Camera.set_img(img)
【Parameter Description】
Parameter NameDescriptionValue Range
imgImage data to be processedMust match the VPS input resolution
【Usage】
camera = libsrcampy.Camera()

# enable vps function, input: 1080p, output: 512x512
ret = camera.open_vps(1, 1, 1920, 1080, 512, 512)
print("Camera vps return:%d" % ret)

fin = open("output.img", "rb")
img = fin.read()
fin.close()

# send image to vps module
ret = vps.set_img(img)
【Return Value】
Return ValueDescription
0Success
-1Failure
【Notes】

This API must be called after open_vps.

【Reference Code】
import sys, os, time

import numpy as np
import cv2
from hobot_vio import libsrcampy

def test_camera_vps():
vps = libsrcampy.Camera()

# enable vps function, input: 1080p, output: 512x512
ret = vps.open_vps(1, 1, 1920, 1080, 512, 512)
print("Camera vps return:%d" % ret)

fin = open("output.img", "rb")
img = fin.read()
fin.close()

# send image data to vps
ret = vps.set_img(img)
print ("Process set_img return:%d" % ret)

fo = open("output_vps.img", "wb+")

# get image data from vps
img = vps.get_img()
if img is not None:
fo.write(img)
print("encode write image success")
else:
print("encode write image failed")
fo.close()

# close vps function
vps.close_cam()
print("test_camera_vps done!!!")

test_camera_vps()

close_cam

【Function Description】

Disable the enabled MIPI camera.

【Function Declaration】
Camera.close_cam()
【Parameter Description】

None

【Usage】
cam = libsrcampy.Camera()

# open MIPI camera, fps: 30, resolution: 1080p
ret = cam.open_cam(0, 1, 30, 1920, 1080)
print("Camera open_cam return:%d" % ret)

# close MIPI camera
cam.close_cam()
【Return Value】

None

【Notes】

None

【Reference Code】

None

Host ID Selection

The host ID corresponding to the camera is shown in the figure below:

20250220-114529.png