使用OpenCV将Hough_Circles转换为热图

问题描述 投票:0回答:1

我正在使用霍夫圆算法来检测图像中的圆。一些圈子重叠,而另一些则没有。我需要使用一些指标(如热图)以高概率将重叠区域可视化,以低概率将非重叠区域可视化。如何实现这一目标,对此有一个专门的术语吗?

我需要这个:enter image description here

我得到的是:enter image description here

def display_image(flag=0, frame=None):
# flag 0 - read image from path, flag 1 - image is passed
img = None
cimg = None

if (flag == 0):
    # cv2.imread(img_path, 0) ; 0 - gray image
    img = cv2.imread(img_path, 0)
else:
    img = frame
    img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)

img = cv2.medianBlur(img, 5)
img = cv2.resize(img, (int(img.shape[1]/2), int(img.shape[0]/2)))
cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)

circles = cv2.HoughCircles(
    img, method=cv2.HOUGH_GRADIENT, dp=1, minDist=5, param1=75, param2=30, minRadius=60, maxRadius=100)
    # img, method=cv2.HOUGH_GRADIENT, dp=1, minDist=5, param1=75, param2=30, minRadius=40, maxRadius=100)

#np.around() > EVENLY round to the given number of decimals.
#np.unit16 > Unsigned integer (0 to 65535)
circles = np.uint16(np.around(circles))

for i in circles[0, :]:
    # draw the outer circle
    cv2.circle(cimg, (i[0], i[1]), i[2], (0, 255, 0), -1)
    # draw the center of the circle
    cv2.circle(cimg, (i[0], i[1]), 2, (0, 0, 255), 3)

if (flag == 0):
    #single image
    cv2.imshow('detected circles', cimg)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
else:
    return cimg
python opencv scikit-learn visualization
1个回答
0
投票
# transparency factor
tr = 0.3
for i in circles[0, :]:
    # copy cimg
    temp_img = cimg.copy()
    # draw circle
    cv2.circle(temp_img, (i[0], i[1]), i[2], (255, 255, 255), -1)
    # blend to get transparency
    cimg = np.uint8(np.float64(cimg)*tr + np.float64(temp_img)*(1-tr))
© www.soinside.com 2019 - 2024. All rights reserved.