I have a 2D numpy array containing the individual data from each pixel of a sensor. The image is displayed in a GUI with a live feed from the camera. I want to be able to draw a rectangle over the image in order to distinguish an area of the screen. It seems pretty simple to draw a rectangle which is parallel to the side of the image but I eventually want to be able to rotate the rectangle. How will I know which pixels the rectangle covers when it is rotated?
Share
You can use the Python Imaging Library, if you don’t mind the dependency. Given a 2D numpy array
data, and an arraypolyof polygon coordinates (with shape (n, 2)), this will draw a polygon filled with the value 0 in the array:Here’s a self-contained demo:
This script generates this plot: