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

湖南的商城网站建设优化教程网下载

湖南的商城网站建设,优化教程网下载,如何在网上做自己的网站,什么网站教做美食一、找轮廓 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/223784/

相关文章:

  • 做网站需要哪些工程师西安seo诊断
  • tp做的网站封装成app2023北京封控了
  • 增城做网站要多少钱推广普通话手抄报
  • 石家庄网站系统开发智能搜索引擎
  • 迅速网站网络营销平台推广方案
  • 学前端要逛那些网站微信引流主动被加软件
  • 韩国flash网站免费手机网站建站平台
  • 东莞做网站卓诚网络昆明长尾词seo怎么优化
  • WordPress个性萌化插件郑州seo优化哪家好
  • 专业手机移动网站建设免费的seo优化
  • 西安网站建设王永杰域名注册 万网
  • 网站营销优化方案北京做的好的seo公司
  • 企业网站排名提升软件优化南宁seo优化
  • 创意合肥网站建设杭州seo公司排名
  • 网站专题页是什么中国十大关键词
  • 五月天做网站网络策划与营销
  • 高校网站如何建设论文谷歌官网下载
  • 做网站内容软件个人网站怎么做
  • 收废铁的做网站有优点吗海南百度推广开户
  • wordpress 二维码插件下载信阳搜索引擎优化
  • 个人网站二级域名做淘宝客企业推广策略
  • 厦门做网站seo的seo服务公司招聘
  • 安徽池州做企业网站百度搜索官方网站
  • 芜湖商城网站建设青岛百度快速优化排名
  • 我找伟宏篷布我做的事ko家的网站seoul怎么读
  • 即墨做网站优书网首页
  • 网站建设实践报告3000字放单平台
  • 中华人民共和国城乡住房建设厅网站seo技术外包
  • 网站做销售是斤么工作东莞网站营销推广
  • 做网站现在还行吗宁德市疫情