Camera display

Camera displayIntroduction to the results of routine experimentsCode ExplanationComplete codeCamera related APIConstructor2.1 sensor.reset2.2 sensor.set_framesize2.3 sensor.set_pixformat2.4 sensor.set_hmirror2.5 sensor.set_vflip2.6 sensor.run2.7 sensor.stop2.8 sensor.snapshot

 

Introduction to the results of routine experiments

In this section, we will call the camera and display the image captured by the camera in the IDE frame buffer.

We use CanMV IDE to open the sample code and connect K230 to the computer via USB.

Click the Run button in the lower left corner of the CanMV IDE, and you can see the image captured by the camera displayed in the frame buffer in the upper right corner of the IDE.

image-20250211095846642

Code Explanation

The source code file for this tutorial is located in [Source Code/02.Basic/17.sensor.py]

Complete code

Camera related API

The following content is excerpted from the CanMV Sensor API chapter

The module of the CanMV K230 platform sensoris responsible for image acquisition and data processing. The module provides a set of high-level APIs that developers can use to easily obtain images of different formats and sizes without having to understand the specific implementation of the underlying hardware.

camera-block-diagram

Sensor 0, sensor 1, and sensor 2 represent three image input sensor devices; Camera Device 0, Camera Device 1, and Camera Device 2 correspond to the corresponding image processing units; output channel 0, output channel 1, and output channel 2 indicate that each image processing unit supports up to three output channels. Through software configuration, different sensor devices can be flexibly mapped to the corresponding image processing units.

The module of CanMV K230 sensorsupports the simultaneous access of up to three image sensors, each of which can independently complete the acquisition, capture and processing of image data. In addition, each video channel can output three channels of image data in parallel for further processing by the back-end module. In actual applications, the specific number of sensors supported, input resolution and number of output channels will be limited by the hardware configuration and memory size of the development board, so a comprehensive evaluation is required based on project requirements.

Constructor

describe

csi idConstruct an object from a and an image sensor type Sensor.

In image processing applications, users usually need to create an Sensorobject first. CanMV K230 software can automatically detect the built-in image sensor, without the user manually specifying the specific model, just set the maximum output resolution and frame rate of the sensor. For information about supported image sensors, see the image sensor support list . If the set resolution or frame rate does not match the default configuration of the current sensor, the system will automatically adjust to the optimal configuration. The final configuration can be viewed in the log, for example use sensor 23, output 640x480@90.

grammar

parameter

Parameter namedescribeInput/Outputillustrate
idcsiPort, support 0-2, please refer to the hardware schematic diagram for specific portsenterOptional. The default value is different for different development boards.
widthsensorMaximum output image widthenterOptional, default1920
heightsensorMaximum output image heightenterOptional, default1080
fpssensorMaximum output image frame rateenterOptional, default30

Return Value

Return Valuedescribe
Sensor ObjectSensor Object

Example

2.1 sensor.reset

describe

Resets sensorthe object. SensorYou must call this function after constructing the object to continue executing other operations.

grammar

parameter

Parameter namedescribeInput/Output
none

Return Value

Return Valuedescribe
none

Example

2.2 sensor.set_framesize

describe

Sets the output image size for the specified channel. The user can configure the output image size via framesizethe parameter or by specifying widthand directly. The width is automatically aligned to 16 pixels wide .height

grammar

parameter

Parameter namedescribeInput/Output
framesizeSensor output image sizeenter
chnSensor output channel numberenter
widthOutput image width, kw_argenter
heightOutput image height, kw_argenter

Return Value

Return Valuedescribe
none

Precautions

Example

2.3 sensor.set_pixformat

describe

Configure the image sensor output image format for the specified channel.

grammar

parameter

Parameter namedescribeInput/Output
pix_formatOutput image formatenter
chnSensor output channel numberenter

Return Value

Return Valuedescribe
none

Example

2.4 sensor.set_hmirror

describe

Configure whether the image sensor is horizontally mirrored.

grammar

parameter

Parameter namedescribeInput/Output
enableTrueEnable horizontal mirror function FalseDisable horizontal mirror functionenter

Return Value

Return Valuedescribe
none

Example

2.5 sensor.set_vflip

describe

Configure whether the image sensor is flipped vertically.

grammar

parameter

Parameter namedescribeInput/Output
enableTrueTurn on the vertical flip function FalseTurn off the vertical flip functionenter

Return Value

Return Valuedescribe
none

Example

2.6 sensor.run

describe

Enables output of the image sensor. This must be done before calling .MediaManager.init()

grammar

Return Value

Return Valuedescribe
none

Precautions

Example

2.7 sensor.stop

describe

Stops image sensor output. This method must be called before .MediaManager.deinit()

grammar

Return Value

Return Valuedescribe
none

Precautions

Example

2.8 sensor.snapshot

describe

Capture a frame of image data from the specified output channel.

grammar

parameter

Parameter namedescribeInput/Output
chnSensor output channel numberenter

Return Value

Return Valuedescribe
image objectCaptured image data
otherCapture failed

Example