Library to help the drawing process with OpenCV. Thought to add labels to the images. Classification of images, etc.
Project description
opencv-draw-tools
Library to help the drawing process with OpenCV. Thought to add labels to the images. Classification of images, etc.
Image generated with Intel Openvino Toolkit and drawed with opencv-draw-tools v0.1.9
Installation
Pre-requisites
You will need to install:
- opencv >= 3.6.2
- numpy >= 1.13.3
- python-constraint >= 1.4.0
You can simply execute:
pip install -r requirements.txt
Finally you can install the library with:
pip install opencv-draw-tools-fernaperg
When you install opencv-draw-tools
, it will automatically download numpy
but not opencv becouse in some cases you will need another version.
Usage
Test
import opencv_draw_tools as cv2_tools
print('Name: {}\nVersion:{}\nHelp:{}'.format(cv2_tools.name,cv2_tools.__version__,cv2_tools.help))
cv2_tools.webcam_test()
Common method
import opencv_draw_tools as cv2_tools
"""
Draw better rectangles to select zones.
Keyword arguments:
frame -- opencv frame object where you want to draw
position -- touple with 4 elements (x1, y1, x2, y2)
This elements must be between 0 and 1 in case it is normalized
or between 0 and frame height/width.
tags -- list of strings/tags you want to associate to the selected zone (default [])
tag_position -- position where you want to add the tags, relatively to the selected zone (default None)
If None provided it will auto select the zone where it fits better:
- First try to put the text on the Bottom Rigth corner
- If it doesn't fit, try to put the text on the Bottom Left corner
- If it doesn't fit, try to put the text Inside the rectangle
- Finally if it doesn't fit, try to put the text On top of the rectangle
alpha -- transparency of the selected zone on the image (default 0.9)
1 means totally visible and 0 totally invisible
color -- color of the selected zone, touple with 3 elements BGR (default (110,70,45) -> dark blue)
BGR = Blue - Green - Red
normalized -- boolean parameter, if True, position provided normalized (between 0 and 1) else you should provide concrete values (default False)
thickness -- thickness of the drawing in pixels (default 2)
filled -- boolean parameter, if True, will draw a filled rectangle with one-third opacity compared to the rectangle (default False)
peephole -- boolean parameter, if True, also draw additional effect, so it looks like a peephole
"""
frame = cv2_tools.select_zone(frame, position, tags=[])
Example with Webcam
import opencv_draw_tools as cv2_tools
cv2_tools.webcam_test()
See webcam_test()
code:
def webcam_test():
"""Reproduce Webcam in real time with a selected zone."""
print('Launching webcam test')
cap = cv2.VideoCapture(0)
f_width = cap.get(3)
f_height = cap.get(4)
window_name = 'opencv_draw_tools'
while True:
ret, frame = cap.read()
frame = cv2.flip(frame, 1)
if ret:
keystroke = cv2.waitKey(1)
position = (0.33,0.2,0.66,0.8)
tags = ['MIT License', '(C) Copyright\n Fernando\n Perez\n Gutierrez']
frame = select_zone(frame, position, tags=tags, color=(130,58,14), thickness=2, filled=True, normalized=True)
cv2.imshow(window_name, frame)
# True if escape 'esc' is pressed
if keystroke == 27:
break
cv2.destroyAllWindows()
cv2.VideoCapture(0).release()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for opencv-draw-tools-fernaperg-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47c1caa1a64b5d17e59773f9e93b43e4d7dc3300d502500f018ebde10aeb5d90 |
|
MD5 | 6126c20d9a42c8ca8409b0cc78e61157 |
|
BLAKE2b-256 | e865f223f5f1e414a3241b0d07f703f3013c8d5017211ccaa6abb9a0c3f4e3cd |
Hashes for opencv_draw_tools_fernaperg-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53b4e6c9c4d0c2c04cd226048f84640599baad499767e35591e3f6bb1a3c4db3 |
|
MD5 | e6de3a5fa771c8ff4c83edeb8a69c958 |
|
BLAKE2b-256 | 7b3575dd427ee165be1a6552874b31405173a7aeb1a14a3327c271153b408ebc |