Quote:
Originally Posted by Espo
We are using OpenCV (python) to threshold an image. I saw team 254's presentation, which said to use HSV/HSL. We are using HSV. However, I believe that OpenCV is still expecting a BGR format. How do I have it take in an HSV/HSL formatted color?
Here is our code:...
|
You will need to convert the BGR to HSV.
Code:
#Convert the image from BGR(RGB) to HSV
hsvImage = cv2.cvtColor( Raw, cv2.COLOR_BGR2HSV)
Once converted to HSV, thresholding is simple.
We keep our upper and lower threshold values in a "calibration" file.
Code:
CalFile = open ('Calibration').read().splitlines()
uh = int(CalFile[0])
lh = int(CalFile[1])
us = int(CalFile[2])
ls = int(CalFile[3])
uv = int(CalFile[4])
lv = int(CalFile[5])
er = int(CalFile[6])
dl = int(CalFile[7])
ap = int(CalFile[8])
Our thresholding command looks like this.
Code:
## Threshold HSV Image to find specific color
binImage = cv2.inRange(hsvImage, (lh, ls, lv), (uh, us, uv))