使用opencv帮助绘图过程的库。想给图片加标签。图像分类等。
cv2-tools的Python项目详细描述
CV2_工具
使用opencv帮助绘图过程的库。想给图片加标签。图像等的分类
用人脸识别生成并用CV2工具2.0.2版绘制的图像
安装
先决条件
您需要安装:
- 打开cv>;=3.6.2
- numpy=1.13.3
- python约束>;=1.4.0
您只需执行:
pip install -r requirements.txt
最后,您可以使用以下命令安装库:
pip install cv2-tools
安装cv2-tools
时,它会自动下载numpy
,但不会下载opencv,因为在某些情况下,您需要另一个版本。
测试
import cv2_tools
print('Name: {}\nVersion:{}\nHelp:{}'.format(cv2_tools.name,cv2_tools.__version__,cv2_tools.help))
webcam_test()
ussage和重要类
经理v2
from cv2_tools.Management import ManagerCV2
如果你想使用视频或流,这个类将帮助你维护你的代码清洁,而你得到更多的功能。
例如:
- 打开一个流(你的网络摄像头)。
- 实时重现,最大fps等于24。
- 按
esc
完成程序。 - 最后打印平均fps。
from cv2_tools.Managment import ManagerCV2
import cv2
# keystroke=27 is the button `esc`
manager_cv2 = ManagerCV2(cv2.VideoCapture(0), is_stream=True, keystroke=27, wait_key=1, fps_limit=60)
# This for will manage file descriptor for you
for frame in manager_cv2:
cv2.imshow('Example easy manager', frame)
cv2.destroyAllWindows()
print(manager_cv2.get_fps())
如果您想使用另一个按钮但不知道ID,可以使用以下代码轻松检查:
from cv2_tools.Managment import ManagerCV2
import cv2
# keystroke=27 is the button `esc`
manager_cv2 = ManagerCV2(cv2.VideoCapture(0), is_stream=True, keystroke=27, wait_key=1, fps_limit=60)
# This for will manage file descriptor for you
for frame in manager_cv2:
# Each time you press a button, you will get its id in your terminal
last_keystroke = manager_cv2.get_last_keystroke()
if last_keystroke != -1:
print(last_keystroke)
cv2.imshow('Easy button checker', frame)
cv2.destroyAllWindows()
选择器C2
首先创建一个selectorcv2对象。您可以传递可选参数来配置输出。
from cv2_tools.Selection import SelectorCV2
selector = SelectorCV2(color=(200,90,0), filled=True)
也可以稍后使用方法(所有可选参数)对其进行配置:
selector.set_properties()
现在,每次要添加选定区域时,请调用以下方法:
"""
Coordinates:
(x1,y1)____(x2,y1)
| |
| |
(x1,y2)____(x2,y2)
Tags (optional parameter):
* It could be a normal string
* A string with '\n'
* A list of strings
* None / '' / [] / False
"""
selector.add_zone((x1,y1,x2,y2),tags=tag)
最后,当您要绘制所有矩形时,请执行:
edited_frame = selector.draw(frame)
如果您想多次使用同一个对象,可以很容易地更改其中的内容:
# This method could help change rectangles to
selector.set_range_valid_rectangles( origin, destination)
# This method could help if you know exactly the indexes that you want to keep
# Default = [], so if you just want to clean the buffer call this method without parameters
set_valid_rectangles(indexes)
如果需要,您可以看到示例detect_faces.py,它还使用名为face_recognition
的开源库。