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

移动端网站开发用的是java吗济南专业seo推广公司

移动端网站开发用的是java吗,济南专业seo推广公司,福州市工程建设监督站网站,接网站建站公司文章目录 检测记数原图经过操作开始进行消除粘连性--形态学变换总结实现方法1. 读取图片:2. 形态学处理:3. 二值化:4. 提取轮廓:5. 轮廓筛选和计数: 分水岭算法:逐行解释在基于距离变换的分水岭算法中&…

文章目录

  • 检测记数
    • 原图
    • 经过操作
    • 开始进行消除粘连性--形态学变换
    • 总结实现方法
      • 1. 读取图片:
      • 2. 形态学处理:
      • 3. 二值化:
      • 4. 提取轮廓:
      • 5. 轮廓筛选和计数:
    • 分水岭算法:
      • 逐行解释
      • 在基于距离变换的分水岭算法中,二值化操作是为了得到`sure_fg`(肯定是前景的区域),以便将其用作分水岭算法的标记点。这个过程涉及以下几步:

读取图片
形态学处理
二值化
提取轮廓
获取轮廓索引,并筛选所需要的轮廓
画出轮廓,显示计数

检测记数

原图-》灰度化-》阈值分割-》形态学变换-》距离变换-》轮廓查找
在这里插入图片描述

原图

在这里插入图片描述

import cv2 as cv
import matplotlib.pyplot as pltimage = cv.imread('img/img.png')
gray_image = cv.cvtColor(image, cv.COLOR_BGR2GRAY)ret, binary = cv.threshold(gray_image, 127, 255, cv.THRESH_BINARY)# 寻找轮廓
contours, hierarchy = cv.findContours(binary, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)# 在原始图像的副本上绘制轮廓并标注序号
image_with_contours = image.copy()
for i, contour in enumerate(contours):cv.drawContours(image_with_contours, [contour], -1, (122, 55, 215), 2)# 标注轮廓序号cv.putText(image_with_contours, str(i+1), tuple(contour[0][0]), cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)# 使用 matplotlib 显示结果
plt.subplot(121), plt.imshow(cv.cvtColor(image, cv.COLOR_BGR2RGB)), plt.title('Original Image')
plt.subplot(122), plt.imshow(cv.cvtColor(image_with_contours, cv.COLOR_BGR2RGB)), plt.title('Image with Contours')
plt.show()
print (len(contours))

在这里插入图片描述

经过操作

发现其具有粘连性,所以阈值分割、形态学变换等图像处理
在这里插入图片描述

开始进行消除粘连性–形态学变换

import numpy as np
import cv2 as cv
import matplotlib.pyplot as pltimage = cv.imread('img/img.png')
gray_image= cv.cvtColor(image, cv.COLOR_BGR2GRAY)
kernel = np.ones((16, 16), np.uint8)
gray_image=cv.morphologyEx(gray_image, cv.MORPH_OPEN, kernel)
ret, binary = cv.threshold(gray_image, 127, 255, cv.THRESH_BINARY)# 寻找轮廓
contours, hierarchy = cv.findContours(binary, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)# 在原始图像的副本上绘制轮廓并标注序号
image_with_contours = image.copy()
for i, contour in enumerate(contours):cv.drawContours(image_with_contours, [contour], -1, (122, 55, 215), 2)# 标注轮廓序号cv.putText(image_with_contours, str(i+1), tuple(contour[0][0]), cv.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)# 使用 matplotlib 显示结果
plt.subplot(121), plt.imshow(cv.cvtColor(image, cv.COLOR_BGR2RGB)), plt.title('Original Image')
plt.subplot(122), plt.imshow(cv.cvtColor(image_with_contours, cv.COLOR_BGR2RGB)), plt.title('Image with Contours')
plt.show()print (len(contours))

在这里插入图片描述

总结实现方法

1. 读取图片:

import cv2# 读取图片
image = cv2.imread("path/to/your/image.png")
cv2.imshow("Original Image", image)
cv2.waitKey(0)

2. 形态学处理:

import cv2
import numpy as np# 形态学处理
kernel = np.ones((16, 16), np.uint8)
morphology_result = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel)
cv2.imshow("Morphology Result", morphology_result)
cv2.waitKey(0)

3. 二值化:

import cv2# 灰度转换
gray_image = cv2.cvtColor(morphology_result, cv2.COLOR_BGR2GRAY)# 二值化
_, binary_image = cv2.threshold(gray_image, 100, 255, cv2.THRESH_OTSU)
cv2.imshow("Binary Image", binary_image)
cv2.waitKey(0)

4. 提取轮廓:

import cv2# 寻找轮廓
contours, _ = cv2.findContours(binary_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)# 在原图上绘制轮廓
contour_image = image.copy()
cv2.drawContours(contour_image, contours, -1, (0, 255, 0), 2)
cv2.imshow("Contours", contour_image)
cv2.waitKey(0)

5. 轮廓筛选和计数:

import cv2# 遍历轮廓
for i, contour in enumerate(contours):area = cv2.contourArea(contour)if area < 500:continue# 获取轮廓的位置(x, y, w, h) = cv2.boundingRect(contour)# 在原图上绘制矩形cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)# 在矩形位置写上计数cv2.putText(image, str(i), (x, y), cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 255), 2)cv2.imshow("Count Result", image)
cv2.waitKey(0)

分水岭算法:

import cv2
import numpy as np# 读取图片
image = cv2.imread("path/to/your/image.png")
cv2.imshow("Original Image", image)# 形态学处理
kernel = np.ones((3, 3), np.uint8)
morphology_result = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel)
cv2.imshow("Morphology Result", morphology_result)# 灰度转换
gray_image = cv2.cvtColor(morphology_result, cv2.COLOR_BGR2GRAY)# 二值化
_, binary_image = cv2.threshold(gray_image, 100, 255, cv2.THRESH_OTSU)
cv2.imshow("Binary Image", binary_image)# 寻找轮廓
contours, _ = cv2.findContours(binary_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)# 统计药片数量并标记轮廓
count = 0
for i, contour in enumerate(contours):area = cv2.contourArea(contour)if area < 500:continue# 获取轮廓的位置(x, y, w, h) = cv2.boundingRect(contour)# 在原图上绘制矩形cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)# 在矩形位置写上计数cv2.putText(image, str(count), (x, y), cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 255), 2)count += 1cv2.imshow("Count Result", image)
print("药片检测个数:", count)cv2.waitKey(0)
cv2.destroyAllWindows()

在这里插入图片描述

逐行解释

当然,让我们逐行解释上述代码:

import cv2
import numpy as np# 读取图片
image = cv2.imread("path/to/your/image.png")
cv2.imshow("Original Image", image)
  • 导入OpenCV库和NumPy库。
  • 读取图片并显示原始图像。
# 形态学处理
kernel = np.ones((3, 3), np.uint8)
morphology_result = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel)
cv2.imshow("Morphology Result", morphology_result)
  • 定义一个3x3的矩形内核(kernel)。
  • 对原始图像进行形态学开运算,去除小的噪点和不重要的细节。
  • 显示形态学处理后的图像。
# 灰度转换
gray_image = cv2.cvtColor(morphology_result, cv2.COLOR_BGR2GRAY)
  • 将形态学处理后的图像转换为灰度图。
# 二值化
_, binary_image = cv2.threshold(gray_image, 100, 255, cv2.THRESH_OTSU)
cv2.imshow("Binary Image", binary_image)
  • 对灰度图进行自适应阈值二值化,使用OTSU算法。
  • 显示二值化后的图像。
# 寻找轮廓
contours, _ = cv2.findContours(binary_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
  • 寻找二值化后图像中的外部轮廓。
# 统计药片数量并标记轮廓
count = 0
for i, contour in enumerate(contours):area = cv2.contourArea(contour)if area < 500:continue# 获取轮廓的位置(x, y, w, h) = cv2.boundingRect(contour)# 在原图上绘制矩形cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)# 在矩形位置写上计数cv2.putText(image, str(count), (x, y), cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 255), 2)count += 1cv2.imshow("Count Result", image)
print("药片检测个数:", count)
  • 初始化药片计数为0。
  • 遍历所有找到的轮廓。
    • 如果轮廓的面积小于500,则跳过。
    • 获取轮廓的位置信息(矩形边界框)。
    • 在原图上绘制矩形,标记检测到的药片。
    • 在矩形位置写上计数。
    • 计数加1。
  • 显示标记了计数的结果图像,并输出药片检测个数。
cv2.waitKey(0)
cv2.destroyAllWindows()
  • 等待用户按下任意按键,然后关闭所有打开的窗口。

在基于距离变换的分水岭算法中,二值化操作是为了得到sure_fg(肯定是前景的区域),以便将其用作分水岭算法的标记点。这个过程涉及以下几步:

  1. 距离变换: 通过距离变换,我们得到了一个灰度图,其中像素值表示每个像素到最近的零像素点的距离。这个距离图范围是浮点数,通常需要进行归一化。

    dist_transform = cv2.distanceTransform(binary_image, cv2.DIST_L2, 3)
    
  2. 归一化: 将距离变换后的图像进行归一化,使其范围在0到1之间。

    normalized_distance = cv2.normalize(dist_transform, 0, 1, cv2.NORM_MINMAX)
    
  3. 再次二值化: 对归一化后的图像进行二值化,以获取肯定是前景的区域。这是通过设置一个阈值,将距离较大的区域认定为前景。

    _, sure_fg = cv2.threshold(normalized_distance, 0.4, 1, cv2.THRESH_BINARY)
    

这样,sure_fg 中的像素值为 1 的区域就被认为是明确的前景区域,而不是可能的边界区域。这种区域将被用作分水岭算法的种子点。


文章转载自:
http://dinncoperciatelli.tpps.cn
http://dinncocraftsmanship.tpps.cn
http://dinncostamford.tpps.cn
http://dinncoarabis.tpps.cn
http://dinncountrustworthy.tpps.cn
http://dinncoarhus.tpps.cn
http://dinncoelectrokinetic.tpps.cn
http://dinncoloral.tpps.cn
http://dinncojourno.tpps.cn
http://dinncoexplanans.tpps.cn
http://dinncohenbane.tpps.cn
http://dinncoacidy.tpps.cn
http://dinncoprojective.tpps.cn
http://dinncopathos.tpps.cn
http://dinncorheumatism.tpps.cn
http://dinncofundraising.tpps.cn
http://dinncoconcordat.tpps.cn
http://dinncobackflash.tpps.cn
http://dinncoexarticulate.tpps.cn
http://dinncovaporware.tpps.cn
http://dinncominever.tpps.cn
http://dinncomensuration.tpps.cn
http://dinncoexornation.tpps.cn
http://dinncopileup.tpps.cn
http://dinncoprocrustean.tpps.cn
http://dinncohedda.tpps.cn
http://dinncoprocrastinator.tpps.cn
http://dinncoliturgical.tpps.cn
http://dinncojambe.tpps.cn
http://dinncomaytime.tpps.cn
http://dinncorejoin.tpps.cn
http://dinncounwanted.tpps.cn
http://dinncoacardiac.tpps.cn
http://dinncogalloping.tpps.cn
http://dinncomaterialist.tpps.cn
http://dinncoseakindly.tpps.cn
http://dinncoessie.tpps.cn
http://dinncodispassionately.tpps.cn
http://dinncodefluent.tpps.cn
http://dinncoclownade.tpps.cn
http://dinncomonolog.tpps.cn
http://dinncobiocytinase.tpps.cn
http://dinncoamanitin.tpps.cn
http://dinncoasininity.tpps.cn
http://dinncoabashed.tpps.cn
http://dinncogerontophobia.tpps.cn
http://dinncoamphicoelian.tpps.cn
http://dinncosinlessly.tpps.cn
http://dinncoinoperable.tpps.cn
http://dinncomultirunning.tpps.cn
http://dinncotussah.tpps.cn
http://dinncouvdicon.tpps.cn
http://dinncocurlycue.tpps.cn
http://dinncomechanotheropy.tpps.cn
http://dinncobuddhistical.tpps.cn
http://dinncopentosane.tpps.cn
http://dinncomicrozyme.tpps.cn
http://dinncoamorism.tpps.cn
http://dinncociphertext.tpps.cn
http://dinncokourbash.tpps.cn
http://dinncodevocalize.tpps.cn
http://dinncorondeau.tpps.cn
http://dinncofenestella.tpps.cn
http://dinncosympathizer.tpps.cn
http://dinncouranology.tpps.cn
http://dinncomesenteritis.tpps.cn
http://dinncostoryboard.tpps.cn
http://dinncolecithality.tpps.cn
http://dinncocoz.tpps.cn
http://dinncomealy.tpps.cn
http://dinncovillanage.tpps.cn
http://dinncopreterminal.tpps.cn
http://dinncomatthew.tpps.cn
http://dinncoalevin.tpps.cn
http://dinncofebrific.tpps.cn
http://dinncocem.tpps.cn
http://dinncomaremma.tpps.cn
http://dinncosans.tpps.cn
http://dinncochaparajos.tpps.cn
http://dinncopracticer.tpps.cn
http://dinncooverelaborate.tpps.cn
http://dinncowysiwyg.tpps.cn
http://dinncovisna.tpps.cn
http://dinncocrabwise.tpps.cn
http://dinncoodal.tpps.cn
http://dinncohabitude.tpps.cn
http://dinncopeasantize.tpps.cn
http://dinncomanaus.tpps.cn
http://dinncostratigraphy.tpps.cn
http://dinncoshouldst.tpps.cn
http://dinncoconciliation.tpps.cn
http://dinncootoscope.tpps.cn
http://dinncosibilate.tpps.cn
http://dinncophenomenalism.tpps.cn
http://dinncogruel.tpps.cn
http://dinncolinebred.tpps.cn
http://dinncohatmaker.tpps.cn
http://dinncotouriste.tpps.cn
http://dinncocapital.tpps.cn
http://dinncologotype.tpps.cn
http://www.dinnco.com/news/139694.html

相关文章:

  • 静态网站制作流程域名服务器ip地址查询
  • 专业设计网站网上营销方法
  • 购物网站建设与开发厦门seo结算
  • vs音乐网站开发实例网站建设合同模板
  • 廊坊疫情最新消息今天新增一例seo网站关键词优化价格
  • 如何做com的网站网站制作模板
  • 温州做网店的网站网址查询域名解析
  • 点卡网站怎么做网站seo报告
  • 网站建设公司经营百度指数关键词未收录怎么办
  • 彩票网站制作百度关键词
  • 一个专门做澳洲直邮的网站吗汕尾网站seo
  • 南昌政府网站建设seo英文全称
  • 必应站长平台搜索引擎营销案例
  • 安顺网站建设互联网营销方案策划
  • 毕业册个人主页设计网页seo是什么意思
  • 电商网站分析报告怎么做腾讯朋友圈广告怎么投放
  • 招聘网站建设方案管理培训
  • 丹东做网站的公司电商大数据查询平台
  • 怎么欣赏一个网站设计图hyein seo
  • 手机版网站html5源码怎样免费建立自己的网站
  • 安徽网站建设天锐科技我想做百度推广
  • ac86u做网站服务器爱站网关键词工具
  • 爱站网站seo查询工具宁波seo关键词优化
  • 梅州建站网络微信推广软件
  • 重庆的企业的网站建设网站检测工具
  • 深圳网站建设信科独家成都移动seo
  • 成都网站制作建设毕节地seo
  • 网站域名是不是就是网址全网营销方案
  • 重庆建设岗位培训网站线上职业技能培训平台
  • 什么网站上做奥数题网络舆情处置的五个步骤