opencv_wrapper.model.
Point
(x, y)[source]¶Model class for a point. Point can be added, subtracted and iterated over, yielding x, y.
cartesian
()[source]¶Return type: | Tuple [float , float ] |
---|---|
Returns: | The point represented as cartesian coordinates |
norm
¶Return the absolute L2 norm of the point. Alias for cvw.norm(point).
Return type: | float |
---|---|
Returns: | The absolute L2 norm of the point |
opencv_wrapper.model.
Rect
(x, y, width, height, *, padding=0)[source]¶Model class of a rectangle.
Rectangles can be iterated over, yielding x, y, width, height.
Rectangles can also be divided. The division is applied to x, y, the width and the height of the rectangle. The makes the rectangle fit to an image shrinked by the same factor.
A test whether or not a point is located inside the rectangle can be checked by the in keyword: if point in rect.
If padding is given, the rectangle will be padding pixels larger in each of its sides. The padding can be negative.
Parameters: |
|
---|
area
¶Return type: | float |
---|---|
Returns: | The area of the rectangle. |
cartesian_corners
()[source]¶Yields the rectangle as top-left and bottom-right points, as used in cv2.rectangle.
Return type: | Tuple [Tuple [float , float ], Tuple [float , float ]] |
---|---|
Returns: | The top-left and bottom-right corners of the rectangle as cartesian two-tuples. |
opencv_wrapper.display.
circle
(image, center, radius, color, thickness=1)[source]¶Draw a circle on image at center with radius.
Parameters: |
|
---|
opencv_wrapper.display.
draw_contour
(image, contour, color, thickness=1)[source]¶Draw a contour on an image.
Parameters: |
|
---|
opencv_wrapper.display.
draw_contours
(image, contours, color, thickness=1)[source]¶Draw multiple contours on an image
Parameters: |
|
---|
opencv_wrapper.display.
line
(image, point1, point2, color, thickness=1, line_style=<LineStyle.SOLID: 1>)[source]¶Draw a line from point1 to point2 on image.
Parameters: |
|
---|
opencv_wrapper.display.
put_text
(image, text, origin, color, thickness=1, scale=1)[source]¶Put text on image at origin.
Parameters: |
|
---|
opencv_wrapper.display.
rectangle
(image, rect, color, thickness=1, line_style=<LineStyle.SOLID: 1>)[source]¶Draw a rectangle on image.
Parameters: |
|
---|
opencv_wrapper.display.
wait_key
(delay)[source]¶Wait for a key event infinitely (if delay is 0) or delay amount of milliseconds.
An alias for cv.waitKey(delay) & 0xFF. See cv.waitKey(delay) for further documentation. Comparison of the key pressed can be found by ord(str). For example
>>> if wait_key(0) == ord('q'): continue
Parameters: | delay (int ) – Amount of milliseconds to wait, or 0 for infinitely. |
---|---|
Return type: | str |
Returns: | The key pressed. |
opencv_wrapper.utils.
Color
[source]¶Color enum for predefined colors.
Color.RANDOM returns a random color. Colors can be added together.
BLACK
= (0, 0, 0)¶BLUE
= (200, 0, 0)¶CYAN
= (255, 255, 0)¶GREEN
= (0, 200, 0)¶MAGENTA
= (255, 0, 255)¶RED
= (0, 0, 200)¶WHITE
= (255, 255, 255)¶YELLOW
= (0, 255, 255)¶opencv_wrapper.image_operations.
AngleUnit
[source]¶Enum for which angle unit to use.
DEGREES
= 2¶RADIANS
= 1¶opencv_wrapper.image_operations.
MorphShape
[source]¶Enum for determining shape in morphological operations.
Alias for OpenCV’s morph enums.
CIRCLE
= 2¶CROSS
= 1¶RECT
= 0¶opencv_wrapper.image_operations.
AngleUnit
[source]Enum for which angle unit to use.
opencv_wrapper.image_operations.
MorphShape
[source]Enum for determining shape in morphological operations.
Alias for OpenCV’s morph enums.
opencv_wrapper.image_operations.
bgr2gray
(image)[source]¶Convert image from BGR to gray
Parameters: | image (ndarray ) – Image to be converted |
---|---|
Return type: | ndarray |
Returns: | Converted image |
opencv_wrapper.image_operations.
bgr2hls
(image)[source]¶Convert image from BGR to HLS color space
Parameters: | image (ndarray ) – Image to be converted |
---|---|
Return type: | ndarray |
Returns: | Converted image |
opencv_wrapper.image_operations.
bgr2hsv
(image)[source]¶Convert image from BGR to HSV color space
Parameters: | image (ndarray ) – Image to be converted |
---|---|
Return type: | ndarray |
Returns: | Converted image |
opencv_wrapper.image_operations.
bgr2luv
(image)[source]¶Convert image from BGR to CIE LUV color space
Parameters: | image (ndarray ) – Image to be converted |
---|---|
Return type: | ndarray |
Returns: | Converted image |
opencv_wrapper.image_operations.
bgr2xyz
(image)[source]¶Convert image from BGR to CIE XYZ color space
Parameters: | image (ndarray ) – Image to be converted |
---|---|
Return type: | ndarray |
Returns: | Converted image |
opencv_wrapper.image_operations.
canny
(image, low_threshold, high_threshold, high_pass_size=3, l2_gradient=True)[source]¶Perform Canny’s edge detection on image.
Parameters: |
|
---|---|
Return type: |
|
Returns: | Binary image of thinned edges. |
opencv_wrapper.image_operations.
dilate
(image, kernel_size, shape=<MorphShape.RECT: 0>, iterations=1)[source]¶Dilate image with kernel_size and shape.
Parameters: |
|
---|---|
Return type: |
|
Returns: | The dilated image |
opencv_wrapper.image_operations.
erode
(image, kernel_size, shape=<MorphShape.RECT: 0>, iterations=1)[source]¶Erode image with kernel_size and shape.
Parameters: |
|
---|---|
Return type: |
|
Returns: | The eroded image |
opencv_wrapper.image_operations.
find_external_contours
(image)[source]¶Find the external contours in the image.
Alias for cv2.findContours(image, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
Parameters: | image (ndarray ) – The image in with to find the contours |
---|---|
Return type: | Tuple [Contour , …] |
Returns: | A tuple of Contour objects |
opencv_wrapper.image_operations.
gray2bgr
(image)[source]¶Convert image from gray to BGR
Parameters: | image (ndarray ) – Image to be converted |
---|---|
Return type: | ndarray |
Returns: | Converted image |
opencv_wrapper.image_operations.
morph_close
(image, kernel_size, shape=<MorphShape.RECT: 0>, iterations=1)[source]¶Morphologically close image with kernel_size and shape.
Parameters: |
|
---|---|
Return type: |
|
Returns: | The closed image |
opencv_wrapper.image_operations.
morph_open
(image, kernel_size, shape=<MorphShape.RECT: 0>, iterations=1)[source]¶Morphologically open image with kernel_size and shape.
Parameters: |
|
---|---|
Return type: |
|
Returns: | The opened image |
opencv_wrapper.image_operations.
normalize
(image, min=0, max=255)[source]¶Normalize image to range [min, max].
Parameters: |
|
---|---|
Return type: |
|
Returns: | The normalized image |
opencv_wrapper.image_operations.
resize
(image, factor=None, shape=None)[source]¶Resize an image with the given factor. A factor of 2 gives an image of half the size.
If the image has 4 dimensions, it is assumed to be a series of images.
:type image: ndarray
:param image: Image to resize
:type factor: Optional
[int
]
:param factor: Shrink factor. A factor of 2 halves the image size.
:type shape: Optional
[Tuple
[int
, …]]
:param shape: Output image size.
:rtype: ndarray
:return: A resized image
opencv_wrapper.image_operations.
rotate_image
(image, center, angle, unit=<AngleUnit.RADIANS: 1>)[source]¶Rotate image angle degrees at center. unit specifies if angle is given in degrees or radians.
Parameters: | |
---|---|
Return type: |
|
Returns: | The rotated image. |
opencv_wrapper.image_operations.
threshold_adaptive
(image, block_size, c=0, *, weighted=True, inverse=False)[source]¶Adaptive thresholding of image, using a (weighted) local mean.
A local threshold value is determined for each block_size x block_size window. If weighted is true, the gaussian weighted mean is used. If not, the mean is used.
Parameters: |
|
---|---|
Return type: |
|
Returns: | The thresholded image. |
opencv_wrapper.tracking.
dense_optical_flow
(prev_frame, next_frame, pyr_scale=0.5, levels=3, winsize=11, iterations=1, poly_n=4, poly_sigma=1.1, gaussian_window=True, initial_flow=None)[source]¶Calculate the dense optical flow between two frames, using the Farnebäck method.
For further documentation on the parameters, see OpenCV documentation for cv2.calcOpticalFlowFarnaback.
Parameters: |
|
---|---|
Return type: |
|
Returns: | An image with the shape |
Convenience functions for reading videos.
Usage:
>>> import cv2 as cv
>>> with load_video("path/to/file") as video:
>>> for frame in read_frames(video):
>>> cv.imshow("Frame", frame)
>>> cv.waitKey(1)
opencv_wrapper.video.
VideoWriter
(filename, fps=None, capture=None, fourcc='MJPG')[source]¶A video writer for writing videos, using OpenCV’s cv.VideoWriter.
The video writer is lazy, in that it waits to receive the first frame, before determining the frame size for the video writer. This is in contrast to OpenCV’s video writer, which expects a frame size up front.
Either fps or capture must be provided.
For additional documentation, see cv2.VideoWriter documentation
Parameters: |
|
---|
opencv_wrapper.video.
load_camera
(index=0)[source]¶Open a camera for video capturing.
Parameters: | index (int ) – Index of the camera to open. For more details see cv2.VideoCapture(index) documentation |
---|
Return type: | Iterator [Any ] |
---|
opencv_wrapper.video.
load_video
(filename)[source]¶Open a video file
Parameters: | filename (str ) – It an be:
For more details see cv2.VideoCapture(filename) documentation |
---|
Return type: | Iterator [Any ] |
---|
opencv_wrapper.video.
read_frames
(video, start=0, stop=None, step=1)[source]¶Read frames of a video object.
Start, stop and step work as built-in range.
Parameters: |
|
---|---|
Return type: |
|
opencv_wrapper.misc_functions.
line_iterator
(image, p1, p2)[source]¶Produces and array that consists of the coordinates and intensities of each pixel in a line between two points.
Credit: https://stackoverflow.com/questions/32328179/opencv-3-0-python-lineiterator
Parameters: | |
---|---|
Return type: |
|
Returns: | An array that consists of the coordinates and intensities of each pixel on the line. (shape: [numPixels, 3(5)], row = [x,y, intensity(b, g, r)]), for gray-scale(bgr) image. |
opencv_wrapper.misc_functions.
norm
(input)[source]¶Calculates the absolute L2 norm of the point or array.
:type input: Union
[Point
, ndarray
]
:param input: The n-dimensional point
:rtype: float
:return: The L2 norm of the n-dimensional point