0% found this document useful (0 votes)
204 views

Detecting Multiple Bright Spots in An Image With Python and OpenCV - PyImageSearch

This document discusses detecting multiple bright spots in an image using Python and OpenCV. It loads an image, converts it to grayscale, blurs it, applies thresholding to reveal bright regions, performs erosions and dilations to clean up noise, and performs connected component analysis to uniquely label the bright spots.

Uploaded by

Zubair
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
204 views

Detecting Multiple Bright Spots in An Image With Python and OpenCV - PyImageSearch

This document discusses detecting multiple bright spots in an image using Python and OpenCV. It loads an image, converts it to grayscale, blurs it, applies thresholding to reveal bright regions, performs erosions and dilations to clean up noise, and performs connected component analysis to uniquely label the bright spots.

Uploaded by

Zubair
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

PYIMAGESE
Click here to download the source code to this post
ARCH

IMAGE PROCESSING (HTTPS://PYIMAGESEARCH.COM/CATEGORY/IMAGE-PROCESSING/)

TUTORIALS (HTTPS://PYIMAGESEARCH.COM/CATEGORY/TUTORIALS/)

Detecting multiple bright spots in an


image with Python and OpenCV
by Adrian Rosebrock (https://pyimagesearch.com/author/adrian/) on October 31, 2016

Today’s blog post is a followup to a tutorial I did a couple of years ago on finding the brightest
spot in an image (https://pyimagesearch.com/2014/09/29/finding-brightest-spot-image-using-
python-opencv/).

M i t t i l d th l b i ht t i th i th t t dt

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 1/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

My previous tutorial assumed there was only one bright spot in the image that you wanted to
detect…
Click here to download the source code to this post
…but what if there were multiple bright spots?

If you want to detect more than one bright spot in an image the code gets slightly more
complicated, but not by much. No worries though: I’ll explain each of the steps in detail.

To learn how to detect multiple bright spots in an image, keep reading.

Looking for the source code to this post?


JUMP RIGHT TO THE DOWNLOADS SECTION

Detecting multiple bright spots in an image with Python


and OpenCV
Normally when I do code-based tutorials on the PyImageSearch blog I follow a pretty standard
template of:

1 Explaining what the problem is and how we are going to solve it.

2 Providing code to solve the project.

3 Demonstrating the results of executing the code.

This template tends to work well for 95% of the PyImageSearch blog posts, but for this one, I’m
going to squash the template together into a single step.

I feel that the problem of detecting the brightest regions of an image is pretty self-explanatory so I
d ’t d t d di t ti ti t d t ili th bl

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 2/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

don’t need to dedicate an entire section to detailing the problem.

Click here
I also think that explaining each to download
block the source
of code followed code to this
by immediately post the output of
showing
executing that respective block of code will help you better understand what’s going on.

So, with that said, take a look at the following image:

Figure 1: The example image that we are detecting multiple bright objects in using computer
vision and image processing techniques (source image
(http://articles.latimes.com/2014/jan/01/business/la-fi-mo-incandescent-lightbulb-ban-
20140101)).

In this image we have five lightbulbs.

Our goal is to detect these five lightbulbs in the image and uniquely label them.

To get started, open up a new file and name it detect_bright_spots.py . From there, insert
the following code:

→ Launch Jupyter Notebook on Google Colab

Detecting multiple bright spots in an image with Python and OpenCV

1. # import the necessary packages


2. from imutils import contours
3. from skimage import measure
4. import numpy as np
5. import argparse
6. import imutils
7 import cv2

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 3/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

7. import cv2
8.
9. # construct the argument parse and parse the arguments
10.
Click here to download the source code
ap = argparse.ArgumentParser()
to this post
11. ap.add_argument("-i", "--image", required=True,
12. help="path to the image file")
13. args = vars(ap.parse_args())

Lines 2-7 import our required Python packages. We’ll be using scikit-image (http://scikit-
image.org/) in this tutorial, so if you don’t already have it installed on your system be sure to
follow these install instructions (http://scikit-image.org/docs/stable/install.html).

We’ll also be using imutils (https://github.com/jrosebr1/imutils), my set of convenience functions


used to make applying image processing operations easier.

If you don’t already have imutils installed on your system, you can use pip to install it for
you:

→ Launch Jupyter Notebook on Google Colab

Detecting multiple bright spots in an image with Python and OpenCV


1. $ pip install --upgrade imutils

From there, Lines 10-13 parse our command line arguments. We only need a single switch here,
--image , which is the path to our input image.

To start detecting the brightest regions in an image, we first need to load our image from disk
followed by converting it to grayscale and smoothing (i.e., blurring) it to reduce high frequency
noise:

→ Launch Jupyter Notebook on Google Colab

Detecting multiple bright spots in an image with Python and OpenCV


15. # load the image, convert it to grayscale, and blur it
16. image = cv2.imread(args["image"])
17. gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
18. blurred = cv2.GaussianBlur(gray, (11, 11), 0)

The output of these operations can be seen below:

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 4/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Click here to download the source code to this post

Figure 2: Converting our image to grayscale and blurring it.

Notice how our image is now (1) grayscale and (2) blurred.

To reveal the brightest regions in the blurred image we need to apply thresholding:

→ Launch Jupyter Notebook on Google Colab

Detecting multiple bright spots in an image with Python and OpenCV


20. # threshold the image to reveal light regions in the
21. # blurred image
22. thresh = cv2.threshold(blurred, 200, 255, cv2.THRESH_BINARY)[1]

This operation takes any pixel value p >= 200 and sets it to 255 (white). Pixel values < 200 are set
to 0 (black).

After thresholding we are left with the following image:

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 5/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Click here to download the source code to this post

Figure 3: Applying thresholding to reveal the brighter regions of the image.

Note how the bright areas of the image are now all white while the rest of the image is set to
black.

However, there is a bit of noise in this image (i.e., small blobs), so let’s clean it up by performing a
series of erosions and dilations:

→ Launch Jupyter Notebook on Google Colab

Detecting multiple bright spots in an image with Python and OpenCV


24. # perform a series of erosions and dilations to remove
25. # any small blobs of noise from the thresholded image
26. thresh = cv2.erode(thresh, None, iterations=2)
27. thresh = cv2.dilate(thresh, None, iterations=4)

After applying these operations you can see that our thresh image is much “cleaner”, although
we do still have a few left over blobs that we’d like to exclude (we’ll handle that in our next step):

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 6/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Click here to download the source code to this post

Figure 4: Utilizing a series of erosions and dilations to help “clean up” the thresholded image by
removing small blobs and then regrowing the remaining regions.

The critical step in this project is to label each of the regions in the above figure; however, even
after applying our erosions and dilations we’d still like to filter out any leftover “noisy” regions.

An excellent way to do this is to perform a connected-component analysis


(https://en.wikipedia.org/wiki/Connected-component_labeling):

→ Launch Jupyter Notebook on Google Colab

Detecting multiple bright spots in an image with Python and OpenCV


29. # perform a connected component analysis on the thresholded
30. # image, then initialize a mask to store only the "large"
31. # components
32. labels = measure.label(thresh, neighbors=8, background=0)
33. mask = np.zeros(thresh.shape, dtype="uint8")
34.
35. # loop over the unique components
36. for label in np.unique(labels):
37. # if this is the background label, ignore it
38. if label == 0:
39. continue
40.
41. # otherwise, construct the label mask and count the
42. # number of pixels
43. labelMask = np.zeros(thresh.shape, dtype="uint8")

44. labelMask[labels == label] = 255


45. numPixels = cv2.countNonZero(labelMask)
46.
47. # if the number of pixels in the component is sufficiently
48. # large, then add it to our mask of "large blobs"
49. if numPixels > 300:
50 mask cv2 add(mask labelMask)

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 7/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

50. mask = cv2.add(mask, labelMask)

Click
Line 32 performs the here
actual to download the source
connected-component analysis code to this
using the post library. The
scikit-image
labels variable returned from measure.label has the exact same dimensions as our
thresh image — the only difference is that labels stores a unique integer for each blob in
thresh .

We then initialize a mask on Line 33 to store only the large blobs.

On Line 36 we start looping over each of the unique labels . If the label is zero then we
know we are examining the background region and can safely ignore it (Lines 38 and 39).

Otherwise, we construct a mask for just the current label on Lines 43 and 44.

I have provided a GIF animation below that visualizes the construction of the labelMask for
each label . Use this animation to help yourself understand how each of the individual
components are accessed and displayed:

Figure 5: A visual animation of applying a connected-component analysis to our thresholded


image.

Line 45 then counts the number of non-zero pixels in the labelMask . If numPixels exceeds
a pre-defined threshold (in this case, a total of 300 pixels), then we consider the blob “large
enough” and add it to our mask .

Th t t k b b l

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 8/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

The output mask can be seen below:

Click here to download the source code to this post

Figure 6: After applying a connected-component analysis we are left with only the larger blobs in
the image (which are also bright).

Notice how any small blobs have been filtered out and only the large blobs have been retained.

The last step is to draw the labeled blobs on our image:

→ Launch Jupyter Notebook on Google Colab

Detecting multiple bright spots in an image with Python and OpenCV


52. # find the contours in the mask, then sort them from left to
53. # right
54. cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
55. cv2.CHAIN_APPROX_SIMPLE)
56. cnts = imutils.grab_contours(cnts)
57. cnts = contours.sort_contours(cnts)[0]
58.
59. # loop over the contours
60. for (i, c) in enumerate(cnts):
61. # draw the bright spot on the image

62. (x, y, w, h) = cv2.boundingRect(c)


63. ((cX, cY), radius) = cv2.minEnclosingCircle(c)
64. cv2.circle(image, (int(cX), int(cY)), int(radius),
65. (0, 0, 255), 3)
66. cv2.putText(image, "#{}".format(i + 1), (x, y - 15),
67. cv2.FONT_HERSHEY_SIMPLEX, 0.45, (0, 0, 255), 2)
68

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 9/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

68.
69. # show the output image
70. cv2.imshow("Image", image)
71.
Click here to
cv2.waitKey(0)
download the source code to this post

First, we need to detect the contours in the mask image and then sort them from left-to-right
(Lines 54-57).

Once our contours have been sorted we can loop over them individually (Line 60).

For each of these contours we’ll compute the minimum enclosing circle (Line 63) which
represents the area that the bright region encompasses.

We then uniquely label the region and draw it on our image (Lines 64-67).

Finally, Lines 70 and 71 display our output results.

To visualize the output for the lightbulb image be sure to download the source code + example
images to this blog post using the “Downloads” section found at the bottom of this tutorial.

From there, just execute the following command:

→ Launch Jupyter Notebook on Google Colab

Detecting multiple bright spots in an image with Python and OpenCV


1. $ python detect_bright_spots.py --image images/lights_01.png

You should then see the following output image:

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 10/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Click here to download the source code to this post

Figure 7: Detecting multiple bright regions in an image with Python and OpenCV.

Notice how each of the lightbulbs has been uniquely labeled with a circle drawn to encompass
each of the individual bright regions.

You can visualize a a second example by executing this command:

→ Launch Jupyter Notebook on Google Colab

Detecting multiple bright spots in an image with Python and OpenCV


1. $ python detect_bright_spots.py --image images/lights_02.png

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 11/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Click here to download the source code to this post

Figure 8: A second example of detecting multiple bright regions using computer vision and image
processing techniques (source image (https://asianpeach.wordpress.com/tag/light-bulbs/)).

This time there are many lightbulbs in the input image! However, even with many bright regions in
the image our method is still able to correctly (and uniquely) label each of them.

What's next? I recommend PyImageSearch University


(https://pyimagesearch.com/pyimagesearch-
university/?
utm_source=blogPost&utm_medium=bottomBanner&u
tm_campaign=What%27s%20next%3F%20I%20recom
mend).

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 12/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Click here to download the source code to this post

Course information:

35+ total classes • 39h 44m video • Last updated: April 2022

★★★★★ 3:524.84 (128 Ratings) • 13,800+ Students Enrolled

I strongly believe that if you had the right teacher you could master computer vision
and deep learning.

Do you think learning computer vision and deep learning has to be time-consuming,
overwhelming, and complicated? Or has to involve complex mathematics and
equations? Or requires a degree in computer science?

That’s not the case.

All you need to master computer vision and deep learning is for someone to explain
things to you in simple, intuitive terms. And that’s exactly what I do. My mission is to
change education and how complex Artificial Intelligence topics are taught.

If you're serious about learning computer vision, your next stop should be
PyImageSearch University, the most comprehensive computer vision, deep learning,
and OpenCV course online today. Here you’ll learn how to successfully and
confidently apply computer vision to your work, research, and projects. Join me in
computer vision mastery.

Inside PyImageSearch University you'll find:

✓ 35+ courses on essential computer vision, deep learning, and OpenCV topics

✓ 35+ Certificates of Completion

✓ 39+ hours of on-demand video

✓ Brand new courses released regularly, ensuring you can keep up with state-of-the-

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 13/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

g y, gy p p
art techniques
Click here to download the source code to this post
✓ Pre-configured Jupyter Notebooks in Google Colab

✓ Run all code examples in your web browser — works on Windows, macOS, and
Linux (no dev environment configuration required!)

✓ Access to centralized code repos for all 450+ tutorials on PyImageSearch

✓ Easy one-click downloads for code, datasets, pre-trained models, etc.

✓ Access on mobile, laptop, desktop, etc.

CLICK HERE TO JOIN PYIMAGESEARCH UNIVERSITY


(HTTPS://PYIMAGESEARCH.COM/PYIMAGESEARCH-UNIVERSITY/?
UTM_SOURCE=BLOGPOST&UTM_MEDIUM=BOTTOMBANNER&UTM_CAMPA
IGN=WHAT%27S%20NEXT%3F%20I%20RECOMMEND)

Summary
In this blog post I extended my previous tutorial on detecting the brightest spot in an image
(https://pyimagesearch.com/2014/09/29/finding-brightest-spot-image-using-python-opencv/)
to work with multiple bright regions. I was able to accomplish this by applying thresholding to
reveal the brightest regions in an image.

The key here is the thresholding step — if your thresh   map is extremely noisy and cannot be
filtered using either contour properties or a connected-component analysis, then you won’t be
able to localize each of the bright regions in the image.

Thus, you should take care to assess your input images by applying various thresholding
techniques (simple thresholding, Otsu’s thresholding, adaptive thresholding, perhaps even
GrabCut) and visualizing your results.

This step should be performed before you even bother applying a connected-component


analysis or contour filtering.

Provided that you can reasonably segment the light regions from the darker, irrelevant regions of
i th th th d tli d i thi bl t h ld k it ll f

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 14/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

your image then the method outlined in this blog post should work quite well for you.

Anyway, I hope youClick here


enjoyed thisto download
blog post! the source code to this post

Before you go, be sure to enter your email address in the form below to be notified when
future tutorials are published on the PyImageSearch blog.

Download the Source Code and FREE 17-page Resource


Guide

Enter your email address below to get a .zip of the code and a FREE 17-page Resource
Guide on Computer Vision, OpenCV, and Deep Learning. Inside you'll find my hand-
picked tutorials, books, courses, and libraries to help you master CV and DL!

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 15/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Click here to download the source code to this post

About the Author


Hi there, I’m Adrian Rosebrock, PhD. All too often I see developers, students, and
researchers wasting their time, studying the wrong things, and generally struggling
to get started with Computer Vision, Deep Learning, and OpenCV. I created this
website to show you what I believe is the best possible way to get your start.

Previous Article:

Ubuntu 16.04: How to install OpenCV

(https://pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/)
Next Article:

Intersection over Union (IoU) for object detection

(https://pyimagesearch.com/2016/11/07/intersection-over-union-iou-for-object-detection/)

111 responses to: Detecting multiple bright spots in an


image with Python and OpenCV

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 16/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Rajeev Click
Ratanhere to download the source code to this post
October 31, 2016 at 11:09 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-409465)

Another excellent tutorial!

Adrian Rosebrock
November 1, 2016 at 8:57 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-409537)

Thanks Rajeev! Have an awesome day 🙂

Chris
October 31, 2016 at 12:25 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-409470)

Hi Adrian,

Thanks for yet another great tutorial. The code runs fine with no errors but only displays the
original images without the red circles or numbers. Any thoughts as to why?

Thanks!

Adrian Rosebrock
November 1, 2016 at 8:56 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-409536)

Hey Chris — are you using the code downloaded via the “Downloads” section of the blog
post? Or are you copying and pasting the code as you go along? The reason I ask is because
it sounds like contours are not being detected in your image for whatever reason. Trying

inserting a few debug statements like print(len(cnts)) to ensure at least some of the
contours are being detected.

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 17/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Bento
May 15,Click here
2017 at to (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-
3:02 am download the source code to this post
in-an-image-with-python-and-opencv/#comment-425193)

I have downloaded via the”Downloads” section but still it only display the original image. i
tried insert print(len(cnts)) and the result is 1. do you know where is the problem?

Adrian Rosebrock
May 15, 2017 at 8:33 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-425208)

It definitely sounds like an issue during either the (1) thresholding step or (2) contour
extraction step. Which version of OpenCV are you using?

James
July 5, 2017 at 7:47 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-429122)

Same exact issue and I can not make it work. My opencv version is 2.

Adrian Rosebrock
July 7, 2017 at 10:02 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-429297)

Go back to the thresholding step and ensure that each of the regions are properly
thresholded (i.e., your throughout output matches mine). Again, it sounds like something
strange is happening with the thresholding or the contour extraction process.

Alvin
November 1, 2016 at 2:57 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-409515)

Do you have a repo on github?

Adrian Rosebrock

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 18/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

d a oseb oc
November 1, 2016 at 8:51 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-409532)
Click here to download the source code to this post

Here is a link to my GitHub account where I maintain libraries such as imutils and color-
transfer:

https://github.com/jrosebr1 (https://github.com/jrosebr1)

The code for this particular blog post can be obtained by using the “Downloads” section of
the tutorial.

Robin Kinge
November 2, 2016 at 11:14 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-409684)

Broken Link?

Another excellent tutorial.

Adrian Rosebrock
November 3, 2016 at 9:41 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-409751)

The link should be working now, please give it another try.

Lenny Lemor
November 1, 2016 at 1:32 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-409602)

Hi, how fast is it? Can I use this for tracking some laser spots?

Regards

Adrian Rosebrock

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 19/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

d a oseb oc
November 3, 2016 at 9:51 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-409757)
Click here to download the source code to this post

This method is very fast since it’s based on thresholding for segmentation followed by
optimized connected-component analysis and contour filtering. It can certainly be used in
real-time semi-real-time environments for reasonably sized images.

Tamilmaran
November 2, 2016 at 4:47 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-409660)

Hi Adrian,

Is that any other ways to segment the bright spots from the RGB image, based on wavelength
range of the lights

Osman
November 3, 2016 at 5:59 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-409802)

Hey Adrian! Nice tutorial. Can this be used (if altered) with a WebCam to detect fire? Thanks

Adrian Rosebrock
November 4, 2016 at 10:05 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-409883)

Detecting smoke and fire is an active area of research in computer vision and image
processing. We typically use machine learning methods combined with feature extraction
methods (or deep learning) to make an approach like this work across a variety of lighting

conditions, environments, etc. I would not recommend using this method directly to detect
fire as you would likely obtain many false-positives.

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 20/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Click here to download the source code to this post


John
November 3, 2016 at 11:33 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-409835)

Hi Adrian,

Thanks so much for sharing your knowledge.

Question, how can I make it so that I can detect which light is turned off. In other word, can the
label be static? 1, 2, 3, 4, 5 => 1, 2, 5 meaning bulb 3 and 4 are off. Assuming the lights are
stationary.

Adrian Rosebrock
November 4, 2016 at 10:00 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-409880)

You can do this, but you would have to start with the lights in a fixed position and all of them
“on”. Once you’ve determined the ROI for each light just loop over each of the ROIs (no need
to detect them each time) and compute the mean of the grayscale region. If the mean is low
(close to black) then the light is off. If the mean is high (close to white) then the light is on.

Joel
December 3, 2016 at 5:54 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-412524)

Thank you for sharing this tutorial. The result was great using a satellite image of the U.S. at
night.

Adrian Rosebrock
December 5, 2016 at 1:33 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-412696)

Fantastic, I’m glad to hear it Joel! 🙂

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 21/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Izru
Click here to download the source code to this post
December 14, 2016 at 1:45 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-413473)

Hello Adrian , it’s Really but i face some Problem. I can’t install SKiImage on My Raspberry Pi 3 i
can’t measure anything Please help me.

thank you in Advance

Adrian Rosebrock
December 14, 2016 at 8:23 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-413491)

You can install scikit-image via:

$ pip install -U scikit-image

Is there a particular error message you are running into?

Bartosz Bartoszewski
February 7, 2017 at 8:42 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-417184)

Dear Adrian, I face the same problem as Izru.

Got all the steps done for installation of opencv. When I try to install scikit, my pi3b gets to a
point “Running setup.py bdist_wheel for scipi …” Then after an hour or two it hangs.

I can tell it’s hanging as I’ve left it yday for the night, when I turned the screen the system
clock was stopped at +1 hour after leaving it to finsh, mouse/kbd not responding. So I had to
pull the plug.

I’ve followed all steps for installation of opencv on my version of pi3b, all packages are up to
date.

Adrian Rosebrock
February 7, 2017 at 8:56 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-417187)

It sounds like the system might be locking up for some strange reason. I would suggest
trying this command and seeing if it helps:

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 22/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

trying this command and seeing if it helps:

Click here to download the source code to this post


$ pip install scikit-image --no-cache-dir

Also be sure to check the power settings on the Pi and ensuring that it’s not accidentally
going into sleep mode.

Bartosz Bartoszewski
February 7, 2017 at 3:18 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-417233)

Hey Adrian,

Many thanks for taking interest in my problem and a blazing fast reply. I’ve actually solved
it myself. While the install was running for the nth time I noticed that the system got very
unresponsive even though no significant CPU load was present, so I checked the
available memory and voila… The system was running out of swap-file space, I’ve had the
default setting of 100MB out of the box. After changing this to 1024MB the next run was
done within 40-50 minutes.

Adrian Rosebrock
February 10, 2017 at 2:16 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-
bright-spots-in-an-image-with-python-and-opencv/#comment-417485)

Thanks for sharing your solution Bartosz!

Jeff Ward (http://jeffward.me)


December 21, 2016 at 12:58 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-414007)

I had to change line 38 from “`if label == 0:“` to “`if label < 0:“`

I didn't dig further than http://scikit-


image.org/docs/dev/api/skimage.measure.html#skimage.measure.label (http://scikit-
image.org/docs/dev/api/skimage.measure.html#skimage.measure.label) to try to find the
f diff i i i d d i h ` h h` i

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 23/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

cause for differing starting indexes despite the `thresh` array starting at zero.

Click here to download the source code to this post

Mark
March 6, 2017 at 7:55 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-
in-an-image-with-python-and-opencv/#comment-419476)

I am also getting an error line 38

I tried the edit you suggested (i.e. label == 0:) but got the error shown below, any thoughts?

if label < 0:

TabError: inconsistent use of tabs and spaces in indentation

Adrian Rosebrock
March 6, 2017 at 3:36 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-419527)

Hey Mark — make sure you are using the “Downloads” section of the post to download the
code rather than copying and pasting from the tutorial. This should help resolve any issues
related to whitespacing.

Mark
March 7, 2017 at 3:44 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-419666)

Thanks Adrian, I only saw your reply now, this is exactly what it was, apologies for troubling
you over such a trivial issue, thanks for taking the time to answer my question anyway, i’ll
be clicking download from now on, instead of copying and pasting 🙂

Adrian Rosebrock
March 8, 2017 at 1:05 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-419749)

I’m happy to hear the issue was resolved 🙂

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 24/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Jehad Mohamed
Click here to download the source code to this post
April 6, 2017 at 9:01 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-422140)

You can solve this particular error by simply selecting your whole code and untabify in the
format tool of the idle

Mark
March 7, 2017 at 3:43 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-
in-an-image-with-python-and-opencv/#comment-419665)

Note: I resolved the issue I flagged above, it seems it was simply an indentation error
caused because I used Tab instead of 4 spaces to correct to code format after I had pasted
it into my IDE.

Alec edwards
February 5, 2017 at 2:26 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-
in-an-image-with-python-and-opencv/#comment-417083)

Hey is there anyway you could use this find rocks in the sand that are whiter than the sand!?
I’m trying to use this code, but it’s not working

Adrian Rosebrock
February 7, 2017 at 9:22 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-417210)

If the rocks are whiter than the sand itself you might want to try simple thresholding.

Célia
February 15, 2017 at 4:28 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-417825)

Hi Adrian, thanks for this great tutorial.

Have you ever encountered problems with the skimage module not having measure label?

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 25/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Have you ever encountered problems with the skimage module not having measure.label?

Click here to download theneighbors=8,


labels = skimage.measure.label(thresh, source codebackground=0)

to this post
AttributeError: 'module' object has no attribute 'label'

I guess maybe I am using a wrong version of skimage? But can’t find how to solve it..

Do you have any advice?

Thanks in advance

Adrian Rosebrock
February 15, 2017 at 8:59 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-417843)

Hey Célia — can you run pip freeze and let us know which version of scikit-image you are
running?

zara
April 3, 2017 at 8:38 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-
in-an-image-with-python-and-opencv/#comment-421820)

scikit-image==0.9.3

Same error i am also getting.

Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_rashmi/scikit-


image

Storing debug log for failure in /home/zara/.pip/pip.log

Adrian Rosebrock
April 3, 2017 at 1:52 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-
in-an-image-with-python-and-opencv/#comment-421842)

It looks like you’re running an old version of scikit-image. Try upgrading:

$ pip install --upgrade scikit-image

Tobias

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 26/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

March 3, 2017 at 12:03 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-


in-an-image-with-python-and-opencv/#comment-419030)
Click here to download the source code to this post

Hi Adrian, great tutorial really helpful, thanks.

Is there a way this could be used to give the coordinates of bright spots in an image for a
tracking application?

thanks

Tobias

Adrian Rosebrock
March 4, 2017 at 9:36 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-
in-an-image-with-python-and-opencv/#comment-419164)

The (x, y)-coordinates and bounding box are already given by Line 62, so I’m not sure what
you’re asking?

Tobias
March 7, 2017 at 8:34 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-
in-an-image-with-python-and-opencv/#comment-419631)

I thought that was the case, but when i try to append onto a list I only get one set of
coordinates, not the 5 I would expect.

Adrian Rosebrock
March 8, 2017 at 1:09 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-419754)

Make sure you are appending the coordinates to the list right after the bounding box is
computed — it sounds like there might be a logic error in your code.

Tobias
March 9, 2017 at 7:04 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 27/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

an-image-with-python-and-opencv/#comment-419813)

Click here to download the source code to this post


Thanks, that sorted it

ankit pitroda (http://www.smartlogic.in)


April 18, 2017 at 11:45 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-423170)

hello Sir,

Awesome work did by you.

I am looking for multiple dark points in the images.

can you suggest me for the same?

Adrian Rosebrock
April 19, 2017 at 12:46 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-
in-an-image-with-python-and-opencv/#comment-423216)

I would suggest inverting your image so that dark spots are now light and apply the same
techniques in this tutorial.

Ankiit Pitroda
October 7, 2019 at 3:43 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-559678)

this is awesome, you are superhuman.

thanks

Adrian Rosebrock

October 10, 2019 at 10:21 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-


spots-in-an-image-with-python-and-opencv/#comment-563654)

You are very kind, Ankiit 🙂

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 28/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Click here to download the source code to this post

Alex
May 20, 2017 at 6:26 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-425639)

Hello. I need a little help: I cannot understand the structure of line 11. Can you explain me?

Adrian Rosebrock
May 21, 2017 at 5:07 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-425695)

Hi Alex — are you referring to the argument parsing code? If so, be sure to read up on
command line arguments (https://pyimagesearch.com/2018/03/12/python-argparse-
command-line-arguments/) before continuing.

Antonios Kats
June 1, 2017 at 11:33 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-426555)

Hi Adrian,

You’ re doing an excellent job !

I have a simple question – you might have answered it a million times 😉

thresh = cv2.threshold(blurred, 200, 255, cv2.THRESH_BINARY)[1]

I’m wondering what the [1] stands for ?

Thanks in advance,

Antonios

Adrian Rosebrock
June 4, 2017 at 5:45 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-426680)

The cv2.threshold function returns a 2-tuple of the threshold value T and the thresholded

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 29/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

image. Since we only need the second entry in the tuple, we grab it via [1]. If you’re interested
in learning moreClick
abouthere to download
the basics the source
of image processing, code to
computer thisand
vision, post OpenCV, be
sure to refer to my book, Practical Python and OpenCV
(https://pyimagesearch.com/practical-python-opencv/).

Julian
July 20, 2017 at 3:40 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-430291)

Hey Adrian, great tutorial, I’m working on a similar project right now but my approach is to use
the connectedComponentsWithStats function of OpenCV 3. It would be nice to know what are
the advantages/disadvantages of using the scikit-image library approach instead of the already
built-in function of OpenCV.

Adrian Rosebrock
July 21, 2017 at 8:53 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-430368)

There really aren’t any disadvantages of using the built-in function with OpenCV. The main
reason I used scikit-image for this is prior to OpenCV 3 there was no connected-component
analysis function with Python bindigns.

Mike
December 19, 2017 at 2:06 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-443776)

Hi there,

Awesome work as always! Keep it up, buddy.

I am struggling for the past 2 weeks to detect glossy/shiny/bright spots or areas in image and
video. I have applied the technique you suggested above using C++.

While I am getting good results in some of the cases, others are slightly off.

i i

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 30/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Here’s an example: https://imgur.com/a/truur (https://imgur.com/a/truur) This is a relatively


good result but I have no idea how to improve it and why it does find so many bright spots on
Click here to download the source code to this post
the curtain even though there’s nothing shiny there.

I have been tuning and playing around with the model’s parameters such as (gaussian radius,
threshold etc) day and night but I’m not getting very good results so I am thinking maybe the
approach is wrong for my purposes. I hope you can give me some direction on this matter

All best!

Adrian Rosebrock
December 19, 2017 at 4:10 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-443794)

Hey Mike, thanks for the comment. I know this isn’t going to help for this particular project but
I want to make sure others read it — computer vision algorithms will struggle to detect glossy,
reflective regions. When a camera captures an image it’s detecting the light bounced off the
object back into the lens. Glossy, reflective objects will distort the capture and make them
hard to detect.

In your particular instance you have light-colored regions that are lighter than the rest of the
image. Unfortunately you cannot do much about this other than consider semantic
segmentation if at all possible.

Federica
March 20, 2018 at 2:05 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-
in-an-image-with-python-and-opencv/#comment-453743)

Hello, would it be possible to detect real time changes through a webcam and execute certain
actions based on what leds are on?

Adrian Rosebrock
March 22, 2018 at 10:13 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-453952)

Sure. Simple motion detection (https://pyimagesearch.com/2015/05/25/basic-motion-

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 31/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

p ( p py g
detection-and-tracking-with-python-and-opencv/) would help determine when a change in
Click
the video stream hereand
happens to from
download the
there you cansource code to action.
take appropriate this post

Scarlett Zheng
April 27, 2018 at 1:00 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-458909)

Hi Adrian ,thank you for your great sharing. I’ve had some problems recently. It maybe like one
from Mike. But I am not sure. I want to find the image that exists violent sunlight(or exposure
field) in many images . Have you some ideas ? Can you share with me? I am trying to convert
RGB to HSL and use the method ( from the tutorial of Finding the Brightest Spot in an Image
using Python and OpenCV) . Then set a threshold of area to define the image. But I don’t have
a satisfying result.

Adrian Rosebrock
April 28, 2018 at 6:08 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-
in-an-image-with-python-and-opencv/#comment-459072)

What does “violent sunlight” mean in this context?

Mehdi cheher (http://pyimagesearch)


May 7, 2018 at 11:16 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-460283)

Hi Adrian , i was running this code and i had this error and i didn’t find solution for it so f you
know how to fix it please help me :

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

error: (-215) scn == 3 || scn == 4 in function cvtColor

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 32/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Thanks in advance 😀

Click here to download the source code to this post

Adrian Rosebrock
May 9, 2018 at 9:59 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-460665)

Your path to “cv2.imread” is incorrect and the function is returning “None”. You can read more
about NoneType errors in OpenCV here (https://pyimagesearch.com/2016/12/26/opencv-
resolving-nonetype-errors/). My guess is that you did not properly pass the command line
argument to the script. Be sure to read up on command line arguments
(https://pyimagesearch.com/2018/03/12/python-argparse-command-line-arguments/).

Patrick Lin
May 10, 2018 at 5:01 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-460811)

Hi Adrian,

Excellent tutorial and thanks for sharing!

Question:

1. If I apply this method to panorama images, what aspects should I pay attention to?

2. What are the limitations of this method? Is this method only applied to high dark contrast?

Thanks.

Adrian Rosebrock
May 14, 2018 at 12:18 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-
in-an-image-with-python-and-opencv/#comment-461570)

1. This method will work with panorama images.

2. There are a number of limitations with this method but the biggest one is false-positives
due to glare or reflection where the object appears (in the image) to be significantly brighter

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 33/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

than it actually is. If you’re working with in an unconstrained environment with lot’s of
relfection or glare I would not recommend this method.
Click here to download the source code to this post

Aman Agrawal
July 2, 2018 at 1:44 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-469673)

Hi Adrian, another excellent tutorial!

I just had one question. This might be a naive one, since I have just begun learning.

What is the need for blurring the picture before moving onto the rest of the process? Also, what
could be the other possible reasons when one might have to blur the picture before
proceeding further?

Adrian Rosebrock
July 3, 2018 at 8:26 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-469847)

Blurring reduces high frequency noises. I discuss why we apply blurring, how to apply it, and
the other fundamentals of computer vision and image processing inside Practical Python and
OpenCV (https://pyimagesearch.com/practical-python-opencv/). Be sure to take a look, I
think it could really help you with your studies.

chitra lalawat
October 11, 2018 at 2:38 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-
in-an-image-with-python-and-opencv/#comment-481925)

Hey!

In the image you’ve got only two colors to deal with… I have an image and I want to calculate
only the blue marks inside it… I’ll be happy if u guide me a little..

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 34/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

AdrianClick here to download the source code to this post


Rosebrock
October 12, 2018 at 9:07 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-482171)

Both of the objects are blue? If so, all you should need is some basic color thresholding.
(https://pyimagesearch.com/2014/08/04/opencv-python-color-detection/)

Biswa
October 21, 2018 at 6:46 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-483428)

Hi Adrian,

The blog was very nice and understandable.

Currently, I have a use case to find the origin of smoke. For example, if my image is having a
smoke from a long distance from the mountain how I can square that originated portion of
smoke. Could you please help with this.

Adrian Rosebrock
October 22, 2018 at 8:04 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-483556)

Smoke detection is an active area of research that is far from solved. I would start by reading
this paper (http://www.cs.ucsb.edu/~yfwang/papers/csie2009.pdf).

Pramit Mazumdar
October 23, 2018 at 6:30 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-483688)

Hello Adrian,

Thanks for the simple explanation. It really helped. Just wanted to ask another follow-up
question.

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 35/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

1. Can we get the member pixel coordinates for each of the minimum bounding circles?

Click here to download the source code to this post


I guess, we have to do something with the “cnts”, but not sure exactly what to be done to know
which pixels are within Circle-1. Or is there any cv2 function for finding member pixels for each
contour?

Adrian Rosebrock
October 29, 2018 at 2:12 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-484502)

I’m not sure what you mean by “member pixels”. Could you elaborate?

Christian Smith
October 30, 2018 at 6:35 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-484683)

Hey Adrian! I am a student at Auburn University. For our senior design project, I would like to
use your tutorial as a part of our senior design project (building a startracker on a Raspberry Pi).
I will be editing your code, but I want to find a way to properly cite you and give you credit. Can
you give me any advice in this regard?

It’s been an amazing learning tool and I am very thankful for all your work in creating this blog.
Without it, I would have been lost beyond all belief. You’re doing amazing things.

Adrian Rosebrock
November 2, 2018 at 7:44 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-485027)

Hi Christian — congrats on working on your senior project, that’s awesome! I’m sure you are
excited to graduate. Auburn is also a great school, I hope you enjoyed your time there.

As far as citation goes, please include (1) my name, (2) the name of the article you are citing,
and (3) a link back to the original blog post.

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 36/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Click here to download the source code to this post


Asad Ali
November 30, 2018 at 5:27 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-490122)

Hello,

Could this model be used to detect dark spots in a bright image as well?

Regards,

Asad

Adrian Rosebrock
December 4, 2018 at 10:18 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-490693)

Yes, you could just invert the input image and you would be able to detect dark spots as well.

Asad Ali
December 4, 2018 at 5:49 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-490755)

Hello,

I am looking to find black spots on a white background.

I am inverting the image as you have suggested earlier in the comments.

I have confirmed the image is being inverted properly.

But I get the following error

ValueError: not enough values to unpack (expected 2, got 0)

from line

—> 66 cnts = contours.sort_contours(cnts)[0]


Any suggestion would be appreciated, thanks.

Asad

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 37/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

AdrianClick here to download the source code to this post


Rosebrock
December 6, 2018 at 9:52 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-491023)

Check the length of the “cnts” array. It sounds like there are no contours being detected.

Hamizan
December 15, 2018 at 11:16 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-492405)

Hello,

I am getting this error:( AttributeError: module ‘imutils’ has no attribute ‘grab_contours’). Is there
any solution to this?

Hamizan
December 15, 2018 at 11:40 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-492408)

I found the solution. I just copied paste your imutils folder from github and paste it to my site-
packages. Somehow my initial imutils does not have grab_contours function.

Adrian Rosebrock
December 18, 2018 at 9:15 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-492831)

You were using an older version of imutils. You need to upgrade it via:

$ pip install --upgrade imutils

Meet Thosar
J 16 2019 t 6 22 (htt // i h /2016/10/31/d t ti lti l b i ht t

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 38/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

January 16, 2019 at 6:22 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-


in-an-image-with-python-and-opencv/#comment-496599)
Click here to download the source code to this post
Thanks a lot for your great tutorials.

I am new to python but you explain all concepts very nicely. This makes task easier for
newbies.

I combined bubble sheet with OMR and this tutorial to create User Identification bubble sheet
with little changes. It worked like charm.

Thanks once again

Adrian Rosebrock
January 16, 2019 at 9:30 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-496632)

Congrats on a successful project!

ShubhamG.
January 16, 2019 at 11:56 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-496705)

You’re a lifesaver, thank you for the great tutorial!

Adrian Rosebrock
January 22, 2019 at 9:59 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-497474)

Thanks, I’m glad it helped you!

rishav sapahia
February 3, 2019 at 11:23 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-499331)

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 39/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Getting ValueError: not here


Click enoughtovalues to unpack
download the(expected 2, got 0)
source code toerror
this on line 57 of the
post
code, which points to line 25 of the sort_contours file cnts = contours.sort_contours(cnts)[0] . I
have used the code you have given in downloads section and all my libraries are updated . I
am using MAC OS with python3.6

Adrian Rosebrock
February 5, 2019 at 9:30 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-499738)

Which version of OpenCV are you using?

Arsenis
February 3, 2019 at 3:24 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-499352)

Hello Adrian as always top quality tutorials.

I am using your point view to detect bright spots in an image, and i am having a problem with it
due to the fact that they are being considered noise. I tried to fix this problem with the
cv2.erode, cv2.dilate and fixed many issues, but i am still having some problems with some
images. What would you recomend to fix this problem ?

Thank you for your time

Adrian Rosebrock
February 5, 2019 at 9:29 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-499737)

It sounds like your preprocessing steps need to be updated. Without knowing exactly what
your image looks like but I would suggest blurring followed by morphological operations,
probably a black hat or white hat. I would also suggest working through the PyImageSearch
Gurus course (https://pyimagesearch.com/pyimagesearch-gurus/) or Practical Python and
O CV (h // i h / i l h /) h l l h b i

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 40/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

OpenCV (https://pyimagesearch.com/practical-python-opencv/) to help you learn the basics


as well.
Click here to download the source code to this post

Arsenis
February 11, 2019 at 5:51 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-500789)

Thank you for your quick answer Adrian,

I fixed the issue, the problem was in the preprocessing.

Keep up the great work.

Adrian Rosebrock
February 14, 2019 at 1:33 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-501341)

Congrats on resolving the issue!

Niklas Schuster
March 30, 2019 at 12:33 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-
in-an-image-with-python-and-opencv/#comment-510102)

Great Tutorial

But how am I able to show the labels individually like you did in your gif animation? I tried
cv2.imshow in the [for label in np.unique(labels):]-loop but it seems like that always gives me
the last found bright spot. (which i really dont understand since it should loop through the
labels one by one..right? )

Thank you for your time

Gaurav Pujar

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 41/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

j
May 7, 2019 at 5:08 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-516355)
Click here to download the source code to this post

You are god!!

Adrian Rosebrock
May 8, 2019 at 12:57 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-
in-an-image-with-python-and-opencv/#comment-516570)

Thanks Gaurav.

Artem Dranoshhuk
May 11, 2019 at 7:06 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-517209)

Hello Adrian as always great tutorial

I using you code to detect small lights on image (car headlights).

It’s turns out that measure.label always give me 0, even without erode and GaussianBlur.

How can I fix that?

Thank you in Advance.

Vaz Chan
June 4, 2019 at 9:46 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-520816)

Hey Adrian,

I’m a bit new to OpenCV, so any help would be great.

I have a live video feed with 5 adjacent LEDs that randomly switch between red or green. I
want to be able to detect these LEDs, number them (as you have), and pick the numbers which
df h i i

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 42/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

are red from them at any given time.

What would be the changes I’d need to make, to detect either red/green lights, and then pick
Click here to download the source code to this post
the red from those selected ones.

I’ll be subscribing to your crash course, and any help would be appreciated.

Adrian Rosebrock
June 6, 2019 at 6:47 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-520996)

Hey Vaz — it would be helpful to see your images first. Perhaps send me an email and I can
take look?

Eve
June 27, 2019 at 3:56 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-523355)

Hello. Great tutorial! Would it be possible to detect sun glares in an image using this method?
Any alterations to the code you would recommend or maybe an alternative method if this
would not work for detecting sun glares? Thanks.

anon
September 23, 2019 at 9:29 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-553652)

So i have this code working with a webcam currently. I am wanting to use it outdoors but it is
currently picking up the sky. How could i work around that?

Hidayat
November 12, 2019 at 2:19 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-572285)

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 43/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Hello Mr.Adrian, i want to make wet hand detector using bright spot method, so i using camera
to detect hand. ToClick
detecthere to download
the wetness the source
of my hands, I put thecode to this
lamp next post
to the camera, I think
the reflection of the light beam on a wet hand can provide input to the camera. is it possible to
use this method?

hope someone can help me

Gaurav
December 25, 2019 at 12:58 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-614270)

Hey Adrian,

I was working on a project where I need to add glossiness/shininess/matte texture to lips.

I was looking for some generic OpenCV based solution but no good results are achieved

Can you please help me with how can I apply glossiness/shininess to an image.

TIA!

Adrian Rosebrock
December 26, 2019 at 9:51 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-617872)

That sounds like a good use case for transparent overlays and alpha blending.
(https://pyimagesearch.com/2016/03/07/transparent-overlays-with-opencv/)

Akash
January 1, 2020 at 7:16 pm (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-
in-an-image-with-python-and-opencv/#comment-622165)

Hey Adrian

I am using your tutorials for one of my project and I want to detect stains/dirt spots on a dish
plate/bowl.I performed pyramid mean shift filtering and Otsu’s thresholding for finding the
contour,however I’m stuck on how to find the stain marks.

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 44/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

What would you recommend to fix this problem ?

Click here to download the source code to this post


Thank you for your time

Adrian Rosebrock
January 2, 2020 at 8:47 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-622492)

It’s hard to say without seeing example images of what you’re working with first. Depending
on the complexity of the image/levels of contrast you may instead need to look into instance
segmentation algorithms.

Akash
January 2, 2020 at 10:24 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-622568)

Thank you for your suggestion.which of the listed course would you suggest subscribing for
computer vision and deep learning applications as i would be working more on this.

Is it possible to for me to share the image to your mail ?

Adrian Rosebrock
January 16, 2020 at 11:04 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-656680)

I would suggest my book, Deep Learning for Computer Vision with Python
(https://pyimagesearch.com/deep-learning-computer-vision-python-book/), which covers
deep learning applied to computer vision applications in detail.

After you purchase you will have access to my email address and we can continue the
conversation there.

Ciro
February 9, 2020 at 6:18 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-712151)

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 45/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

great job, i will buy yourhere


Click book to
shortly. but speaking
download of this, I code
the source wantedto
tothis
ask you
posta favor would
you help me a lot with my project, where is there a function or a way to understand the
difference in brightness? so as to assign 1 to maximum brightness and 0 to lowest brightness.

Adrian Rosebrock
February 13, 2020 at 11:09 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-
spots-in-an-image-with-python-and-opencv/#comment-725667)

Take a look at min-max normalization as that should achieve what you want.

Rusj
March 4, 2020 at 6:18 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-765410)

Hi Adrians, thankyou so much for your kindness and generousity.

I am a beginner, and

I wonder how it can draw a curve. to select the result (may it be along the contour ) instead of a
circle ?

How can it be done?

Btw, sorry for my bad english.

Ali Qadar
April 6, 2020 at 5:58 am (https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-
an-image-with-python-and-opencv/#comment-770745)

Hi Adrian,

I have applied this code on Night time vehicles detection, it works fine for some frames. I was
thinking to cluster detected blobs in each frame and track their position using Kalman filter. I
would highly appreciate if you can give me some hints or suggestions especially on clustering
part. The thing in my mind is that clustering process should group detected blobs and compare
h i h bl b d di h f b d K l fil di i f h

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 46/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

them against the blobs detected in the next frame based on Kalman filter prediction of the
position of the previous blob.

Click here to download the source code to this post


I know eventually I had to get rid of Thresholding but this is a really good start to get hands
dirty for starting on complex project like the one I mentioned in the first line. Hats of to you for
this great tutorial.

Comment section

Hey, Adrian Rosebrock here, author and creator of PyImageSearch. While I love
hearing from readers, a couple years ago I made the tough decision to no longer offer
1:1 help over blog post comments.

At the time I was receiving 200+ emails per day and another 100+ blog post
comments. I simply did not have the time to moderate and respond to them all, and
the sheer volume of requests was taking a toll on me.

Instead, my goal is to do the most good for the computer vision, deep learning, and
OpenCV community at large by focusing my time on authoring high-quality blog
posts, tutorials, and books/courses.

If you need help learning computer vision and deep learning, I suggest you refer to
my full catalog of books and courses (https://pyimagesearch.com/books-and-
courses/) — they have helped tens of thousands of developers, students, and
researchers just like yourself learn Computer Vision, Deep Learning, and OpenCV.

Click here to browse my full catalog. (https://pyimagesearch.com/books-and-


courses/)

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 47/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Click here to download the source code to this post

Similar articles

PYIMAGECONF

PyImageConf 2018 Recap


October 1, 2018

(https://pyimagesearch.com/2018/10/01/pyimageconf-2018-recap/)

OPENCV TUTORIALS TUTORIALS

OpenCV Histogram Equalization and Adaptive Histogram Equalization


(CLAHE)
February 1, 2021
(https://pyimagesearch.com/2021/02/01/opencv-histogram-equalization-and-
adaptive-histogram-equalization-clahe/)

IMAGE PROCESSING TUTORIALS

Color Quantization with OpenCV using K-Means Clustering


July 7, 2014
(https://pyimagesearch.com/2014/07/07/color-quantization-opencv-using-k-means-
clustering/)

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 48/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Click here to download the source code to this post

You can learn Computer Vision, Deep Learning, and OpenCV.


Get your FREE 17 page Computer Vision, OpenCV, and Deep Learning Resource Guide PDF. Inside
you’ll find our hand-picked tutorials, books, courses, and libraries to help you master CV and DL.

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 49/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Topics Machine Learning and Computer Vision


(https://pyimagesearch.com/category/machine-
Click here to download the source code to this post
Deep Learning learning-2/)
(https://pyimagesearch.com/category/deep-
Medical Computer Vision
learning-2/)
(https://pyimagesearch.com/category/medical/)
Dlib Library
Optical Character Recognition (OCR)
(https://pyimagesearch.com/category/dlib/)
(https://pyimagesearch.com/category/optical-
Embedded/IoT and Computer Vision character-recognition-ocr/)
(https://pyimagesearch.com/category/embedded/)
Object Detection
Face Applications (https://pyimagesearch.com/category/object-
(https://pyimagesearch.com/category/faces/) detection/)
Image Processing Object Tracking
(https://pyimagesearch.com/category/image- (https://pyimagesearch.com/category/object-
processing/) tracking/)
Interviews OpenCV Tutorials
(https://pyimagesearch.com/category/interviews/) (https://pyimagesearch.com/category/opencv/)
Keras (https://pyimagesearch.com/category/keras/) Raspberry Pi
(https://pyimagesearch.com/category/raspberry-
pi/)

PyImageSearch
Books & Courses

Affiliates (https://pyimagesearch.com/affiliates/)
PyImageSearch University
(https://pyimagesearch.com/pyimagesearch- Get Started (https://pyimagesearch.com/start-
university/) here/)

FREE CV, DL, and OpenCV Crash Course OpenCV Install Guides
(https://pyimagesearch.com/free-opencv- (https://pyimagesearch.com/opencv-tutorials-
computer-vision-deep-learning-crash-course/) resources-guides/)

Practical Python and OpenCV About (https://pyimagesearch.com/about/)


(https://pyimagesearch.com/practical-python-
FAQ (https://pyimagesearch.com/faqs/)
opencv/)
Blog (https://pyimagesearch.com/topics/)
Deep Learning for Computer Vision with Python
(https://pyimagesearch.com/deep-learning- Contact (https://pyimagesearch.com/contact/)
computer-vision-python-book/)
Privacy Policy (https://pyimagesearch.com/privacy-
PyImageSearch Gurus Course policy/)
(https://pyimagesearch.com/pyimagesearch-
gurus/)

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 50/51
6/26/22, 1:00 PM Detecting multiple bright spots in an image with Python and OpenCV - PyImageSearch

Raspberry Pi for Computer Vision


(https://pyimagesearch.com/raspberry-pi-for-
Click here to download the source code to this post
computer-vision/)

(https://www.facebook.com/pyimagesearch)
(https://twitter.com/PyImageSearch) (http://www.linkedin.com/pub/adrian-
rosebrock/2a/873/59b) (https://www.youtube.com/channel/UCoQK7OVcIVy-nV4m-
SMCk_Q/videos)

© 2022 PyImageSearch (https://pyimagesearch.com). All Rights Reserved.

https://pyimagesearch.com/2016/10/31/detecting-multiple-bright-spots-in-an-image-with-python-and-opencv/ 51/51

You might also like