pycharmers.opencv.drawing module¶
-
pycharmers.opencv.drawing.
convert_coords
(bbox, to_type, from_type='')[source]¶ Convert coordinates:
[OpenCV] [YOLO] (x,y)---------(x+w,y) (l,t)----------(r,t) | | | | | | | | | | | | (x,y+h)-------(x+w,y+h) (l,b)----------(r,b) [xywh] [ltrb]
- Parameters
bbox (tuple) – Bounding Box coordinates.
to_type (str) – coordinate type.
Examples
>>> from pycharmers.opencv import convert_coords >>> xywh = (120,250,60,80) >>> ltrb = convert_coords(bbox=xywh, to_type="ltrb") >>> xywh = convert_coords(bbox=ltrb, to_type="xywh")
-
pycharmers.opencv.drawing.
draw_bboxes_xywh
(frame, bboxes, infos=None)¶ Drawing Inference results on frame.
- Parameters
frame (ndarray) – Image. shape=(H,W,ch)
bboxes (list) – Each element is the coordinate (x,y,w,h)
infos (list) – Each element is dictionary. (
key
iscolor
, ortext
)
Examples
>>> import cv2 >>> import matplotlib.pyplot as plt >>> from pycharmers.opencv import draw_bboxes_xywh, cv2read_mpl >>> img = cv2read_mpl("path/to/img.png") >>> draw_bboxes_xywh( ... frame=img, ... bboxes=[(120,250,60,80),(220,40,80,100)], ... infos=[{"color":(255,0,0),"text": "person1"},{"color":(0,255,0),"text": "person2"}] ... ) >>> plt.imshow(img) >>> plt.show()
-
pycharmers.opencv.drawing.
draw_bboxes_ltrb
(frame, bboxes, infos=None)¶ Drawing Inference results on frame.
- Parameters
frame (ndarray) – Image. shape=(H,W,ch)
bboxes (list) – Each element is the coordinate (x,y,w,h)
infos (list) – Each element is dictionary. (
key
iscolor
, ortext
)
Examples
>>> import cv2 >>> import matplotlib.pyplot as plt >>> from pycharmers.opencv import draw_bboxes_ltrb, cv2read_mpl >>> img = cv2read_mpl("path/to/img.png") >>> draw_bboxes_ltrb( ... frame=img, ... bboxes=[(120,250,60,80),(220,40,80,100)], ... infos=[{"color":(255,0,0),"text": "person1"},{"color":(0,255,0),"text": "person2"}] ... ) >>> plt.imshow(img) >>> plt.show()
-
pycharmers.opencv.drawing.
cv2read_mpl
(filename, *flags)[source]¶ loads an image from the specified file and returns it as RGB format.
- Parameters
filename (str) – Name of file to be loaded.
flags (int) – Flags.
-
pycharmers.opencv.drawing.
cv2plot
(x, ax=None, clear_pos=['l', 't', 'r', 'b'], cmap=None, is_cv2=True, figkeywargs={}, plotkeywargs={})[source]¶ Plot Image using OpenCV
- Parameters
x (str/np.ndarray) – path to an image, or image. (BGR)
ax (Axes) – The
Axes
instance.clear_pos (list) – Positions to clean a grid
cmap (str) –
is_cv2 (bool) – Whether
x
is BGR (OpenCV format) or not.figkeywargs (dict) – Keyword arguments for
FigAxes_create
plotkeywargs (dict) – Keyword arguments for
ax.imshow
.
Examples
>>> from pycharmers.opencv import cv2plot, SAMPLE_LENA_IMG >>> ax = cv2plot(x=SAMPLE_LENA_IMG)
-
pycharmers.opencv.drawing.
draw_text_with_bg
(img, text, org=10, 10, offset=10, 10, fontFace=3, fontScale=1, color=0, 0, 0, bgcolor=255, 255, 255, color_type='css4', thickness=2, **kwargs)[source]¶ Put text with background color.
- Parameters
img (np.ndarray) – Image.
text (str) – Text string to be drawn.
org (tuple) – Bottom-left corner of the text string in the image.
fontFace (int) – Font type.
fontScale (int) – Font scale factor that is multiplied by the font-specific base size.
color (str/tuple) – Text color.
thickness (int) – Thickness of the lines used to draw a text.
lineType (int) – Line type.
bottomLeftOrigin (bool) – When ``True`, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner.
Examples
>>> import matplotlib.pyplot as plt >>> from pycharmers.opencv import draw_text_with_bg, cv2read_mpl, SAMPLE_LENA_IMG >>> img = cv2read_mpl(filename=SAMPLE_LENA_IMG) >>> draw_text_with_bg(img=img, offset=(100,-100), text="My name is Shuto") >>> plt.imshow(img) >>> plt.show()
-
pycharmers.opencv.drawing.
plot_cv2fontFaces
(bgcolor=50, 50, 50, cmap='Pastel1')[source]¶ Plot All
fontFace
supported by OpenCV.- Parameters
bgcolor (tuple) – background color (RGB)
cmap (str) – The name of a color map known to
matplotlib
Examples
>>> from pycharmers.opencv import plot_cv2fontFaces >>> plot_cv2fontFaces()