1.目标-数出有多少个贴纸
好久没更新博客了,最近家里小朋友在一张A3纸上贴了很多水晶贴纸,要让我帮他数有多少个,看上去有点多,贴的也比较随意,于是想着使用Opencv来识别一下有多少个。
原图如下:
代码:
import cv2 import numpy as np from matplotlib import pyplot as plt def count_stars(image_path): # 读取图像 image = cv2.imread(image_path) # # 显示原始图像 # plt.figure() # plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) # plt.title('Original Image') # 转换为灰度图像 gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # # 显示灰度图像 # plt.figure() # plt.imshow(gray, cmap='gray') # plt.title('Gray Image') # 应用高斯模糊以减少噪声 gs=85 blurred = cv2.GaussianBlur(gray, (gs, gs), 0) # # 显示高斯模糊后的图像 # plt.figure() # plt.imshow(blurred, cmap='gray') # plt.title(&