Camera

CameraCase Experiment ResultsCode Explanation

 

Case Experiment Results

When training your own AI vision model later, it is recommended to use K230 to shoot the target to be identified and save the picture as a training set.

This can optimize and reduce some of the poor results caused by the difference between the training photos and the actual recognition environment.

The sample code for this section is located in: [Source code/02.Basic/19.snapshot.py]

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

In the system's file manager, open the directory corresponding to CanMV. We enter the directory CanMV/sdcard

The path of the pictures saved is in the [/data/snapshot/] directory

Run the program, the camera will be awakened, and the screen will show the photo currently being taken.

image-20250401195011879

Press the Key key, K230 will take a picture of the current screen and save it in the [/sdcard/photo/(xxx)] directory. The saved folder (xxx) will be displayed on the screen each time the program is run.

Taking the code in the above figure as an example, the photo taken this time is saved in the path [/sdcard/photo/28549/]

image-20250401195201375

Code Explanation

The example code in this section is as follows

Specific workflow:

  1. Initialization settings:

    • Set the photo save path to "/data/snapshot/"
    • Create unique folder names with current timestamp
    • Set up photo counter
  2. Camera Settings:

    • Initialize the camera sensor and set the resolution to 800x480
    • Set RGB565 color format
    • Configuring HDMI display output
    • Initialize the Media Manager
  3. Main loop function:

    • Continuously capture camera images

    • Overlay the current photo information (save path and photo sequence number) on the preview screen

    • Monitoring key input

    • When a key press is detected:

      • Make sure the storage directory exists

        • Save photos with increasing serial numbers
        • Short delay after saving to prevent repeated triggering
  4. Exception handling:

    • Can handle user interrupts (such as pressing Ctrl+C)
    • Catch and display other possible exceptions
  5. Program end processing:

    • Stop the camera
    • Turn off display device
    • Release the media cache
    • Clean up system resources