All Projects → 1zlab → 1ZLAB_Color_Block_Finder

1zlab / 1ZLAB_Color_Block_Finder

Licence: other
使用OpenCV实现色块追踪 为了方便大家入门OpenCV以及使用OpenCV实现颜色识别, 阿凯编写了相关的上位机脚本, 同时也有. 刚开始的时候, 你的精力可以放在算法流程上面, 没必要在前期过于关注代码的细节. 脚本的代码阿凯也是逐行注释的, 也可以作为你的项目参考 .

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to 1ZLAB Color Block Finder

colorsys
🎨 Minimalistic color converter for RGB, HSV, HSL, CMYK, HEX and CSS strings
Stars: ✭ 53 (-27.4%)
Mutual labels:  hsv
HSV-Color-Picker
A simple OpenCV script that displays the upper and lower HSV ranges of any pixel in an RGB image
Stars: ✭ 40 (-45.21%)
Mutual labels:  hsv
SimpleVideoAnnotation
A simple video annotation made with python + OpenCV for detection in YoloV2 format
Stars: ✭ 13 (-82.19%)
Mutual labels:  python-opencv
docker-opencv
Docker image with OpenCV 2 and 3
Stars: ✭ 21 (-71.23%)
Mutual labels:  python-opencv
orthomosaic
Rectify and stitch images together using multiview geometry.
Stars: ✭ 72 (-1.37%)
Mutual labels:  python-opencv
reinvented-color-wheel
A vanilla-js touch-friendly HSV color picker inspired by Farbtastic Color Picker.
Stars: ✭ 43 (-41.1%)
Mutual labels:  hsv
ColorHelper
No description or website provided.
Stars: ✭ 34 (-53.42%)
Mutual labels:  hsv
sass-color-helpers
A collection of Sass color helpers that enables easier, more fool-proof design implementations (+ some math helpers)
Stars: ✭ 92 (+26.03%)
Mutual labels:  hsv
vscode-color
Helper with GUI to generate color codes such as CSS color notations.
Stars: ✭ 88 (+20.55%)
Mutual labels:  hsv
colorsys-go
🎃 colorsys-go is a go package(or lib) for everyone to transform one color system to another. The transformation is among RGB, YIQ, HLS and HSV.
Stars: ✭ 75 (+2.74%)
Mutual labels:  hsv
rgb-tui
Create and get colors code from the terminal using a nice interface.
Stars: ✭ 57 (-21.92%)
Mutual labels:  hsv
ichiColor
Full features javascript color parser module, perfect work with vue.js; support RGB, HSL, HSV/HSB, HSL255, HSL240, HWB, XYZ, LAB, LUV, LHCab, xyY...
Stars: ✭ 23 (-68.49%)
Mutual labels:  hsv
ColorPicker
Customizable Color Picker control for WPF
Stars: ✭ 57 (-21.92%)
Mutual labels:  hsv
pi pico neopixel
Pi Pico library for NeoPixel led-strip written in MicroPython. Works with ws2812b (RGB) and sk6812 (RGBW).
Stars: ✭ 70 (-4.11%)
Mutual labels:  hsv

OpenCV色块识别-1Z实验室

作者: 阿凯 出品: 1Z实验室(1zlab) Make Things Easy

前言

在OpenCV上实现颜色识别是很多人入门计算机视觉(OpenCV)首先会去学习的算法.

色块识别演示样例

而且颜色识别可以广泛应用于色块追踪, 巡线等机器人项目.
为了方便大家入门OpenCV以及使用OpenCV实现颜色识别, 阿凯编写了相关的上位机脚本, 同时也有. 刚开始的时候, 你的精力可以放在算法流程上面, 没必要在前期过于关注代码的细节. 脚本的代码阿凯也是逐行注释的, 也可以作为你的项目参考 .

备注: 代码兼容Windows, Mac, Ubuntu

目录

1选择ROI区域

桌面上放置着一个瓶盖, 如果我们想识别蓝色瓶盖的话, 第一步就需要截取蓝色瓶盖的蓝色区域的子图(ROI, Region Of Interest, 感兴趣区域).

选择ROI区域代码在01-选择ROI区域文件夹下. 代码演示视频见: 01-选择ROI区域/演示视频

image

python select_roi.py "图片文件路径"

例如:

python select_roi.py demo-pic.png

select roi

截取出来的图像就是这样的.

image_roi

2图像颜色统计HSV

获取了瓶盖的子图之后, 我们就要对图片在HSV颜色空间(color space)下的统计进行可视化的绘制, 从而获取颜色阈值的初步参考范围.

HSV

图像颜色统计HSV在02-图像颜色统计HSV文件夹下. 代码演示视频见: 02-图像颜色统计HSV/演示视频

脚本使用方法

 python img_hsv_stat.py  <图片路径>

应用举例.

 python img_hsv_stat.py image_roi.png

HSV颜色统计样例

观察上面的统计图,我们可以获取到蓝色瓶盖在HSV颜色空间下的分布.

通道(Channel) 最小值(Min) 最大值(Max)
H: Hue 色调/色彩 96 114
S: Saturation 饱和度 210 255
V: Value 明暗 174 216

3颜色阈值动态调节

有了大致的颜色范围还不行, 我们需要借助颜色阈值调节工具去细化, 对阈值进行微调. 阈值的初始设定,按照之前获取的大致范围开始.然后按照阈值进行图像二值化(binary), 满足阈值条件的像素点为白色, 不满足阈值条件的像素为黑色.

HSV颜色阈值动态调节工具 在03-HSV颜色阈值动态调节工具 文件夹下. 代码演示视频见: 03-HSV颜色阈值动态调节工具 /演示视频

HSV颜色阈值调节工具

脚本使用说明

python ThresholdEditorGUIHsv.py + <图片路径>

例如:

python ThresholdEditorGUIHsv.py demo-pic.png

阈值调节目标

调节目标,就是要让目标颜色区域变为白色.

二值化

选中窗口,按E键盘退出程序.

4色块识别

获取到颜色阈值了,我们就可以检索画面中的色块啦.

色块识别 在04-色块识别 文件夹下. 代码演示视频见: 04-色块识别 /演示视频

色块识别

脚本使用方法

运行测试程序test_color_feature.py

python test_color_feature.py

默认是从视频中读入视频流, 并显示识别后的视频.

如果是从图片中读入的话就调整一下代码注释:

if __name__ == "__main__":
    # 测试图片色块识别
    test_color_block_finder_01()
    # 测试视频流色块识别
    # test_color_block_finder_02()

色块识别的核心算法已经封装在color_block_finder.py 里面的color_block_finder 函数中, 函数返回的是Tuple类型的矩形区域. 通过draw_color_block_rect 函数可以绘制画面中的色块.

颜色阈值如果要调整的话, 调整这里:

  • lowerb = (minH, minS, minV)
  • upperb = (maxH, maxS, maxV)
def test_color_block_finder_02():
    '''
    色块识别测试样例2 从视频流中读取并且识别
    '''
    # 视频路径
    video_path = 'demo-video.mkv'
    # 颜色阈值下界(HSV) lower boudnary
    lowerb = (96, 210, 85) 
    # 颜色阈值上界(HSV) upper boundary
    upperb = (114, 255, 231)

宣传海报

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].