zoukankan      html  css  js  c++  java
  • 检测中心

    检测每个形状的轮廓并计算中心:

    转换为灰度:cv2.cvtColor()→高斯滤波cv2.GaussianBlur()→图像二元化cv2.thresholod()

     1 import imutils
     2 import cv2
     3 
     4 #通过cv2.imread()直接获取函数
     5 img = cv2.imread("C:/Users/15212/Desktop/python/example_shapes.png")
     6 
     7 #转换为灰度图
     8 gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
     9 
    10 #高斯滤波->模糊以减少高频噪音
    11 blurred = cv2.GaussianBlur(gray, (5,5), 0)
    12 
    13 #图像二元化
    14 thresh = cv2.threshold(blurred, 60, 255, cv2.THRESH_BINARY)[1]
    15 
    16 #显示图像
    17 cv2.namedWindow("sss",cv2.WINDOW_NORMAL)
    18 cv2.imshow("sss",thresh)
    19 
    20 cv2.waitKey(0)
    21 cv2.destroyAllWindows()

    输入不同的图像有不同的结果:

     

    复现代码后:

     提问:为何自己的图片达不到这种效果?

  • 相关阅读:
    POJ1045 Bode Plot
    POJ1044 Date bugs
    POJ1043 What's In A Name?
    POJ1042 Gone Fishing
    POJ1041 John's trip
    POJ1040 Transportation
    POJ1039 Pipe
    background-size属性
    一些CSS的备忘
    only-child选择器
  • 原文地址:https://www.cnblogs.com/isadoraytwwt/p/15024484.html
Copyright © 2011-2022 走看看