OpenCV 您所在的位置:网站首页 OpenCV快速入门面向python OpenCV

OpenCV

#OpenCV| 来源: 网络整理| 查看: 265

OpenCV-Python小应用(四):红绿灯检测

* – 前言 – 前提条件 – 实验环境 – 红绿灯检测 – 参考文献

前言 本文是个人使用OpenCV-Python的应用案例,由于水平有限,难免出现错漏,敬请批评改正。 更多精彩内容,可点击进入 OpenCV-Python小应用专栏或我的个人主页查看 前提条件 熟悉Python 实验环境 Python 3.6.13 (面向对象的高级语言) OpenCV 3.4.10(python第三方库) pip3 install opencv-python==3.4.10.37 红绿灯检测 主要思路:使用传统的HSV颜色空间对颜色进行提取和定位。这属于传统算法的范畴,有一定的局限性。 HSV颜色空间相关知识点,可查阅OpenCV-Python快速入门(四):色彩空间

OpenCV-Python小应用(四):红绿灯检测 import cv2 import numpy as np img=cv2.imread("light3.png") minRed = np.array([0, 127, 128]) maxRed = np.array([10, 255, 255]) minGreen = np.array([50,100,20]) maxGreen = np.array([90,255,200]) img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) mask_red = cv2.inRange(img_hsv, minRed, maxRed) mask_green = cv2.inRange(img_hsv, minGreen, maxGreen) contours1, hierarchy1 = cv2.findContours(mask_red, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) contours2, hierarchy2 = cv2.findContours(mask_green, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) for cnt in contours1: (x, y, w, h) = cv2.boundingRect(cnt) if w*h < 20*20: continue cv2.rectangle(img, (x, y), (x + w, y + h), (255, 255, 255), 2) cv2.putText(img, 'red_light', (x, y - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 255), 2) for cnt in contours2: (x, y, w, h) = cv2.boundingRect(cnt) if w*h < 20*20: continue cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2) cv2.putText(img, 'green_light', (x, y - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.6,(0, 255, 0) , 2) cv2.imshow('res', img) cv2.waitKey(0) cv2.destroyAllWindows()

OpenCV-Python小应用(四):红绿灯检测 参考文献

[1] https://opencv.org/[2] 李立宗. OpenCV轻松入门:面向Python. 北京: 电子工业出版社,2019

更多精彩内容,可点击进入 OpenCV-Python小应用专栏或我的个人主页查看

Original: https://blog.csdn.net/FriendshipTang/article/details/127942594Author: FriendshipTTitle: OpenCV-Python小应用(四):红绿灯检测

相关阅读 Title: 使用yagmail发送邮件 一.yagmail基本数据准备

1.终端下载yagmail:pip install yagmail

2.获取SMTP和密钥

我们以新浪邮箱为例,登录成功后进入设置页面,点击客户端pop/imap/smtp分类栏,会看见IMAP4服务/SMTP服务

使用yagmail发送邮件

SMTP就是客户端设置下SMTP服务器的值,密钥的话在你开启服务状态成功后会弹出(如果原本就是开启状态,需先

关闭后再开启)。

二.发送正文

1.与邮箱服务器建立连接

python;gutter:true; smtps = yagmail.SMTP(user='[email protected]', password='密钥', host='SMTP服务器') # 建立连接

user:你的邮箱地址 password:密钥值,不是邮箱密码 host:SMTP值 2.通过send()方法发送邮件 ;gutter:true;smtps.send(to="[email protected]", subject="标题", contents="正文")

to:指定接收人的邮箱

subject:邮件标题

contents:邮件正文内容

3.contents属性

1)可直接输入发送的内容或图片以及文件地址,会自动识别传递的内容格式,若是图片/文件会以附件的方式发送给目标邮箱

2)可将内容格式编辑在文件中,直接读取文件内容发送

python;gutter:true; with open("./txt/yag.txt", mode="r", encoding="utf-8")as a: data = a.read() smtps.send(to="[email protected]", subject="标题", contents=data)

4.关闭连接 ;gutter:true;smtps.close()

三.发送附件

1.发送单个附件

python;gutter:true; smtps.send(to="[email protected]", subject="标题", contents="正文",attachments="文件地址")

attachments:附件 2.发送多个附件 ;gutter:true;att_list = [‘./img/base64.png’, ‘yag.txt’]smtps.send(to="[email protected]", subject="标题", contents="正文", attachments=att_list)

attachments:可传list

四.收件人起别名

python;gutter:true; reci = { '[email protected]': "qq" # 取别名 } smtps.send(to=reci, subject="标题", contents="正文")

若发送多个邮箱都起别名的话,可在reci中添加多个 ### 五.多人发送 ;gutter:true;to_list = [‘[email protected]’, ‘[email protected]’]smtps.send(to=to_list, subject="标题", contents="正文")

to:可传递list

六.多人抄送和密抄

python;gutter:true; cc_list = ['[email protected]', '[email protected]'] bcc_list = ['[email protected]'] smtps.send(to="[email protected]", subject="标题", contents="正文",cc=cc_list,bcc=bcc_list)

cc:抄送 bcc:密抄 ### 七.发送html测试报告 1.生成html文件:pytest --html=生成报告的url --self-contained-html 运行用例的.py文件 2.以附件的形式发送 ;gutter:true;smtps.send(to="[email protected]", subject="发送自动化测试报告html", contents="html", attachments="html地址")

文章来源:https://www.cnblogs.com/lihongtaoya/ ,请不要转载

Original: https://www.cnblogs.com/lihongtaoya/p/16725231.htmlAuthor: 傻姑娘家的李先生Title: 使用yagmail发送邮件

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/283947/

转载文章受原作者版权保护。转载请注明原作者出处!



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有