444 lines
11 KiB
Plaintext
444 lines
11 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "8a340f1a-f6d6-4ca5-a8f1-d53f6eafa00e",
|
||
"metadata": {},
|
||
"source": [
|
||
"<a align=\"center\" href=\"https://gitee.com/CV_Lab/opencv_webcam\" target=\"_blank\" alt=\"Simple Icons\" >\n",
|
||
"<img src=\"https://gitee.com/CV_Lab/opencv_webcam/attach_files/932349/download/%E7%81%AB%E7%AE%AD.svg\" width=64 height=64></a>\n",
|
||
"\n",
|
||
"<p>opencv-webcam-script v0.3(Jupyter版)</p>\n",
|
||
"<p>创建人:曾逸夫</p>\n",
|
||
"<p>创建时间:2022-01-16</p>"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "68e88aa6-99c8-42b9-a189-70e42e7e6460",
|
||
"metadata": {},
|
||
"source": [
|
||
"<a href=\"https://pypi.org/project/opencv-webcam-script/0.3.0/\"><img src=\"https://img.shields.io/badge/PyPi-v0.3.0-brightgreen?logo=pypi\" alt=\"PyPi\" /></a>\n",
|
||
"<a href=\"https://gitee.com/CV_Lab/opencv_webcam/releases/v0.3\"><img src=\"https://img.shields.io/badge/Releases-v0.3-green\" alt=\"Releases Version\" /></a>\n",
|
||
"<a href=\"https://hub.docker.com/r/zengdockerdocker/opencv-webcam-script\"><img src=\"https://img.shields.io/badge/docker-v0.3-blue?logo=docker\" alt=\"Docker\" /></a>\n",
|
||
"<a href=\"https://gitee.com/CV_Lab/opencv_webcam/blob/master/tutorial.ipynb\"><img src=\"https://img.shields.io/badge/Jupyter-v0.3-orange?logo=jupyter\" alt=\"Jupyter\" /></a>\n",
|
||
"<a href=\"https://gitee.com/CV_Lab/opencv_webcam/blob/master/LICENSE\"><img src=\"https://img.shields.io/badge/License-GPL--3.0-blue\" alt=\"License\" /></a>"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "5518d6e0-89ca-41d3-8be6-a3c76bc32709",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 安装"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "f25bb221-dee2-499b-8879-f87ab35a9a60",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 克隆、安装依赖"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "89e07b19-7efa-4221-a220-f698b948cee2",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 首先手动创建虚拟环境\n",
|
||
"# conda create -n ow python==3.8 # 虚拟环境名称为ow\n",
|
||
"# conda activate ow # 激活虚拟环境\n",
|
||
"!git clone https://gitee.com/CV_Lab/opencv_webcam.git # 克隆\n",
|
||
"%cd opencv_webcam\n",
|
||
"%pip install -qr requirements.txt -U # 安装"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "b6bbf4a0-db17-4727-96f0-ba6370b7eae6",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 运行"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "6961c53a-a334-4c2a-b8de-1f52ebda8828",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 常规调用"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "58307de4-173b-46a9-b30d-c12cfe4a1de2",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 默认按q键退出\n",
|
||
"!python opencv_webcam.py"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "7ceb44c6-5434-4f28-ae05-fe10d8def815",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 设备选择"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "6bc38dd9-698f-4dbc-8249-2743ac8d3f18",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 多摄像头切换示例,默认为0\n",
|
||
"!python opencv_webcam.py -dev 0\n",
|
||
"!python opencv_webcam.py -dev 1\n",
|
||
"!python opencv_webcam.py -dev 2\n",
|
||
"# RTSP\n",
|
||
"!python opencv_webcam.py -dev rtsp://username:password@xxx.xxx.xxx"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "8bc2584c-ea5f-414f-bb71-1b422b319853",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 设置退出键"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "53eccc33-5076-4158-93b3-1e06fa1d84ec",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 默认按q键退出\n",
|
||
"!python opencv_webcam.py -q z # 设置z键退出\n",
|
||
"!python opencv_webcam.py -q k # 设置k键退出"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "53b53248-4cd5-4221-b632-25b387bdec05",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 自动保存帧"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "f04eab9b-f7fc-42a0-a3df-6d546bcde5d9",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 视频帧自动保存\n",
|
||
"!python opencv_webcam.py -isasf"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "91cc1ea9-ce8d-40e5-aefd-4118696ea018",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 每隔n帧保存一次帧"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "acaf3636-8f83-47af-8161-2614a24cf3cc",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 每隔10帧保存一次帧\n",
|
||
"!python opencv_webcam.py -isasf -fns 10"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "c4587772-b8be-4c07-9469-c71c69d6b020",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 手动保存帧"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "6b564768-4ea4-4081-a9e8-6799dd862ef8",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 默认按a键捕获一帧\n",
|
||
"!python opencv_webcam.py -ishsf"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "f3e924ed-612d-4c1d-873a-786aacc57937",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 自定义捕获键"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "bbf16f8a-50fb-41f6-8c6d-31152ce29217",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 设置z键为捕获键\n",
|
||
"!python opencv_webcam.py -ishsf -fck z"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "0677cd5a-007f-4743-82a8-f533d108e6ba",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 重塑帧尺寸(自定义宽高)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "b5be8596-d7c4-4f30-bdec-b2ac1ab31479",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 重塑宽度300 高度200\n",
|
||
"!python opencv_webcam.py -isasf -isrf -rf 300 200 # 自动版\n",
|
||
"!python opencv_webcam.py -ishsf -isrf -rf 300 200 # 手动版"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "b05047c0-0714-4170-9dea-13b718b1bd5d",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 重塑帧尺寸(自定义宽高缩放比)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "17d4f042-bcf5-4040-9737-ce5b927c13b2",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 宽高缩放比为0.5\n",
|
||
"!python opencv_webcam.py -isasf -isrf -rrf 0.5 # 自动版\n",
|
||
"!python opencv_webcam.py -ishsf -isrf -rrf 0.5 # 手动版"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "6c0bc300-8aa7-4028-aea6-ef806f6c8118",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 自定义保存路径"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "46f48201-9608-4122-a0d0-ac226e46eaac",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 设置保存路径,默认保存路径为./WebcamFrame\n",
|
||
"!python opencv_webcam.py -fsd custom_dir -isasf # 以自动版为例"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "77054e11-6869-49d3-b810-919614c5a25f",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 自定义帧目录名称"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "7cf58077-be7d-4f1b-ab1e-a88004ffbee3",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 设置帧目录名称,默认保存路径为frames\n",
|
||
"!python opencv_webcam.py -fdn frames_custom -isasf # 以自动版为例"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "0078a79f-81a8-4e41-9290-b9349f44fa02",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 自定义帧名前缀"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "5b34e67f-0e25-43ff-aec1-ef3ed74f7fd8",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 设置帧图片的前缀名称\n",
|
||
"!python opencv_webcam.py -isasf -fnp webcam"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "bb695981-2e72-4277-a67b-4b2e0ad1524c",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 设置帧保存格式"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "387d62f8-5e9b-4141-8e90-3d2c13381d57",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 设置JPG质量为100,默认为95\n",
|
||
"!python opencv_webcam.py -isasf -fss jpg -jq 100\n",
|
||
"# 设置PNG质量为5,默认为3\n",
|
||
"!python opencv_webcam.py -isasf -fss png -jq 5"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "c224bfc6-5f9b-42f9-b952-d90106992317",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 设置暂停键"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "7cc860c3-e8a0-4e65-95c1-123f84c21c09",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 设置w键为暂停键,默认为p键\n",
|
||
"!python opencv_webcam.py -p w # 按任意键继续"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "be8a8ff7-d659-4df2-a92b-7ae08879c477",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 设置保存帧数"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "13f16a9e-cc3c-4b41-b23b-6383b36c5c16",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 设置保存100帧\n",
|
||
"!python opencv_webcam.py -isasf -afn 100"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "56a703c9-f0d3-4e98-aca3-8779b13cd6e0",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 日志设置"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "990489b6-1a95-4ca7-bfcc-034cf500281b",
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 日志文件默认保存在项目根目录,test.log\n",
|
||
"!python opencv_webcam.py\n",
|
||
"# 设置日志文件名称及类型,类型包括.log、.txt、.data\n",
|
||
"!python opencv_webcam.py -ln test02.txt\n",
|
||
"# 设置日志保存方式,,默认为追加模式\n",
|
||
"!python opencv_webcam.py -lm w # 设置为覆盖模式"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"id": "129ad574-f290-4a68-b8ce-160c27cdb340",
|
||
"metadata": {},
|
||
"source": [
|
||
"### 指令查询"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"id": "fcb03330-b662-4d49-b302-32c70ec40104",
|
||
"metadata": {
|
||
"tags": []
|
||
},
|
||
"outputs": [],
|
||
"source": [
|
||
"# 查询脚本参数\n",
|
||
"!python opencv_webcam.py --help"
|
||
]
|
||
}
|
||
],
|
||
"metadata": {
|
||
"kernelspec": {
|
||
"display_name": "Python 3 (ipykernel)",
|
||
"language": "python",
|
||
"name": "python3"
|
||
},
|
||
"language_info": {
|
||
"codemirror_mode": {
|
||
"name": "ipython",
|
||
"version": 3
|
||
},
|
||
"file_extension": ".py",
|
||
"mimetype": "text/x-python",
|
||
"name": "python",
|
||
"nbconvert_exporter": "python",
|
||
"pygments_lexer": "ipython3",
|
||
"version": "3.8.12"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 5
|
||
}
|