美文网首页大数据 爬虫Python AI SqlPython小哥哥
Python+OpenCV调用摄像头接口打造家庭安防系统 !

Python+OpenCV调用摄像头接口打造家庭安防系统 !

作者: 14e61d025165 | 来源:发表于2019-05-26 15:11 被阅读1次

问题描述:使用Python+opencv调用笔记本摄像头接口,定期捕捉图像或录制视频并保存为图像文件或视频文件。可以在家里没有人的时候使用该程序监视家中是否有小偷进入或者宠物们有没有搞破坏。

1、安装扩展库numpy和opencv-python,如果后面的代码无法运行,可以把numpy和opencv都更新到最新版本。

<tt-image data-tteditor-tag="tteditorTag" contenteditable="false" class="syl1558854632472 ql-align-center" data-render-status="finished" data-syl-blot="image" style="box-sizing: border-box; cursor: text; text-align: left; color: rgb(34, 34, 34); font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; display: block;"> image

<input class="pgc-img-caption-ipt" placeholder="图片描述(最多50字)" value="" style="box-sizing: border-box; outline: 0px; color: rgb(102, 102, 102); position: absolute; left: 187.5px; transform: translateX(-50%); padding: 6px 7px; max-width: 100%; width: 375px; text-align: center; cursor: text; font-size: 12px; line-height: 1.5; background-color: rgb(255, 255, 255); background-image: none; border: 0px solid rgb(217, 217, 217); border-radius: 4px; transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) 0s;"></tt-image>

Python学习交流群:1004391443,这里有资源共享,技术解答,还有小编从最基础的Python资料到项目实战的学习资料都有整理,希望能帮助你更了解python,学习python

2、编写代码

<tt-image data-tteditor-tag="tteditorTag" contenteditable="false" class="syl1558854632478 ql-align-center" data-render-status="finished" data-syl-blot="image" style="box-sizing: border-box; cursor: text; text-align: left; color: rgb(34, 34, 34); font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; display: block;"> image

<input class="pgc-img-caption-ipt" placeholder="图片描述(最多50字)" value="" style="box-sizing: border-box; outline: 0px; color: rgb(102, 102, 102); position: absolute; left: 187.5px; transform: translateX(-50%); padding: 6px 7px; max-width: 100%; width: 375px; text-align: center; cursor: text; font-size: 12px; line-height: 1.5; background-color: rgb(255, 255, 255); background-image: none; border: 0px solid rgb(217, 217, 217); border-radius: 4px; transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) 0s;"></tt-image>

3、关闭摄像头防偷拍功能,具体到我的笔记本上,就是把摄像头上的创可贴揭下来。

<tt-image data-tteditor-tag="tteditorTag" contenteditable="false" class="syl1558854632483 ql-align-center" data-render-status="finished" data-syl-blot="image" style="box-sizing: border-box; cursor: text; text-align: left; color: rgb(34, 34, 34); font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; display: block;"> image

<input class="pgc-img-caption-ipt" placeholder="图片描述(最多50字)" value="" style="box-sizing: border-box; outline: 0px; color: rgb(102, 102, 102); position: absolute; left: 187.5px; transform: translateX(-50%); padding: 6px 7px; max-width: 100%; width: 375px; text-align: center; cursor: text; font-size: 12px; line-height: 1.5; background-color: rgb(255, 255, 255); background-image: none; border: 0px solid rgb(217, 217, 217); border-radius: 4px; transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) 0s;"></tt-image>

4、运行代码,每5秒钟自动捕捉一次当前图像,保存为文件备查。

<tt-image data-tteditor-tag="tteditorTag" contenteditable="false" class="syl1558854632487 ql-align-center" data-render-status="finished" data-syl-blot="image" style="box-sizing: border-box; cursor: text; text-align: left; color: rgb(34, 34, 34); font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; display: block;"> image

<input class="pgc-img-caption-ipt" placeholder="图片描述(最多50字)" value="" style="box-sizing: border-box; outline: 0px; color: rgb(102, 102, 102); position: absolute; left: 187.5px; transform: translateX(-50%); padding: 6px 7px; max-width: 100%; width: 375px; text-align: center; cursor: text; font-size: 12px; line-height: 1.5; background-color: rgb(255, 255, 255); background-image: none; border: 0px solid rgb(217, 217, 217); border-radius: 4px; transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) 0s;"></tt-image>

5、改进代码。前面的代码虽然可以工作,但是运行程序后摄像头一直处于占用状态,对于突发式的拍照应用不是很合适,代码改为下面的样子,每次拍照之前再打开摄像头,拍照之后立刻关闭。

<tt-image data-tteditor-tag="tteditorTag" contenteditable="false" class="syl1558854632492 ql-align-center" data-render-status="finished" data-syl-blot="image" style="box-sizing: border-box; cursor: text; text-align: left; color: rgb(34, 34, 34); font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; display: block;"> image

<input class="pgc-img-caption-ipt" placeholder="图片描述(最多50字)" value="" style="box-sizing: border-box; outline: 0px; color: rgb(102, 102, 102); position: absolute; left: 187.5px; transform: translateX(-50%); padding: 6px 7px; max-width: 100%; width: 375px; text-align: center; cursor: text; font-size: 12px; line-height: 1.5; background-color: rgb(255, 255, 255); background-image: none; border: 0px solid rgb(217, 217, 217); border-radius: 4px; transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) 0s;"></tt-image>

6、录像模式。前面的代码每隔5秒钟捕捉一次当前图像,如果要录像并保存文件,可以使用下面的代码。

<tt-image data-tteditor-tag="tteditorTag" contenteditable="false" class="syl1558854632498 ql-align-center" data-render-status="finished" data-syl-blot="image" style="box-sizing: border-box; cursor: text; text-align: left; color: rgb(34, 34, 34); font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; display: block;"> image

<input class="pgc-img-caption-ipt" placeholder="图片描述(最多50字)" value="" style="box-sizing: border-box; outline: 0px; color: rgb(102, 102, 102); position: absolute; left: 187.5px; transform: translateX(-50%); padding: 6px 7px; max-width: 100%; width: 375px; text-align: center; cursor: text; font-size: 12px; line-height: 1.5; background-color: rgb(255, 255, 255); background-image: none; border: 0px solid rgb(217, 217, 217); border-radius: 4px; transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) 0s;"></tt-image>

7、运行程序,捕捉几段录像。

<tt-image data-tteditor-tag="tteditorTag" contenteditable="false" class="syl1558854632503 ql-align-center" data-render-status="finished" data-syl-blot="image" style="box-sizing: border-box; cursor: text; text-align: left; color: rgb(34, 34, 34); font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", "Helvetica Neue", Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; display: block;"> image

<input class="pgc-img-caption-ipt" placeholder="图片描述(最多50字)" value="" style="box-sizing: border-box; outline: 0px; color: rgb(102, 102, 102); position: absolute; left: 187.5px; transform: translateX(-50%); padding: 6px 7px; max-width: 100%; width: 375px; text-align: center; cursor: text; font-size: 12px; line-height: 1.5; background-color: rgb(255, 255, 255); background-image: none; border: 0px solid rgb(217, 217, 217); border-radius: 4px; transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1) 0s;"></tt-image>

相关文章

  • Python+OpenCV调用摄像头接口打造家庭安防系统 !

    问题描述:使用Python+opencv调用笔记本摄像头接口,定期捕捉图像或录制视频并保存为图像文件或视频文件。可...

  • 广州智能家居无线安防视频监控系统解决方案

    隽智智能发布无线家庭安防视频监控系统一站式解决方案,打造广州智能家居无线家庭安防监控,为室内室外应用场景提供灵活的...

  • 摄像头基础架构一

    安防摄像头、家用摄像头;芯片厂家有华为海思、安霸、TI等;通常采用linux作为系统。摄像头往往为了降低成本,硬件...

  • 调用本地相机

    UIImagePickerController 是系统提供的用来获取图片和视频的接口。 它可以直接 调用摄像头拍照...

  • 米家烟雾报警器评测

    家庭安全问题越来越受到广大消费者的关注,但是大多数家庭对于安防只想到了监控摄像头。其实,家庭安防还有一个很重要的部...

  • 8月12日西安王敏日清

    今天我们坐大巴去胶州星月海尔智慧家庭体验馆学习。今天学习了海尔的智慧家庭的产品及安防三大系统:安防系统,净水系统,...

  • 家庭安防领域“新势力” 二维码门禁兴起!

    在过去几年时间里,我们在谈到家庭安防的时候,更多的是从家用摄像头说起,摄像头搭载手机APP可作为用户远程看家(防小...

  • ios 摄像头应用+相册

    本文介绍一些关于摄像头和相册的基本用法,在调用摄像头之前,不要忘记检测摄像头是否可用;首先导入系统文件 调用系统摄...

  • 外贸行业CCTV摄像头采购商分析

    安防工程商 安防工程的承包商,从事CCTV,门禁等各种安防工程的设计与安装维护,适合中国安防摄像头、指纹、门禁卡、...

  • 当家小卫士——小豚当家AI全彩摄像头体验

    【前言】 对于许多家庭,尤其是有老人或者小孩的家庭,越来越亲睐于家庭安防产品。而家庭智能摄像头作为智能家居的组成部...

网友评论

    本文标题:Python+OpenCV调用摄像头接口打造家庭安防系统 !

    本文链接:https://www.haomeiwen.com/subject/onzxtctx.html