Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 2088

can't run HoughCircles on image

$
0
0
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.

Viewing all articles
Browse latest Browse all 2088

Trending Articles