简体   繁体   中英

What should the HSV thresholding in OpenCV return if successful?

I'm using OpenCV and Python to develop software that can find a target pattern in an image. I'm currently working on finding the desired targets, and part of this is running an HSV thresholding operation to isolate the color of my target. The HSV thresholding code looks like this:

out = cv2.cvtColor(input, cv2.COLOR_RGB2HSV)
return cv2.inRange(out, (hue[0], sat[0], val[0]), (hue[1], sat[1], val[1]))

The arrays hue[] , sat[] , and val[] are defined elsewhere in the code, and contain experimentally checked values for the HSV range I'm looking for. I added a print statement to print the output after running this method. When I run this method on my camera frames, it's returning this:

[[0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]]

I tried using a different stock image of balloons that contains lots of different colors, and it returned the same thing. I'm having trouble finding documentation on what the HSV method should return if working correctly, so I'm not exactly sure how to debug this.

Does anyone know what types of output I should be seeing if things are working properly and/or have any examples?

I've solved this, and I wanted to put this here in case anyone has a similar question and searches it later on.

Printing out the image to a window helped me immensely, because my web viewer for the IP camera, the GRIP display window, and the OpenCV image were all slightly different, therefore the thresholding numbers that I got from GRIP did not work at all, and returned only a black image.

Here's how to print your image to a window and see what you're working with:

cv2.imshow('image', img) #img is your image, 'image' is the name of the window you'll create
cv2.waitKey(0) #handles GUI elements, and causes the window to close when you press any key
cv2.destroyAllWindows()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM