Ask Your Question

Ali001's profile - activity

2020-07-07 03:32:15 -0500 received badge  Nice Question (source)
2020-07-06 21:16:53 -0500 received badge  Supporter (source)
2020-07-06 09:17:38 -0500 commented question can't run HoughCircles on image

This is the original image.

2020-07-06 09:16:50 -0500 edited question can't run HoughCircles on image

can't run HoughCircles on image I am trying to count objects in an image. To do that this is the approach I am using;

2020-07-06 09:16:50 -0500 received badge  Editor (source)
2020-07-06 07:41:58 -0500 commented answer can't run HoughCircles on image

How can I implement Multilevel Otsu threshold in OpenCV and Python?

2020-07-06 05:04:54 -0500 marked best answer can't run HoughCircles on image

I am trying to count objects in an image. To do that this is the approach I am using;

  1. Open an image file
  2. Convert the image file to HSV
  3. Extract S channel
  4. Run Gaussian Filter
  5. Otsu Thresholding
  6. Sobel Edge detection
  7. Hough Circle transform
  8. Detect and count

I have managed to complete the task upto Soble Edge detection. When I run Hough Circle transform, I get following error:

circles = cv.HoughCircles(sobely, cv.HOUGH_GRADIENT,1,20,
cv2.error: OpenCV(4.2.0) /io/opencv/modules/imgproc/src/hough.cpp:1728: error: (-215:Assertion failed) !_image.empty() && _image.type() == CV_8UC1 && (_image.isMat() || _image.isUMat()) in function 'HoughCircles'

This is the code I wrote so far. It is working fine until I try to run HoughCircles on the result of Sobel method.

import cv2 as cv
import numpy as np

src = cv.imread("both.png", cv.IMREAD_COLOR)

src = cv.cvtColor(src, cv.COLOR_RGB2HSV)

h, s, v = cv.split(src)

v = cv.GaussianBlur(v, (3,3),0,0)

ret2, otsu_src = cv.threshold(v,0,250, cv.THRESH_BINARY+cv.THRESH_OTSU)

sobely = cv.Sobel(otsu_src, cv.CV_64F, 0, 1, ksize=1)

circles = cv.HoughCircles(sobely, cv.HOUGH_GRADIENT,1,20,
                            param1=50,param2=30,minRadius=0,maxRadius=-1)

Any help, on how can I fix this error.

image description

2020-07-06 05:04:54 -0500 received badge  Scholar (source)
2020-07-06 04:12:22 -0500 received badge  Student (source)
2020-07-06 03:55:44 -0500 asked a question can't run HoughCircles on image

can't run HoughCircles on image I am trying to count objects in an image. To do that this is the approach I am using;