Image moments are statistical values computed from an image. They allow us to analyze the image as a whole. Note that it's often useful to extract contours first, and only then compute and work with each component moment, independently. In this recipe, you will learn how to compute moments for binary/grayscale images.
Calculating image moments
Getting ready
You need to have OpenCV 3.x installed, with Python API support.
How to do it...
- Import the modules:
import cv2
import numpy as np
import matplotlib.pyplot as plt
- Draw a test image—a white ellipse with the...