Here, we are saying that all pixels in our image that have a R >= 100, B >= 15, and G >= 17 along with R <= 200, B <= 56, and G <= 50 will be considered red. Let’s go ahead and define this list of colors: # define the list of boundariesĪll we are doing here is defining a list of boundaries in the RGB color space (or rather, BGR, since OpenCV represents images as NumPy arrays in reverse order), where each entry in the list is a tuple with two values: a list of lower limits and a list of upper limits.įor example, let’s take a look at the tuple (, ). That means we’ll have to recognize red, blue, yellow, and gray colors in the image. We want to be able to detect each of the Game Boy cartridges in the image. Then, on Line 12, we load our image off disk. We’ll need just a single switch, -image, which is the path to where our image resides on disk. Lines 7-9 then handle parsing our command line arguments. ![]() We’ll use NumPy for numerical processing, argparse to parse our command line arguments, and cv2 for our OpenCV bindings. We’ll start by importing our necessary packages on Lines 2-4. # construct the argument parse and parse the argumentsĪp.add_argument("-i", "-image", help = "path to the image") Open up your favorite editor and create a file named detect_color.py : # import the necessary packages This example will run on Python 2.7/Python 3.4+ and OpenCV 2.4.X/OpenCV 3.0+. Looking for the source code to this post? Jump Right To The Downloads Section
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |