Skip to main content

A computer vision toolkit focused on color detection and feature matching using OpenCV. It allows you to easily start the picamera in case you're using a Raspberry PI.

Project description

About

A computer vision toolkit focused on color detection and feature matching using OpenCV. It allows you to easily start the picamera in case you're using a Raspberry PI.

Some of the stuff you can currently do

  • Color detection
    • Detect a range of colors in an image using HSV boundaries.
    • Find bounding boxes.
  • Feature matching
    • Draw matches between a source and target image.
    • Find bounding boxes.
  • Picamera
    • Easily start the picamera.
  • Tools
    • Draw boxes.
    • Draw boxes' offset from the center of the frame.
    • Stack frames in a grid.

Dependencies

Dependency Installation
python3 Refer to the official website
opencv Refer to the official installation guide (tested with version 4.5.2)
numpy pip install numpy
picamera Installed by default in Raspberry PI OS (required only if working with a picamera)

Installation

pip install cv-recon

Usage

See examples in the examples folder or test it directly form source. Change directory cd cv_recon/recon/ once in this folder you can run:

Command Description Preview
python colorspace.py Generates HSV settings to detect a specific color Colorspace example 1
python colorspace.py <path to .log file> Loads HSV settings to detect a specific color Colorspace example 2
python features.py <path to an image> Performs feature detection against a given image Feature matching example

Documentation

Class: Colorspace(hsv_settings=None)

This class allows you to detect a range of colors using HSV boundaries. You can generate the settings or set them directly. See examples here.

Args Description Default
hsv_settings Path to .log file containing the HSV settings or list containing lower and upper HSV boundaries None

Import example

from cv_recon import Colorspace
# load generated settings
colorspace_1 = Colorspace('settings.log')
# or set hsv lower and upper boundaries
colorspace_2 = Colorspace([ [0, 0, 0], [179, 255, 255] ])

Properties

Property Description Type Default
lower Lower HSV boundary list None
upper Upper HSV boundary list None
im_mask Mask obtained from the HSV boundaries np.array None
im_cut Portions of the frame containing the color boundaries np.array None
im_edges Canny edge detection applied to im_mask np.array None
im_contours Contours of the detected objects drawn on the current frame np.array None

Methods

loadSettings(settings)

Loads HSV settings from a generated .log file.

Args Description Default
settings Path to .log file with generated HSV settings None

returns: None

dumpSettings(output='last.log')

Generates a .log file with the current HSV settings.

Args Description Default
output Path in which the file is gonna be written 'last.log'

returns: None

createSliders()

Creates a window with sliders in order to adjust the HSV settings.
returns: None

updateHSV()

Updates the current HSV settings with the current slider values.
returns: None

getMaskBoxes(im_base, im_hsv, min_area=20, scale=0.1)

Generates a list containing the bounding boxes (x, y, w, h) of the objects.

Args Description Default
im_base Base image in bgr format None
im_hsv Base image in hsv format None
min_area Minimum area to generate the coordinates 20
scale Scale of the bounding box 0.1

returns: bounding_boxes

getMaskBoxesArea(im_base, im_hsv, min_area=20, scale=0.1)

Generates two lists containing the bounding boxes (x, y, w, h) and the estimated area of each object.

Args Description Default
im_base Base image in bgr format None
im_hsv Base image in hsv format None
min_area Minimum area to generate the coordinates 20
scale Scale of the bounding box 0.1

returns: bounding_boxes, areas

Class: Features(im_source=None, features=500)

This class allows you to easily perform feature matching detection. See examples here.

Args Description Default
im_source Source image None
features Amount of features in im_source 500

Import example

from cv_recon import Features
import cv2 as cv

# load source image (the image you want to detect)
im_source = cv.imread('image.jpg')
# create Features object (detects 1000 features from the source image)
my_feature = Features(im_source, 1000)

Properties

Property Description Type Default
im_source Source image (the image you want to detect) np.array im_source
im_source_kp Source image keypoints np.array im_source keypoints
im_target Target image np.array None
im_target_kp Target image keypoints np.array None
im_poly Image containing a polygon around the best matches np.array None

Methods

loadTarget(im)

Loads the target image to perform the feature matching detection.

Args Description Default
im Target image in which the feature matching is gonna be perform None

returns: None

getMatches(distance=0.75)

Generates a list with the good matches found in the target image.

Args Description Default
distance Threshold which decides if it is a good match 0.75

returns: good_matches

matchPoints(matches)

Returns an image containing the matches between im_target and im_source.

Args Description Default
matches List containing the good matches None

returns: image

getBoxes(matches, min_matches=20)

Generates a list containing the bounding box (x, y, w, h) of the object.

Args Description Default
matches Good matches None
min_matches Minimum amount of matches to generate the bounding box 20

returns: bounding_box

Class: PiCam(resolution=(320, 240), framerate=32, **kargs)

This class allows you to easily interact with the picamera. See examples here.

Args Description Default
resolution Camera resolution (320, 240)
framerate Framerate 32
**kargs Assign default picamera settings. See a list of the settings here None

Import example

from cv_recon.picam import PiCam

# cam settings
res = (320, 240)
fps = 24

# initialize the camera
camera = PiCam(res, fps, brightness=55, contrast=10)

Properties

Property Description Type
current_frame Current frame np.array

Methods

videoCapture()

Creates a thread which updates the property current_frame .
returns: None

release()

Stops updating the property current_frame .
returns: None

effects()

Prints the list of image effects.
returns: None

exposureModes()

Prints the list of exposure modes.
returns: None

awbModes()

Prints the list of automatic withe balance modes.
returns: None

Module: cv_tools

This module allows you generate a grid of images, draw bounding boxes and its offset from the center of the frame.

Import example

from cv_recon import cv_tools

Functions

grid(base, dimensions, images, scale=0.5)

Generates a numpy.array containing a grid of images with the given dimensions and scale.

Args Description Default
base Image with the base dimensions for the rest of the images None
dimensions Tupla containing the dimensions of the grid None
images List of images not larger than dimensions[0] * dimensions[1], each image must have the same dimensions as base None
scale Scale of the output image 0.5

Returns: image

getBoxesOffset(im, boxes)

Generates a list containing the offset of each box from the center of the frame.

Args Description Default
im Image with the size of the frame None
boxes List of bounding boxes None

Returns: [x_offset, y_offset]

drawBoxes(im, boxes)

Draw the bounding boxes over an image.

Args Description Default
im Image in which the bounding boxes are going to be drawn None
boxes List of bounding boxes None

Returns: image

drawBoxesPos(im, boxes)

Draw the offset from the center of the frame of each bounding box.

Args Description Default
im Image in which the offsets are going to be drawn None
boxes List of bounding boxes None

Returns: image

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cv-recon-1.0.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

cv_recon-1.0.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file cv-recon-1.0.0.tar.gz.

File metadata

  • Download URL: cv-recon-1.0.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.9

File hashes

Hashes for cv-recon-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5b172338e31e828991728a7772b475389912cec7b4b3d90be2002fa40081e9ee
MD5 8ba359ffbe7e9d54415067cbb33c46e1
BLAKE2b-256 e2bca86b6114a81f54ddc4e377f587e425c6497991173678284dca86aec113ae

See more details on using hashes here.

File details

Details for the file cv_recon-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cv_recon-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.5.0.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.9

File hashes

Hashes for cv_recon-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b4f6462b90adeac03c59c04a6fe500f8ed81a03996a7ab44a333c234273ca97b
MD5 fd451dafc3787d5122d730a299fc52a5
BLAKE2b-256 fe54a0c893babe1c4831203637a20fa314f968ac3bb25b1f5f6697b281327b19

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page