Simple Beginner level Color Detection program
HSV (for hue, saturation, value; also known as HSB, for hue, saturation, brightness) are alternative representations of the RGB color model, designed in the 1970s by computer graphics researchers to more closely align with the way human vision perceives color-making attributes. In these models, colors of each hue are arranged in a radial slice, around a central axis of neutral colors which ranges from black at the bottom to white at the top
above brief introduction of the HSV color panel will help you to better understanding the following codeWhen you bring an object in front of your camera, the 'res' window shows you the only color you have selected to detect. And in this project, I will use my webcam as my primary camera but you can choose any camera as your wish.
First of all, you have to initialize the NumPy library and OpenCV library,
And you have to define a new function call nothing (you can use any function name as your wish) and this will be help full for displaying changing values, and I'll explain this more later on. Then we create a 'cap' variable to capture our video,
After all of this, I will create a blank name window to create my Trackbars for changing values, then I create six Trackbars for low hue, low saturation, low value, upper hue, upper saturation, upper value
the syntax for creating a trackbar is cv2.createTrackbar(trackbar name, window name, value, count, change)
after initializing all these things I create a while loop. then use cap.read() function to capture the video
'hsv' variable stands for converting our captured video from our default webcam to HSV form also creates another six variables to store trackbar positions which we are changing.
when you are done with all of these things, what you have to do next is define a variable to store lower and upper HSV value range for that I create a NumPy array named 'l_b' and 'u_b'.
Then create a mask with lower and upper HSV ranges. Using bitwise_and you can filter up the color that you want to detect from the input video.
And finally, I put some command to close the windows it can be added as your preference
-*-*-*-*-*-*-*-*-*-*-*-*-*- full Code is here -*-*-*-*-*-*-*-*-*-*-*-*-*-









It's great😍
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteSuperb brooo
ReplyDelete