当前位置: 首页 > news >正文

dedecms网站模板软文类型

dedecms网站模板,软文类型,数字营销证书,陕西企尚网络科技有限公司一、找轮廓 cv2.findContours() contours,hierarchy cv2.findContours(image*,mode*,method*) contours:找到的所有轮廓数组,数组内的元素为轮廓像素点坐标。 hierarchy:轮廓间的层次关系。 image:二值图像(cv2.t…

一、找轮廓 cv2.findContours()

contours,hierarchy = cv2.findContours(image=*,mode=*,method=*)

contours:找到的所有轮廓数组,数组内的元素为轮廓像素点坐标。

hierarchy轮廓间的层次关系。

image:二值图像(cv2.threshold())。

mode:轮廓检测模式,常见方法如下:

模式解释
RETR_EXTERNAL0只检测外部轮廓
RETR_LIST1检测所有轮廓,但不建立层级关系
RETR_CCOMP2检测所有轮廓,同时建立两个层级关系,如果内部还有轮廓则此轮廓与最外层轮廓同级
RETR_TREE3检测所有轮廓,同时建立一个树状层级关系

method:保存轮廓的方法,常见方法如下:

方法解释
CHAIN_APPROX_NONE1存储所有轮廓点坐标
CHAIN_APPROX_SIMPLE2只保存轮廓顶点坐标
CHAIN_APPROX_TC89L13使用CHAIN_APPROX_TC89L1 近视算法保存轮廓坐标
CHAIN_APPROX_TC89KCOS4使用CHAIN_APPROX_TC89KCOS近视算法保存轮廓坐标

二、绘轮廓 cv2.drawContours()

img = cv2.drawContours(image=*,contours=,contourIdx=*,color=*,thickness=*,lineType=*,hierarchy=*,maxLevel=*,offset=*)

 img:目标图像。

image:二值图像,用于填画上轮廓。

contours:cv2.findContours()函数返回的轮廓列表 list。

contourIdx:需要绘制的轮廓,在轮廓列表中的索引。-1 表示绘制列表中的所有轮廓。

color:(B,G,R)颜色。

thickness:轮廓粗细,-1 表示实心。

lineType:线条类型。

hierarchy:cv2.findContours() 输出的层次关系。

maxLevel:轮廓层次关系的深度,0表示绘制第0层次关系的轮廓。

offset:常数值,轮廓偏移量(相较于原轮廓坐标)

三、检测模式 

3.1 外轮廓 RETR_EXTERNAL

import cv2
# 图像前处理
img = cv2.imread('contours.png')  # 原图
img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)  # GRAY
thresh,img_threshold = cv2.threshold(img_gray,150,255,cv2.THRESH_BINARY)  # 二值contours,hierarchy = cv2.findContours(img_threshold,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
img1 = cv2.drawContours(img,contours,-1,(255,0,0),3)cv2.imshow('img',img)
cv2.imshow('img_threshold',img_threshold)
cv2.waitKey(0)
cv2.destroyAllWindows()

 3.2 所有轮廓 cv2.RETR_LIST

import cv2
# 图像前处理
img = cv2.imread('contours.png')  # 原图
img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)  # GRAY
thresh,img_threshold = cv2.threshold(img_gray,150,255,cv2.THRESH_BINARY)  # 二值contours,hierarchy = cv2.findContours(img_threshold,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
img1 = cv2.drawContours(img,contours,-1,(255,0,0),2)cv2.imshow('img',img)
cv2.imshow('img_threshold',img_threshold)
cv2.waitKey(0)
cv2.destroyAllWindows()

 3.3 RETR_CCOMP

import cv2
import numpy as np# 图像前处理
img = cv2.imread('m.png')  # 原图
img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)  # GRAY
thresh,img_threshold = cv2.threshold(img_gray,150,255,cv2.THRESH_BINARY)  # 二值contours,hierarchy = cv2.findContours(img_threshold,cv2.RETR_CCOMP,cv2.CHAIN_APPROX_SIMPLE)
print(hierarchy)
img1 = cv2.drawContours(img,contours,-1,(255,0,0),2)cv2.imshow('img',img)
cv2.imshow('img_threshold',img_threshold)
cv2.waitKey(0)
cv2.destroyAllWindows()

 hierarchy:详细解释请参考:《OpenCV计算机视觉项目实战(Python版)---p265》

print(hierarchy)结果
[[[ 1 -1 -1 -1][-1  0  2 -1][ 3 -1 -1  1][-1  2 -1  1]]]

 3.4 RETR_TREE

import cv2
import numpy as np# 图像前处理
img = cv2.imread('m.png')  # 原图
img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)  # GRAY
thresh,img_threshold = cv2.threshold(img_gray,150,255,cv2.THRESH_BINARY)  # 二值contours,hierarchy = cv2.findContours(img_threshold,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
print(hierarchy)
img1 = cv2.drawContours(img,contours,-1,(255,0,0),2)cv2.imshow('img',img)
cv2.imshow('img_threshold',img_threshold)
cv2.waitKey(0)
cv2.destroyAllWindows()

  hierarchy:详细解释请参考:《OpenCV计算机视觉项目实战(Python版)---p265》

print(hierarchy) 结果:
[[[-1 -1  1 -1][ 3 -1  2  0][-1 -1 -1  1][-1  1 -1  0]]]

四、轮廓面积、周长

4.1 面积 cv2.contourArea()

area = cv2.contourArea(contour=*,oriented=*)

area:轮廓面积。

countour:要计算轮廓。

oriented:默认为:False,换回面积的绝对值。

import cv2
import numpy as np# 图像前处理
img = cv2.imread('contours.png')  # 原图
img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)  # GRAY
thresh,img_threshold = cv2.threshold(img_gray,150,255,cv2.THRESH_BINARY)  # 二值contours,hierarchy = cv2.findContours(img_threshold,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
img1 = cv2.drawContours(img,contours,-1,(255,0,0),2)
areas = []
for i in range(len(contours)):area = cv2.contourArea(contours[i])areas.append(area)
print(areas)
cv2.waitKey(0)
cv2.destroyAllWindows()
[8500.5, 15986.0, 11396.0, 11560.0, 7136.5]

4.2  面积 cv2.arcLength()

arc = cv2.arcLength(contours,closed=*)

arc:轮廓周长。

countours:要计算轮廓。

closed:Ture表示轮廓是封闭的。

import cv2
import numpy as np# 图像前处理
img = cv2.imread('contours.png')  # 原图
img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)  # GRAY
thresh,img_threshold = cv2.threshold(img_gray,150,255,cv2.THRESH_BINARY)  # 二值contours,hierarchy = cv2.findContours(img_threshold,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
img1 = cv2.drawContours(img,contours,-1,(255,0,0),2)
areas = []
for i in range(len(contours)):arc = cv2.arcLength(contours[i],closed=True)areas.append(arc)
print(areas)
cv2.waitKey(0)
cv2.destroyAllWindows()
[437.9482728242874, 492.6173119544983, 696.3086559772491, 403.98989498615265, 558.1147834062576]

http://www.hkea.cn/news/617703/

相关文章:

  • 网站建设公司怎样拓展网站业务大连网站推广
  • 什么网站可以免费做找客户东莞seo建站推广费用
  • 合肥微信网站建设购物网站如何推广
  • 网站建设课程简介图片百度官网认证免费
  • 月夜影视在线观看免费完整版韩剧关键词排名优化报价
  • 做网站的工作时间兰州seo公司
  • css怎么嵌入到html直通车关键词优化口诀
  • 虚拟网站php专业型seo网站关键词排名提升
  • 找人合伙做网站平台b2b电商平台
  • 手机网站建设技术方案找网站设计公司
  • 杭州如何设计公司网站惠州seo网站推广
  • 成都网站建设门户大连企业网站建站模板
  • 游戏卡充值可以做网站吗百度竞价关键词出价技巧
  • 建设企业网站就等于开展网络营销网店推广实训报告
  • dede无法更新网站主页到百度联盟注册
  • wordpress支持爱奇艺企业网站seo托管怎么做
  • 永川做网站的武汉百度快速排名提升
  • 做网站的故意给中病毒网络营销广告
  • 关于阅读类网站的建设规划书友情链接系统
  • 专业做幼儿园设计的网站百度小程序关键词优化
  • 腾龙时时彩做号网站整站优化关键词排名
  • 正规的网站制作与推广百度广告运营
  • 网站建设估价引擎搜索有哪些
  • 东莞网站建设选菲凡网络如何制作网站
  • 网站收录系统备案查询官网
  • 临朐县网站建设利用搜索引擎营销成功的案例
  • 利用网盘做视频网站镇江优化推广
  • 视频微网站开发哪个公司网站设计好
  • 品网站建设智能搜索引擎
  • 怎样在百度建网站seo建设者