Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Divyanshu Shekhar
Divyanshu Shekhar

Posted on • Edited on

     

Blob Detection OpenCV Python

What is blob? How to detect blobs in an image? In this blog, we are going to learn about blob detection in OpenCV Python.

Blob can be described as groups of connected pixels that all share a common property.

Let’s Code Blob Detection in OpenCV Python!

Blob Detection OpenCV Algorithm

  1. Read Image using OpenCV imread() function.
  2. Create or Set up the Simple Blob Detector.
  3. Input image in the created detector.
  4. Obtain key points on the image.
  5. Draw shapes on the Key points found on the image.
  6. If You have any kind of problem in OpenCV basic operations and 7. OpenCV image manipulation. Read the blog about those functions as it will be used herein blob detection.

Import packages

Import Computer Vision Python package for image manipulation.

NumPy for working with image matrix and matrix manipulation.

Matplotlib for data visualization and for displaying two or more images in the same window. This package is also used for scientific purposes.

Read Image

Img = cv.imread(‘./img.jpg’, cv.IMREAD_GRAYSCALE)
Enter fullscreen modeExit fullscreen mode

The image is read and converted to Grayscale.

Blob Detector OpenCV

detector = cv.SimpleBlobDetector()
Enter fullscreen modeExit fullscreen mode

This step will create the object/instance of Simple Blob Detector. We will use this created instance in blob detection.

OpenCV Blob Detection Keypoints

keypoints = detector.detect(img)
Enter fullscreen modeExit fullscreen mode

The detect() function from the detector instance takes the grayscale image as an argument and finds the key points for blob detection.

NumPy Black Screen

blank = np.zeros((1,1))
Enter fullscreen modeExit fullscreen mode

This will create a black screen on which the shapes will be drawn.

Color Blob Detection OpenCV Python

blobs = cv.drawKeypoints(img, keypoints, blank, (0,255,255), cv.DRAW_MATCHES_FLAGS_DEFAULT)
Enter fullscreen modeExit fullscreen mode

This will draw the shapes on the keypoints detected by the detector on the Grayscale image.

cv.DRAW_MATCHES_FLAGS_DEFAULT – This method draws detected blobs as red circles and ensures that the size of the circle corresponds to the size of the blob.

Read more...Blob Detection OpenCV Python

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Developer | Blogger
  • Joined

More fromDivyanshu Shekhar

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp