HSV trackbar Opencv Python

您所在的位置:网站首页 opencv+python HSV trackbar Opencv Python

HSV trackbar Opencv Python

2024-07-09 07:06:35| 来源: 网络整理| 查看: 265

A basic yet very useful application of OpenCV is to track color.

One major challenge while doing color detection is to include all the shades of color.

To solve this problem of shades instead of using RGB color space we use HSV color space.

Don’t know “How to create trackbar in OpenCV Python’ Read ->”Trackbars in OpenCV python“

HSV trackbar code #import opencv and numpy import cv2 import numpy as np #trackbar callback fucntion to update HSV value def callback(x): global H_low,H_high,S_low,S_high,V_low,V_high #assign trackbar position value to H,S,V High and low variable H_low = cv2.getTrackbarPos('low H','controls') H_high = cv2.getTrackbarPos('high H','controls') S_low = cv2.getTrackbarPos('low S','controls') S_high = cv2.getTrackbarPos('high S','controls') V_low = cv2.getTrackbarPos('low V','controls') V_high = cv2.getTrackbarPos('high V','controls') #create a seperate window named 'controls' for trackbar cv2.namedWindow('controls',2) cv2.resizeWindow("controls", 550,10); #global variable H_low = 0 H_high = 179 S_low= 0 S_high = 255 V_low= 0 V_high = 255 #create trackbars for high,low H,S,V cv2.createTrackbar('low H','controls',0,179,callback) cv2.createTrackbar('high H','controls',179,179,callback) cv2.createTrackbar('low S','controls',0,255,callback) cv2.createTrackbar('high S','controls',255,255,callback) cv2.createTrackbar('low V','controls',0,255,callback) cv2.createTrackbar('high V','controls',255,255,callback) while(1): #read source image img=cv2.imread("ballimage.jpg") #convert sourece image to HSC color mode hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) # hsv_low = np.array([H_low, S_low, V_low], np.uint8) hsv_high = np.array([H_high, S_high, V_high], np.uint8) #making mask for hsv range mask = cv2.inRange(hsv, hsv_low, hsv_high) print (mask) #masking HSV value selected color becomes black res = cv2.bitwise_and(img, img, mask=mask) #show image cv2.imshow('mask',mask) cv2.imshow('res',res) #waitfor the user to press escape and break the while loop k = cv2.waitKey(1) & 0xFF if k == 27: break #destroys all window cv2.destroyAllWindows()

Read this great article on Colorspaces and know why convert RGB to HSV for color detection.

Trending6 Interactive platform to learn Python free & fast.

Read More about Anatomy of a digital Image

Thank you for reading, Happy Learning, drop your suggestion in the comments.

Feel free to follow us on Youtube, Linked In , Instagram

Stay updated with the latest advancements Explore event, webinars and conferences

Om SinghOm Singhblog.electroica.com


【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭