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:
import numpy as np
import cv2
from networktables import NetworkTable as nettab
import logging
logging.basicConfig(level=logging.DEBUG)
#H: 0 - 360
#S: 0 - 255
#V: 0 - 255
lower_thresh = np.array([60, 150, 150])
upper_thresh = np.array([180, 255, 255])
#lower_thresh = np.array([0, 100, 0])
#upper_thresh = np.array([50, 255, 50])
lower_thresh[0] /= 2
upper_thresh[0] /= 2
nettab.setIPAddress("10.51.13.2")
nettab.setClientMode()
nettab.initialize(server="10.51.13.83")
table = nettab.getTable("vision")
print(nettab.isConnected())
cap = cv2.VideoCapture(0) #1280 x 720
while (True):
# Capture frame-by-frame
ret, frame = cap.read() # frame = None, which is causing the run time error
# Our operations on the frame come here
new = cv2.inRange(frame, lower_thresh, upper_thresh)
#Display the resulting frame
cv2.imshow('BW', new)
cv2.imshow('Color', frame)
table.putBoolean("test", True)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()