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.
- 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.
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) |
pip install cv-recon
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:
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 |
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] ])
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 |
Loads HSV settings from a generated .log file.
Args | Description | Default |
---|---|---|
settings | Path to .log file with generated HSV settings | None |
returns: None
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
Creates a window with sliders in order to adjust the HSV settings.
returns: None
Updates the current HSV settings with the current slider values.
returns: None
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
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
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 |
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)
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 |
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
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
Returns an image containing the matches between im_target and im_source.
Args | Description | Default |
---|---|---|
matches | List containing the good matches | None |
returns: image
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
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 |
from cv_recon.picam import PiCam
# cam settings
res = (320, 240)
fps = 24
# initialize the camera
camera = PiCam(res, fps, brightness=55, contrast=10)
Property | Description | Type |
---|---|---|
current_frame | Current frame | np.array |
Creates a thread which updates the property current_frame.
returns: None
Stops updating the property current_frame.
returns: None
Prints the list of image effects.
returns: None
Prints the list of exposure modes.
returns: None
Prints the list of automatic withe balance modes.
returns: None
This module allows you generate a grid of images, draw bounding boxes and its offset from the center of the frame.
from cv_recon import cv_tools
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
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]
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
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