# cv2.SimpleBlobDetector\_create() not accept parameters in OpenCV 4.10.0

**URL:** <https://forum.opencv.org/t/cv2-simpleblobdetector-create-not-accept-parameters-in-opencv-4-10-0/19579>\
**Category:** Python\
**Tags:** programming\
**Created:** [December 19, 2024, 7:03pm UTC](https://forum.opencv.org/t/cv2-simpleblobdetector-create-not-accept-parameters-in-opencv-4-10-0/19579 "2024-12-19T19:03:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![GSF](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/gsf/32/11679_2.png) [@GSF](https://forum.opencv.org/u/GSF)\
**Post date:** [December 19, 2024, 7:03pm UTC](https://forum.opencv.org/t/cv2-simpleblobdetector-create-not-accept-parameters-in-opencv-4-10-0/19579/1 "2024-12-19T19:03:47Z")

</div>

Hello everyone,

I’m having an error when I want to specify values ​​for parameters to create a Blob detector in Python 3.12.7  
Follow this code:

```auto

params = cv2.SimpleBlobDetector_Params

params.filterByArea = True #Ativa
params.minArea = 100 #Área minima de 100

params.filterByCircularity = True #Ativa
params.minCircularity = 0.9 #Testar e ver qual se adequa mais a forma de interesse
# 0 a 1, sendo 1, o circulo perfeito

params.filterByConvexity = False #Desativa o parametro
params.minConvexity = 0.2
    
params.filterByInertia = True #Ativa
params.minInertiaRatio = 0.01 # 1 para full simétrico e abaixo de 1, imperfeições.

"""
MinInertiaRatio - 0.8 a 1 (Circulos ou quase circulos)
MinInertiaRatio - 0.2 a 0.5 (Objetos alongados e elípticos)
MinInertiaRatio - < 0.2 (Qualquer coisa)
"""
#Recriando o detector com os parametros novos
detector = cv2.SimpleBlobDetector_create(params)

ERROR: TypeError: Expected cv::SimpleBlobDetector::Params for argument 'parameters'

```

The create function does not accept the parameter variable. Does anyone know how to fix it?

When i use

```auto
params = cv2.SimpleBlobDetector_Params()

```

Also gives error (AttributeError: ‘cv2.SimpleBlobDetector.Params’ object attribute ‘filterByArea’ is read-only)

---

<div class="post-metadata">

**Author:** ![sturkmen](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/sturkmen/32/13_2.png) [@sturkmen](https://forum.opencv.org/u/sturkmen)\
**Post date:** [December 19, 2024, 10:19pm UTC](https://forum.opencv.org/t/cv2-simpleblobdetector-create-not-accept-parameters-in-opencv-4-10-0/19579/2 "2024-12-19T22:19:58Z")

</div>

take a look at [learnopencv/BlobDetector at master · spmallick/learnopencv](https://github.com/spmallick/learnopencv/tree/master/BlobDetector)

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [December 20, 2024, 10:02am UTC](https://forum.opencv.org/t/cv2-simpleblobdetector-create-not-accept-parameters-in-opencv-4-10-0/19579/3 "2024-12-20T10:02:39Z")

</div>

> [@GSF](#):
>
> ```auto
> params = cv2.SimpleBlobDetector_Params
> 
> ```

you have to _call_ the constructor. there is no call there.

---

<div class="post-metadata">

**Author:** ![GSF](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/gsf/32/11679_2.png) [@GSF](https://forum.opencv.org/u/GSF)\
**Post date:** [December 20, 2024, 5:23pm UTC](https://forum.opencv.org/t/cv2-simpleblobdetector-create-not-accept-parameters-in-opencv-4-10-0/19579/4 "2024-12-20T17:23:46Z")

</div>

Not work with version verification.

---

<div class="post-metadata">

**Author:** ![GSF](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/gsf/32/11679_2.png) [@GSF](https://forum.opencv.org/u/GSF)\
**Post date:** [December 20, 2024, 5:35pm UTC](https://forum.opencv.org/t/cv2-simpleblobdetector-create-not-accept-parameters-in-opencv-4-10-0/19579/5 "2024-12-20T17:35:58Z")

</div>

With Constructor (`params = cv2.SimpleBlobDetector_Params()`), also not work.  
My current code :

```auto
# Carregando a imagem
image = cv2.imread("images/blobs.jpg", 0)
imshow('Original Image',image)

# Inicializa o detector de blobs
detector = cv2.SimpleBlobDetector_create()
 
# Pegando os blobs
keypoints = detector.detect(image)
 
# Desenhando os blobs. 
blank = np.zeros((1,1)) #Cria uma matriz pequena de zeros (só para passar uma imagem vazia como parametro)
blobs = cv2.drawKeypoints(image, keypoints, blank, (0,0,255),
                                      cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

number_of_blobs = len(keypoints)
text = "Total de Blobs: " + str(len(keypoints))
cv2.putText(blobs, text, (20, 550), cv2.FONT_HERSHEY_SIMPLEX, 1, (100, 0, 255), 2)

# Display image with blob keypoints
imshow("Blobs usando os parâmetros padrões", blobs)

# Setar filtros de parametros
# Vamos pegar os parametros base da função cv2.SimpleBlobDetector_Params
params = cv2.SimpleBlobDetector_Params

# PARÂMETRO DO ASPECTO ÁREA (TAMANHO DO OBJETO)
params.filterByArea = True #Ativa
params.minArea = 100 #Área minima de 100

# PARÂMETRO DA CIRCULARIDADE (O QUANTO A FORMA É PRÓXIMA A UM CIRCULO PERFEITO)
params.filterByCircularity = True #Ativa
params.minCircularity = 0.9 #Testar e ver qual se adequa mais a forma de interesse
# 0 a 1, sendo 1, o circulo perfeito

# PARÂMETRO DA CONVEXIDADE
params.filterByConvexity = False #Desativa o parametro
params.minConvexity = 0.2
    
# PARÂMETRO DA INERCIA
params.filterByInertia = True #Ativa
params.minInertiaRatio = 0.01 # 1 para full simétrico e abaixo de 1, imperfeições.

"""
MinInertiaRatio - 0.8 a 1 (Circulos ou quase circulos)
MinInertiaRatio - 0.2 a 0.5 (Objetos alongados e elípticos)
MinInertiaRatio - < 0.2 (Qualquer coisa)
"""
#Recriando o detector com os parametros novos
# Create a detector with the parameters
ver = (cv2. __version__ ).split('.')
if int(ver[0]) < 3 :
    detector = cv2.SimpleBlobDetector(params)
else: 
    detector = cv2.SimpleBlobDetector_create(params)
    
# Detect blobs
keypoints = detector.detect(image)

# Draw blobs on our image as red circles
blank = np.zeros((1,1)) 
blobs = cv2.drawKeypoints(image, keypoints, blank, (0,255,0),
                                      cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

number_of_blobs = len(keypoints)
text = "Number of Circular Blobs: " + str(len(keypoints))
cv2.putText(blobs, text, (20, 550), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 100, 255), 2)

# Show blobs
imshow("Filtering Circular Blobs Only", blobs)

```

My error: `TypeError: Expected cv::SimpleBlobDetector::Params for argument 'parameters'` in line `detector = cv2.SimpleBlobDetector.create(params)`

---

<div class="post-metadata">

**Author:** ![GSF](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/gsf/32/11679_2.png) [@GSF](https://forum.opencv.org/u/GSF)\
**Post date:** [December 20, 2024, 8:26pm UTC](https://forum.opencv.org/t/cv2-simpleblobdetector-create-not-accept-parameters-in-opencv-4-10-0/19579/6 "2024-12-20T20:26:24Z")

</div>

In OpenCV 4.7.0 also not work.  
Still atributtes can’t are change.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [December 20, 2024, 9:39pm UTC](https://forum.opencv.org/t/cv2-simpleblobdetector-create-not-accept-parameters-in-opencv-4-10-0/19579/7 "2024-12-20T21:39:34Z")

</div>

if you keep ignoring the advice, you won’t get anywhere.

```auto
>>> p = cv.SimpleBlobDetector_Params()
>>> p.filterByArea = True # works
>>> p.filterByArea = False # works too

```

> [@GSF](#):
>
> AttributeError: ‘cv2.SimpleBlobDetector.Params’ object attribute ‘filterByArea’ is read-only

that happens because you altered the `SimpleBlobDetector_Params` class before you made an instance of the class.

```auto
>>> p = cv.SimpleBlobDetector_Params
>>> p.filterByArea = True # alters the class, fatally
>>> p = cv.SimpleBlobDetector_Params()
>>> p.filterByArea = True # tries to alter an attribute of an instance
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'cv2.SimpleBlobDetector.Params' object attribute 'filterByArea' is read-only

```

---

<div class="post-metadata">

**Author:** ![GSF](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/gsf/32/11679_2.png) [@GSF](https://forum.opencv.org/u/GSF)\
**Post date:** [December 20, 2024, 9:55pm UTC](https://forum.opencv.org/t/cv2-simpleblobdetector-create-not-accept-parameters-in-opencv-4-10-0/19579/8 "2024-12-20T21:55:18Z")

</div>

My code is correct.  
Solve error `TypeError: Expected cv::SimpleBlobDetector::Params for argument 'parameters'` restart the VSCode. The Cache generate bug.  
My env with: OpenCV 4.10.82 (contrib also) with numpy 1.26
