yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
K210 Module📖
0.Camera changes
  • Precautions for camera changes
1.K210-AI-Camera introduction
  • 1.K210 main chip introduction
  • 2.K210 visual recognition module introduction
  • 3.Module pin assignments
  • 4.MicroPython Introduction
  • 5. FAQ analysis
  • 6.Bracket installation
2.Development Environment Setup
  • 1.To install the serial port assistant
  • 2.Install CanMV IDE development software
  • 3.Flashcard factory firmware
  • 4.IDE import routine
  • 5.Call custom py library
  • 6.MicroPython API documentation
3.Basic experimental routines
  • 1.Lighting the RGB light experiment
  • 2.Key features of the experiment
  • 3.Timer experiment
  • 4.PWM breathing light experiment
  • 5.LCD display experiment
  • 6.The touchpad read the coordinates of the experiment
  • 7.The camera shows the experimental
  • 8.Memory card read and write files of the experiment
  • 9.External interface experimental
4.Graphical manipulation routines
  • 1.Draw graphics
  • 2.Button and the click event
  • 3.Slider
  • 4.Chart animation
  • 5.Multi-label layout
5.AI visual experiments routines
  • How to import the model file into memory cardnew
  • 1.Color recognition
  • 2.Barcode recognition
  • 3.QR code recognition
  • 4.Apriltags recognition
  • 5.Face detection
  • 6.Face feature detection
  • 7.Mask detection
  • 8.Face recognition
  • 9.Object detection
  • 10.Self-learning classification
  • 11.Handwritten digit recognition
  • 12. Multiple color recognition
  • 13. Human body detectionnew
  • 14. Yolo hand detectionnew
  • 15. License Plate Recognitionnew
  • 16. Autonomous training modelnew
6.Extended routines (sold separately)
6.1.For STM32 Car
  • 10. stm_ K210 Autonomous Learning Classification
  • 1.automatic driving
  • 2.color follow
  • 3.Handwriting digital operation
  • 4.Color reaction
  • 5.Road sign indicating the operation
  • 6.Following the apriltag
  • 7.QR code instruction
  • 8.PTZ tracking color
  • 9.PTZ tracking face
6.2.1 arduino_k210
  • 1.ard_k210-Color recognition
  • 2.ard_k210-Bar code identification
  • 3.ard_k210-QR code identification
  • 4.ard_ K210-mechanical code identification
  • 5.ard_ K210-Face Detection
  • 6. ard_ K210-facial feature detection
  • 7. ard_ K210-mask detection
  • 8. ard_ K210-facial recognition
  • 9. ard_ K210-object detection
  • 10. ard_ K210 Autonomous Learning Classification
  • 11. ard_ K210 Handwritten Digit Recognition
6.2 K210 as a coprocessor
  • ReadMe
6.2.2 stm32_k210
  • 1.stm_ K210 color recognition
  • 2. stm_ K210 barcode recognition
  • 3. stm_ K210 QR code recognition
  • 4. stm_ K210 mechanical code identification
  • 5. stm_ K210 Face Detection
  • 6.stm_ K210 facial feature detection
  • 7. stm_ K210 mask detection
  • 8. stm_ K210 facial recognition
  • 9. stm_ K210 object detection
  • 11. stm_ K210 Handwritten Digit Recognition
6.2.3 microbit_k210
  • 1.microbit_ K210 color recognition
  • 2.microbit_ K210 barcode recognition
  • 3.microbit_ K210 QR code recognition
  • 4.microbit_ K210 mechanical code identification
  • 5. microbit_ K210 Face Detection
  • 6. microbit_ K210 facial feature detection
  • 7. microbit_ K210 mask detection
  • 8. microbit_ K210 facial recognition
  • 9. microbit_ K210 object detection
  • 10. microbit_ K210 autonomous classification learning
  • 11. microbit_ K210 Handwritten Digit Recognition
6.2.4 pico_k210
  • 1. pico_ K210 color recognition
  • 2. Pico_ K210 barcode recognition
  • 3. Pico_ K210 QR code recognition
  • 4. pico_ K210 machine code recognition
  • 5. pico_ K210 Face Detection
  • 6. pico_ K210 facial feature detection
  • 7. pico_ K210 mask recognition
  • 8. pico_ K210 facial recognition
  • 9. pico_ K210 object detection
  • 10. pico_ K210 Autonomous Learning Classification
  • 11. pico_ K210 Handwritten Digit Recognition
6.2.5 MSPM0G3507_k210
  • 1.MSPM0_K210 color recognition
  • 2.MSPM0_K210 barcode recognition
  • 3.MSPM0_K210 QR code recognition
  • 4.MSPM0_K210 mechanical code recognition
  • 5.MSPM0_K210 face detection
  • 6.MSPM0_K210 facial feature detection
  • 7.MSPM0_K210 mask detection
  • 8.MSPM0_K210 face recognition
  • 9.MSPM0_K210 Object Detection
  • 10.MSPM0_K210 Self-study classification
  • 11.MSPM0_K210 handwritten digit recognition
6.2.6 MSPM0G3519_k210
  • 1. MSPM0_K210 Color Recognitionnew
  • 2. MSPM0_K210 Barcode Recognitionnew
  • 3. MSPM0_K210 QR Code Recognitionnew
  • 4. MSPM0_K210 Mechanical Code Recognitionnew
  • 5. MSPM0_K210 Face Detectionnew
  • 6. MSPM0_K210 Facial Feature Detectionnew
  • 7. MSPM0_K210 Mask Detectionnew
  • 8. MSPM0_K210 Face Recognitionnew
  • 9. MSPM0_K210 Object Detectionnew
  • 10. MSPM0_K210 Self-study Classificationnew
  • 11. MSPM0_K210 Handwritten Digit Recognitionnew
6.3 For 24 channel servo drive board
  • 1. 2DOF PTZ Color Tracking
  • 2. 2DOF Face Tracking
  • 3. 2DOF Fruit sorting
6.4 For autopilot map
  • 1.k210 model training
  • 2.Assembly and wiring of stm32 car
  • 3.Recognize left and right sign
  • 4.Identify and remove speed limit
  • 5.Identify parking spaces and park
  • 6.STM32 car autopilot
6.5.1 For MSPM0G3507_Wheeled Chassis Kit
  • 1.MSPM0-Automatic Driving
  • 2.MSPM0-Color follow
  • 3.MSPM0-Number recognition
  • 4.MSPM0-Color reaction
  • 5.MSPM0-Road signs
  • 6.MSPM0-Machine code following
  • 7.MSPM0-QR code recognition
6.5.2 For MSPM0G3519_Wheeled Chassis Kit
  • 1.MSPM0-Automatic Drivingnew
  • 2.MSPM0-Color follownew
  • 3.MSPM0-Number recognitionnew
  • 4.MSPM0-Color reactionnew
  • 5.MSPM0-Road signsnew
  • 6.MSPM0-Machine code followingnew
  • 7.MSPM0-QR code recognitionnew
6.5.3 For STM32_Wheeled Chassis Kit
  • 1.STM32-Automatic Driving
  • 2.STM32-Color follow
  • 3.STM32-Number recognition
  • 4.STM32-K210-Color Reaction
  • 5.STM32-Road signs
  • 6.STM32-Machine code following
  • 7.STM32-QR code recognition
Download
  • Driver development software
  • AI model
  • Source code
  • Instruction manual
  • Hardware_3DModelFile
  • K210_Chip_Data
Download ZIP

Welcome to K210 Module repository

12. Multiple color recognition

12、Multiple color recognition

12、Multiple color recognition1.1 Experimental Objectives1.2 experimentation1.3、Experimental effect1.4、Experimental Summary2.1、Add new colors for recognition2.2、Obtain the LAB threshold that requires color increase

1.1 Experimental Objectives

This lesson mainly focuses on various color recognition functions. Based on the LAB value of the color, objects of different colors (red, yellow, blue, green) are framed without the need for collection The reference code path for this experiment is: CanMV\05-AI\multi_color_recognition.py

1.2 experimentation

The factory firmware of the module has already integrated the AI visual algorithm module. If you have downloaded other firmware, please burn it back to the factory firmware before conducting experiments.

  1. Import relevant libraries and initialize cameras and LCD displays

​x
import sensor
import image
import time
import lcd

lcd.init()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 100)
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)

clock = time.clock()
  1. Writing threshold ranges for color lab values

xxxxxxxxxx
color_thresholds = [
    (31, 69, 27, 58, 14, 36),# Red
    (14, 61, -39, -6, 0, 14), # Green
    (14, 66, 1, 38, -56, -12),# Blue
    (49, 77, -8, 52, 16, 60),# Yellow
]
color_strings = ['Red', 'Green', 'Blue', 'Yellow']
  1. Create a new while loop to recognize the colors of the images captured by the camera and display the recognition results on the screen

xxxxxxxxxx
while True:
    clock.tick()
    img = sensor.snapshot()
    for color_idx, threshold in enumerate(color_thresholds):
        blobs = img.find_blobs([threshold], pixels_threshold=100, area_threshold=100, merge=True, margin=10)
        if blobs:
            for blob in blobs:
                color_new = (255 , 255,255)
                if color_idx == 0 :
                    color_new = (255 , 0,0)
                elif color_idx == 1:
                    color_new = ( 0,255 ,0)
                elif color_idx == 2:
                    color_new = ( 0,0,255)
                elif color_idx == 3:
                    color_new = ( 255,255,0)
                img.draw_rectangle(blob.rect(), color=color_new,thickness = 3)
                img.draw_cross(blob.cx(), blob.cy(), color=color_new)
                img.draw_string(blob.cx() + 10, blob.cy() - 10, color_strings[color_idx], color=color_new)
    lcd.display(img)
    print(clock.fps())

1.3、Experimental effect

Connect the K210 module to the computer via a microUSB data cable, click the connect button in the CanMV IDE, and after the connection is completed, click the run button to run the routine code. You can also download the code as main.py and run it on the K210 module.

After the system initialization is completed, the LCD displays the camera image and begins to recognize the image, displaying the recognized colors on the screen.

  • The following image is the result recognized by the OV2640 camera image-2024010400002

  • The following image is the result recognized by the GC2145 camera image-2024010400003

1.4、Experimental Summary

The main function of multi color recognition is to analyze the LAB value of colors, and then compare it with the LAB value of colors collected by the camera for analysis. If it meets the requirements, draw a box and label the corresponding color to indicate recognition. This method has a significant impact on the ambient light of the recognized color, and the value of LAB may vary depending on the ambient light. Below, we will explain how to modify the value of LAB based on the ambient light, or add DIY colors beyond the tutorial.

2.1、Add new colors for recognition

Just add the color and threshold you want to recognize in the program source code, and the following pseudocode needs to be modified by yourself

xxxxxxxxxx
color_thresholds = [
    (31, 69, 27, 58, 14, 36),# Red
    # Green
    (14, 61, -39, -6, 0, 14),
    (14, 66, 1, 38, -56, -12),# Blue
    (49, 77, -8, 52, 16, 60),# Yellow
    (The value of LAB that needs to be added)#DIY's LAB value needs to be modified by oneself
]
color_strings = ['Red', 'Green', 'Blue', 'Yellow','Custom colors that need to be added'] #Self modification required

2.2、Obtain the LAB threshold that requires color increase

If you need to obtain the LAB threshold for new colors, or modify the LAB value of colors based on ambient light. All can be obtained through the tools of CanMV IDE.

  1. Double click on the CanMV IDE to open it, click on "Tools ->Machine Vision ->Threshold Editor", and select the Threshold Editor tool. image-2024010400004

  2. Click on "Image File" You can also click on the frame buffer (this method of obtaining LAB values is not explained in this tutorial, please note that k210 needs to be connected to cammv, and cammv cannot disable the frame buffer) image-2024010400005

  3. Choose and prepare images that contain new colors that need to be added, or images that recognize colors based on the current ambient light (try to choose images with a clean background and no interference from other colors) image-2024010400006

  4. Drag the slider until all recognized color areas are white and all other areas are black. Record the obtained LAB threshold

image-2024010400001

  1. Simply put the obtained threshold into the source code and make modifications according to the instructions in 2.1

Handwritten digit recognition
Human body detection

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文