Last chapter, we created a module called utils
for some miscellaneous helper functions. A couple of extra helper functions will make it easier for us to write a tracker.
First, it may be useful to know whether an image is in grayscale or color. We can tell based on the dimensionality of the image. Color images are 3D arrays, while grayscale images have fewer dimensions. Let's add the following function to utils.py
to test whether an image is in grayscale:
def isGray(image): """Return True if the image has one channel per pixel.""" return image.ndim < 3
Second, it may be useful to know an image's dimensions and to divide these dimensions by a given factor. An image's (or other array's) height and width, respectively, are the first two entries in its shape
property. Let's add the following function to utils.py
to get an image's dimensions, divided by a value:
def widthHeightDividedBy(image, divisor): """Return an image's dimensions, divided by a value.""" h, w = image.shape[:2] return (w/divisor, h/divisor)
Now, let's get back on track with this chapter's main subject, tracking.