[英]Transform Hough_Circles into a heatmap using OpenCV
I'm using Hough Circles algorithm to detect circles in an image.我正在使用 Hough Circles 算法来检测图像中的圆圈。 Some circles ovelap while others don't.有些圆圈重叠,而有些则没有。 I need to visualize the over lapping area with a high probability and non overlapping areas with low probability with some indicator(As a heat map).我需要用一些指标(作为热图)可视化高概率的重叠区域和低概率的非重叠区域。 How to achive this and is there a specific term for this?如何实现这一点,是否有具体的术语?
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
# 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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.