CannyCam

https://badge.fury.io/py/cannycam.svg

Description

Uses webcam stream and performs Canny Edge Detection and Haar Cascade image detection.

Canny Edge Detection removes noise from image, giving black background and white outline. This accentuates sharp edges in the image, making it very easy to detect a target.

Haar Cascade image detection actually detects the target, given a training set of positive images (pictures of the target) and negative images (pictures not containing target, should be images of the physical backgroud used for the experiment).

Together, they take a video as a stream of images, to isolate and detect the target.

Targets used: face, upper body, lower body, hands. Knee, elbow, smaller body parts are work in progress.

Next step is to implement this into a diagnostic image detection program for assisting doctors. E.g. patient goes to doctor with broken ankle, doctor takes x-ray, diagnostic image detection program may be able to detect certain problems with patient’s ankle upon scanning the x-ray.

CannyCam. Better than a nannycam.

Installation

pip install cannycam

Run

From the command line

python -m cannycam.cannycam
python -m cannycam.haarcam
python -m cannycam.cannyhaarcam

Or in python

import cannycam

cannycam.cannycam.main()
cannycam.haarcam.main()
cannycam.cannyhaarcam.main()

API

Webcams

class cannycam.basecam.BaseCam(window)[source]

Abstract class for running a cv2 webcam.

Parameters:window – Name of the window that the cv2 webcam will open.
run(frame_throttle)[source]

Run main cv2 webcam capture loop.

Parameters:frame_throttle – Number of frames to throttle for capturing and processing an image from the webcam.
class cannycam.cannycam.CannyCam(window)[source]

Bases: cannycam.basecam.BaseCam

Webcam that performs Canny Edge detection on the video stream.

Parameters:window – Name of the window that the cv2 webcam will open.
detect_edges(img, color=True)[source]

Detect edges of img with Canny Edge detection.

Parameters:
  • img – Image read from webcam.
  • color – Boolean to indicate if should use color. Defaults to True.
run(frame_throttle)[source]

Run main cv2 webcam capture loop.

Parameters:frame_throttle – Number of frames to throttle for capturing and processing an image from the webcam.
class cannycam.haarcam.HaarCam(window)[source]

Bases: cannycam.basecam.BaseCam

Webcam that performs Haar Cascade object detection on the video stream.

Parameters:window – Name of the window that the cv2 webcam will open.
detect_parts(img, classifier)[source]

Detect anatomical parts in img with Haar Cascade object detection.

Parameters:
  • img – Image read from webcam.
  • classifier – Classifier to detect anatomical parts.
face_classifier

Get a face classifier.

fullbody_classifier

Get a full body classifier.

lowerbody_classifier

Get a lower body classifier.

run(frame_throttle, classifier=None)[source]

Run main cv2 webcam capture loop.

Parameters:
  • frame_throttle – Number of frames to throttle for capturing and processing an image from the webcam.
  • classifier – Classifier to detect anatomical parts. Defaults to a face classifier if None.
upperbody_classifier

Get an upper body classifier.

class cannycam.cannyhaarcam.CannyHaarCam(window)[source]

Bases: cannycam.cannycam.CannyCam, cannycam.haarcam.HaarCam

Webcam that performs Canny Edge detection and then Haar Cascade object detection on the video stream.

Parameters:window – Name of the window that the cv2 webcam will open.
detect_edges(img, color=True)

Detect edges of img with Canny Edge detection.

Parameters:
  • img – Image read from webcam.
  • color – Boolean to indicate if should use color. Defaults to True.
detect_parts(img, classifier)

Detect anatomical parts in img with Haar Cascade object detection.

Parameters:
  • img – Image read from webcam.
  • classifier – Classifier to detect anatomical parts.
face_classifier

Get a face classifier.

fullbody_classifier

Get a full body classifier.

lowerbody_classifier

Get a lower body classifier.

run(frame_throttle, classifier=None)[source]

Run main cv2 webcam capture loop.

Parameters:
  • frame_throttle – Number of frames to throttle for capturing and processing an image from the webcam.
  • classifier – Classifier to detect anatomical parts. Defaults to a face classifier if None.
upperbody_classifier

Get an upper body classifier.

Utils

cannycam.util.apply_doc(source)[source]

Decorator that will prepend source’s docstring to the decorated object’s docstring.

Parameters:source – Object with docstring to be prepended onto the decorated object.
cannycam.util.get_cascade_file_path(cascade_file)[source]

Formats a full filepath to the XML cascade_file in the xmls directory.

Parameters:cascade_file – XML file.
cannycam.util.is_escape(key)[source]

Determines if key is the ESC key.

Parameters:key – Key to check.
cannycam.util.wait_frames(throttle)[source]

Returns a generator that yields every throttle frames.

Parameters:throttle – Number of frames to wait before yielding.

Indices and tables