Various utilities for OpenCV.
class FPSCounter
: utility for measuring frames per second (FPS) with a rolling averageFPSCounter(avg_len=30)
: create a new FPS counter that averagesavg_len
measurementsgot_frame()
: tell the counter that a frame was processedfps()
: get the average FPSdraw_fps(self, img, pos=(10,30), prec=1, size=2, thickness=2, color=(255,255,255), fmt='%.1f FPS')
: draw the FPS on an imageimg
: the image to draw onpos
: the position to draw the text atprec
: the number of decimal digits to displaysize
: the size of the textthickness
: the thickness of the textcolor
: the color of the textfmt
: the format string for the text. Must format a float.
Color-related utilities
hex2bgr(h)
: converts a hexadecimal color into a BGR numpy array. E.g.0x00FF01
->[1, 255, 0]
cvtPixel(color, code)
: converts a color into another color space.color
: the color to convert. Can be a list, numpy array, or tuple – e.g.(255, 0, 0)
code
: an OpenCV color conversion code, e.g.cv2.COLOR_HSV2BGR
- Color constants (in BGR):
MAROON
,RED
,ORANGE
,YELLOW
,OLIVE
,GREEN
,PURPLE
,FUCHSIA
,LIME
,TEAL
,AQUA
,BLUE
,NAVY
,BLACK
,GRAY
,SILVER
,WHITE
.
sort_contour(contour)
: sorts a contour's points in clockwise order.contour
: a numpy array of points with shape(n_points, 1, 2)
center(contour)
: returns the center of a contour as tuple(cx, cy)
iou(contour1, contour2)
: returns the intersection over union (IOU) of two contours. IOU = (area of intersection) / (area of union)