Go to Post Don't worry about someone stealing your ideas...if they're good ideas, then imitation is the sincerest form of flattery. If they're lousy ideas, we'll let you know, so you can work on finding a better idea. win-win! - MrForbes [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 27-01-2017, 16:01
Espo Espo is offline
Registered User
AKA: Ben
FRC #5113 (Combustible Lemons)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2016
Location: Moorestown, NJ
Posts: 5
Espo is an unknown quantity at this point
OpenCV question about thresholding

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:

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()
Reply With Quote
  #2   Spotlight this post!  
Unread 27-01-2017, 16:29
billbo911's Avatar
billbo911 billbo911 is offline
I prefer you give a perfect effort.
AKA: That's "Mr. Bill"
FRC #2073 (EagleForce)
Team Role: Mentor
 
Join Date: Mar 2005
Rookie Year: 2005
Location: Elk Grove, Ca.
Posts: 2,386
billbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond reputebillbo911 has a reputation beyond repute
Re: OpenCV question about thresholding

Quote:
Originally Posted by Espo View Post
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))
__________________
CalGames 2009 Autonomous Champion Award winner
Sacramento 2010 Creativity in Design winner, Sacramento 2010 Quarter finalist
2011 Sacramento Finalist, 2011 Madtown Engineering Inspiration Award.
2012 Sacramento Semi-Finals, 2012 Sacramento Innovation in Control Award, 2012 SVR Judges Award.
2012 CalGames Autonomous Challenge Award winner ($$$).
2014 2X Rockwell Automation: Innovation in Control Award (CVR and SAC). Curie Division Gracious Professionalism Award.
2014 Capital City Classic Winner AND Runner Up. Madtown Throwdown: Runner up.
2015 Innovation in Control Award, Sacramento.
2016 Chezy Champs Finalist, 2016 MTTD Finalist
Reply With Quote
  #3   Spotlight this post!  
Unread 27-01-2017, 23:21
truell20 truell20 is offline
Registered User
FRC #5806
 
Join Date: Jan 2017
Location: New York
Posts: 11
truell20 is on a distinguished road
Re: OpenCV question about thresholding

Could you link to the 254 presentation?
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 15:28.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi