GithubHelp home page GithubHelp logo

kushalchaudhari21 / rangefinder Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 4.51 MB

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.

Python 100.00%
computer-vision opencv python rangefinder trackbar image-processing hsv rgb object-detection

rangefinder's Introduction

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.