Practical combat | OpenCV traditional method to implement dense circle segmentation and counting (detailed steps + y source code)

Introduction

    This article mainly introduces the application of dense circle segmentation and counting based on the traditional method of OpenCV, and gives detailed steps and code.

Background introduction

    The example picture comes from the Internet. The goal is to segment and count the circular targets in the picture below.

picture

    The effect of this article is as follows:

picture

Implementation steps

  【1】Grayscale conversion + mean filtering + binarization to obtain the reference background

img = cv2.imread('src.jpg')cv2.imshow("src",img)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)cv2.imshow("gray",gray)
blur = cv2.medianBlur(gray,7)cv2.imshow("blur",blur)
_,thres = cv2.threshold(gray, 199, 255, cv2.THRESH_BINARY_INV )cv2.imshow("thresh",t

Guess you like

Origin blog.csdn.net/stq054188/article/details/135008077