Skip to content

Simple script to find RGB or HSV colourspace ranges for the region of interest(ROI). Real time saver for your computer vision or image processing projects. It can also be used to find range of other colourspaces like LAB by tweaking basic OpenCV functions.

Notifications You must be signed in to change notification settings

kushalchaudhari21/RangeFinder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Description

This is an python script to get a colorspace range for your computer vision or image processing projects using trackbars.

Sample Invocation

  • In the terminal, you need to specify a filter and "only one" image source:
(python) range-detector --filter RGB --image /path/to/image.png
  • You can also capture image via webcam to process it further:
(python) range-detector --filter HSV --webcam
  • Example:
(cv) KC:RangeFinder> python range_finder.py --filter HSV --image /Users/Desktop/tutorials/git/RangeFinder/img.jpeg 

executionCommand

Usage

1. Execute the script and the program starts printing real-time trackbar values.

2. Next, two windows pop up on the screen containing original image and trackbar filtered image respectively.

3. Adjust the trackbar sliders to get the desired region of interest(ROI). In this case, trackbars are adjusted to detect the red LED blob in the image.

UsingTrackbarstoSelectBlob

4. Note down the corresponding colourspace ranges for your ROI.

correspondingHSVforBlob

Important Insights

  • Function adjust_gamma can be used to preprocess the image to attenuate effect of different lighting conditions.
def adjust_gamma(image, gamma):

   invGamma = 1.0 / gamma
   table = np.array([((i / 255.0) ** invGamma) * 255
      for i in np.arange(0, 256)]).astype("uint8")

   return cv2.LUT(image, table)
  • ROI range for a different colourspace can be evaluated by converting image to that colourspace instead of RGB or HSV.
if args['image']:
        image = cv2.imread(args['image'])
        image = cv2.resize(image, (768,576))
        #image = adjust_gamma(image,gamma)
        #image = cv2.addWeighted(image,alpha,np.zeros(image.shape,image.dtype),-0.3,beta)
        
        if range_filter == 'RGB':
            frame_to_thresh = image.copy()
        else:
        #Converting to LAB colourspace to get LAB ranges. Sequence remains the same for ranges.
            frame_to_thresh = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)
    else:
        camera = cv2.VideoCapture(0)

About

Simple script to find RGB or HSV colourspace ranges for the region of interest(ROI). Real time saver for your computer vision or image processing projects. It can also be used to find range of other colourspaces like LAB by tweaking basic OpenCV functions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages