Skip to main content

Visual Tools - an object oriented approach to image processing and analysis. Requires OpenCV 3.0+

Project description

vtools
============

vimg README rev.0 2017/3/11
This library is a project that is the result of my venture into the realm of computer vision.
This project is a direct result of exploring and thinking about a highly simple and intuitive
way to create an image object, and then easily be able to perform a powerful set of methods and
alterations to that object, making routine tasks like thresholding and contouring a more simple
and Object-oriented endeavor.

I want to pay complete homage to Dr. Adrian Rosebrock in every way for the content of this package.
His website is http://www.pyimagesearch.com/ . I've read his book and his blog posts about OpenCV
for a long time and this package is a direct result from the knowledge that I have gained while
and since doing so. This package borrows logic, code, and even comments that Dr. Rosebrock has
written in his 'imutils' package located here: https://pypi.python.org/pypi/imutils

The goal of this package is to integrate these tools into an object oriented interface that extends
the np.ndarray class with methods and properties to create an even simpler image manipulation and
analysis interface than what Dr. Rosebrock's imutils package provides.


Dependencies
------------
OpenCV 3.0+
Python 3.6+


Install vtools
--------------------
**From Source**

You should clone this repository and run setup.py::

cd vtools && python setup.py install

**From PyPI**

::

pip install vtools

Getting Started
---------------

thresholding (simple binary) an image before vtools' vImg class:

# Read in the image

image = cv2.imread('../images/trex.png')

# Convert to grayscale and apply gaussian blur

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Set gaussian blur k (size of weighted mean area),
# must be odd so there's a center pixel

k = 3
gauss = cv2.GaussianBlur(gray, (k,k), 0)

# Now set the threshold level, T

T = 215

# Next, apply the threshold to the image

thresh = cv2.threshold(gauss, T, 255, cv2.THRESH_BINARY_INV)[1]

thresholding (simple binary) an image using vtools.vImg:

image = vImg('../images/trex.png')
thresh = image.threshold(215)

note: currently the only required variable is for T, but k (defaults to 5) and
inverse (bool, defaults to True) are also available as named parameters.

The vContour class:

calculating contours and evaluating contour properties before vtools.vimg:

image = cv2.imread('quiz1.png')
_, cnts, _ = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
hullImage = np.zeros(gray.shape[:2], dtype="uint8")

# loop over the contours

for (i, c) in enumerate(cnts):

# compute the area of the contour along with the bounding box
# to compute the aspect ratio

print(f'Contour {i} type({type(c)})')
area = cv2.contourArea(c)
(x, y, w, h) = cv2.boundingRect(c)
x2, y2 = x + w, y + h

# compute the aspect ratio of the contour, which is simply the width
# divided by the height of the bounding box

aspectRatio = w / float(h)

# use the area of the contour and the bounding box area to compute
# the extent

extent = area / float(w * h)

# compute the convex hull of the contour, then use the area of the
# original contour and the area of the convex hull to compute the
# solidity

hull = cv2.convexHull(c)
hullArea = cv2.contourArea(hull)
solidity = area / float(hullArea)

# compute the center (tuple)

center = ((x + x2) / 2, (self. + y2) / 2)

# visualize the original contours and the convex hull and initialize
# the name of the shape

cv2.drawContours(hullImage, [hull], -1, 255, -1)
cv2.drawContours(image, [c], -1, (240, 0, 159), 3)

print(f'Shape #{i}: Aspect Ratio is {aspectRatio:.2f}, hull area is {hullArea:.2f}, '
f'solidity is {solidity:.2f}, extent is {extent:.2f}, center is {center}')


Evaluating contours for usefulness with vtools' vImg, vContour, and vContours classes:

img = vImg("images/test.png")

# outline each contour one by one and print simple and advanced contour properties
# allowing you to easily determine whether contours may be useful to your CV application

img.gray().evalContours()

# the evalContours() method defaults to using the vImg simpleContours function with default parameters,
# but you can also supply your own calculated contours value (in the form of a list of vContours)

Histograms with vtools' vImg

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

vtools-0.0.28.tar.gz (23.5 kB view details)

Uploaded Source

File details

Details for the file vtools-0.0.28.tar.gz.

File metadata

  • Download URL: vtools-0.0.28.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for vtools-0.0.28.tar.gz
Algorithm Hash digest
SHA256 ffa23bf27ac11fc2e8c736dc9cb9f0ce883893d25145003d0477f5dec13cb5d0
MD5 813a35d41e9ef863e9fb3eb52628f430
BLAKE2b-256 23a2a062bc461c2d93b1d045eb4b353a217b84a68082de9119997785199e110d

See more details on using hashes here.

Supported by

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