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

360提交网站备案青岛网站关键词排名优化

360提交网站备案,青岛网站关键词排名优化,做网站 收费,做得好的营销网站一、找轮廓 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.yidumall.com/news/10026.html

相关文章:

  • 网站建设都分几个阶段seo搜索优化是什么呢
  • 全能网站建设百度联系方式
  • 零基础学计算机难吗资深seo顾问
  • 网站开发bs架构seo广告投放是什么意思
  • 太原公司注册厦门seo外包公司
  • 免费网站打包app网页制作软件免费版
  • 做网站公司牛鼻子软件外包公司排行
  • 海南住房与建设厅网站旺道seo推广
  • 网站出错咨询电话外链工具xg下载
  • 拿p5.js做的网站培训课程设计
  • 做情书直接点网站泉州网站seo外包公司
  • 文山网站建设哪家好网络推广网络营销软件
  • 网站建设优化托管网络推广方案七步法
  • 怎么把一个网站设置成首页东莞seo整站优化
  • 工程建设管理重庆seo优化效果好
  • wordpress数据控查看密码关键词搜索优化公司
  • 做一套网站开发多少钱怎么在百度发布自己的文章
  • 青岛网站建设多少钱上海网络推广公司
  • 公司旅游视频网站模板华为手机网络营销策划方案
  • 建立自己的网站平台的好处免费p站推广网站入口
  • 仿牌做外贸建网站北京seo招聘
  • 哪些公司的网站做的很好盐城网站优化
  • 用竹片做的网站百度免费发布信息网站
  • 站长工具韩国日本中南建设集团有限公司
  • 宁波网站建设最好免费找精准客户的app
  • 网站设计定制关键词大全
  • 怎么做百度网盘链接网站全面网络推广营销策划
  • 教育网站制作哪个好软件开发公司排行榜
  • 秦皇岛网站推广最近发生的重大新闻事件
  • 那个网站可以做司考真题seo工具有哪些