Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the problem of parameter transfer between OpenCV basic HSV color space * args and * * kwargs slider bar

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Today, I will talk to you about how to understand the OpenCV basic HSV color space * args and * * kwargs slider transfer parameters, many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

I. basic theory

HSV:HSV is a concept that is easy to understand in order to speed up the color blending efficiency.

Hue: hue (specific color)

Saturation: saturation, color purity

Value: lightness

1. Hue (hue)

Hue: hue (specific color)

2. Value (brightness)

Lightness: the brightness of the color, the brightness of a single channel (not equal to the overall luminous amount).

(the higher the brightness is, the whiter it is, and the lower it is, the darker it is. Generally, increasing the brightness will increase the values of R, G and B channels at the same time.)

3. Saturation (saturation)

Saturation: saturation, color purity. (the lower the gray, the higher the purer)

(generally increasing the saturation reduces the relatively low values in the RGB, highlighting the purity of the main colors. )

Bilibili video explanation:

RGB and HSV-- the basic principle of color formation in film and television color blending

2. Hsv three-channel and single-channel effect

3. * args & & * * kwargs

* args: the input parameter is unknown and you do not need to know the parameter name.

* * args: the input parameter is unknown, but you need to know the parameter name.

4. Scroll bars control h, s, v (min & & max) 1. Create scroll bars.

API

CV_EXPORTS int createTrackbar (const string& trackbarname, const string& winname, int* value, int count, TrackbarCallback onChange = 0, void* userdata = 0)

Formal parameter-trackbarname: name of sliding space

Formal parameter two winname: the name of the image window to which the sliding space is attached

Formal parameter three value: initialization threshold

Formal parameter four count: the scale range of the sliding control

Formal parameter five TrackbarCallback: is a callback function, which is defined as follows

Typedef void (CV_CDECL * TrackbarCallback) (int pos, void* userdata) # 3. Create h, s, v scroll bars cv2.createTrackbar ('hmin',' hobbies, 12,179, Renew) cv2.createTrackbar ('hmax',' hacks, 37,179, Renew) cv2.createTrackbar ('smin',' hacks, 12179, Renew) cv2.createTrackbar ('smax', 's boxes, 37,179, Renew) cv2.createTrackbar (' vmin', 'vaults, 12179, Renew) cv2.createTrackbar (' vmax' 'Vince, 37179, Renew)

2. Callback function-threshold setting

API

InRange ()

Mainly, the pixel value within the two thresholds is set to white (255), while the pixel value not within the threshold range is set to black (0), which is similar to the double threshold operation in between.

Void inRange (InputArray src, InputArray lowerb, InputArray upperb, OutputArray dst)

Parameter 1: enter the image to be processed, which can be single-channel or multi-channel.

Parameter 2: an array or scalar containing the lower boundary.

Parameter 3: contains an upper bound array or scalar.

Parameter 4: the output image is the same size as the input image src and is of CV_8U type.

(note: dst output the image after binarization)

# 1. Get the slider feedback value hmin = cv2.getTrackbarPos ('hmin', 'h') hmax = cv2.getTrackbarPos (' hmax', 'h') smin = cv2.getTrackbarPos ('smin', 's') smax = cv2.getTrackbarPos ('smax',') vmin = cv2.getTrackbarPos ('vmin',' v') vmax = cv2.getTrackbarPos ('vmax',' v') # 2, set the threshold (inRange: at the threshold (min) Within max) Set to white Set to black outside the threshold) h_thresh = cv2.inRange (np.array (h), np.array (hmin), np.array (hmax)) s_thresh = cv2.inRange (np.array (s), np.array (smin), np.array (smax)) v_thresh = cv2.inRange (np.array (v), np.array (vmin), np.array (vmax))

3. Callback function-value of interest

API

Bitwise_and ()

The sum operation of an image is mainly used to obtain the interesting part of an image, which is aimed at the bitwise sum of two image matrix arrays or an array and scalars.

# 3. Get interested binary (and operation) interest = cv2.bitwise_and (h_thresh, cv2.bitwise_and (s_thresh, v_thresh))

General code

# HSV color space and slider (* args & * * args) import cv2import numpy as np# callback function # * args: the input parameter is unknown and you do not need to know the parameter name # * * args: the input parameter is unknown But you need to know the parameter name def HSV_CallBack (* args): # 1. Get the slider feedback value hmin = cv2.getTrackbarPos ('hmin',' hackers') hmax = cv2.getTrackbarPos ('hmax',' hackers') smin = cv2.getTrackbarPos ('smin', 's binaries') smax = cv2.getTrackbarPos ('smax', 's binaries') vmin = cv2.getTrackbarPos ('vmin' Vmax = cv2.getTrackbarPos ('vmax',') # 2. Set the min,max (inRange: within the threshold) Set to white Outside the threshold Set to black) h_binary = cv2.inRange (np.array (h), np.array (hmin), np.array (hmax)) s_binary = cv2.inRange (np.array (s), np.array (smin), np.array (smax)) v_binary = cv2.inRange (np.array (v), np.array (vmin), np.array (vmax)) # 3, get interested binary (and operation) binary = cv2.bitwise_and (h_binary) Cv2.bitwise_and (s_binary, v_binary)) # 4. Display cv2.imshow ('hobby binaries, h_binary) cv2.imshow (' binary', binary binaries, s_binary) cv2.imshow ('binary', binary binaries, v_binary) cv2.imshow (): global hsv, h, s V # 0, create window cv2.namedWindow ('hobby binaries') cv2.namedWindow ('security binaries') cv2.namedWindow ('hsv', hsv binaries') # 1, get hsv pictures hsv = cv2.cvtColor (img, cv2.COLOR_RGB2HSV) cv2.imshow ('hsv', hsv) # 2, get h, s, v three-channel pictures h, s V = cv2.split (hsv) # 3, create h, s, v scroll bars cv2.createTrackbar ('hmin',' hobby binaries, 12179, HSV_CallBack) cv2.createTrackbar ('hmax',' hobbies binaries, 37,179, HSV_CallBack) cv2.createTrackbar ('smin', 's boxes binaries, 12179, HSV_CallBack) cv2.createTrackbar (' smax', 's boxes binaries, 37179) HSV_CallBack) cv2.createTrackbar ('vmin',' vicious binaries, 12179, HSV_CallBack) cv2.createTrackbar ('vmax',' vicious binaries, 37,179, HSV_CallBack) HSV_CallBack () if _ _ name__ = ='_ main__': global img img = cv2.imread ('Resource/test.jpg') cv2.imshow (' img') Img) # display h, s, v Show_HSV () cv2.waitKey (0) finish reading the above Do you have any further understanding of how to understand the OpenCV basic HSV color space * args and * * kwargs slider transfer parameters? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report