Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opencv CUDA detected much more Hough circles than CPU #5

Open
zachary-zheng opened this issue Jan 27, 2021 · 0 comments
Open

Opencv CUDA detected much more Hough circles than CPU #5

zachary-zheng opened this issue Jan 27, 2021 · 0 comments

Comments

@zachary-zheng
Copy link

Hello,

System information (version)
OpenCV 4.5.1, Windows 10 64 bits, Python3.7, Cuda 10.2

Detailed description
I have found that cuda HoughCirclesDetector gives much more circles than CPU HougnCircles with the same parameters.
Also the parameter minDist seems inefficient, larger the minDist is, it still gives the circels between which distance less than minDist.

For pic "eight.tif", it gives incrediable 24 circles , the code as following:

import cv2
import numpy as np
gpuImg = cv2.cuda_GpuMat()
def cv_show(name, image):
    cv2.namedWindow(name, cv2.WINDOW_NORMAL)
    cv2.imshow(name, image)

    cv2.waitKey(0)
    cv2.destroyAllWindows()
def getGpuResize(src):
    global gpuImg
    basePixSize = 1280
    height = src.shape[0]
    width = src.shape[1]
    print('height:', height)
    print('width:', width)
    largeSize = max(height, width)
    resizeRate = basePixSize/largeSize
    gpuImg.upload(src)
    gpuDst = cv2.cuda.resize(gpuImg, (int(width*resizeRate),int(height*resizeRate)))
    return gpuDst

def getGpuCircles(gpuSrc,src):
    ksize = (5,5)
    gpuFilter = cv2.cuda.createGaussianFilter(srcType=cv2.CV_8UC1, dstType=cv2.CV_8UC1, ksize=ksize, sigma1=0, sigma2=0)
    gpuSrc = cv2.cuda_Filter.apply(gpuFilter, gpuSrc)
    detector = cv2.cuda.createHoughCirclesDetector(dp=1, minDist=100, cannyThreshold=122, votesThreshold=50,
                                                   minRadius=1,
                                                   maxRadius=308)  # 100/110/50/445/510 or 150/110/50/430/510/MINRADIUS260
    cuCircles = detector.detect(gpuSrc)
    circles = cuCircles.download()
    print("circles0:", circles)
    print(circles.shape)
    if circles is not None:  # detect circles
        circles = np.uint0(np.around(circles))
        print("circles1:", circles)
    for circle in circles[0, :]:
        dst = cv2.circle(src, (circle[0], circle[1]), circle[2], (255, 0, 255), 2)
    return dst
if __name__ == '__main__':
    img = cv2.imread('./eight.tif', cv2.IMREAD_GRAYSCALE)
    cuImg = getGpuResize(img)
    img = cuImg.download()
    print(img.shape)
    # cv_show('img', img)
    dst = getGpuCircles(cuImg, img)
    cv_show('res', dst)

Appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant