所需要导入的包
import numpy as np
import cv2 as cv
1.以灰度模式读入图像
gray = cv.imread("bottle_mouth.png", 0)
cv.imshow('gray', gray)
2.对灰度图像进行霍夫圆变换,并使用Numpy对结果进行16位无符号整型转换
circles = cv.HoughCircles(gray, cv.HOUGH_GRADIENT, 1, 100, 100, 50)
circles = np.uint16(circles)
3.从霍夫变换结果中获取圆心和半径
center = (circles[0][0][0], circles[0][0][1]) # 圆心坐标
radius = circles[0][0][2] # 半径大小
4.对灰度图像进行极坐标变换
polar = cv.warpPolar(gray, (300, 900), center, radius, cv.WARP_POLAR_LINEAR)
5.对极坐标变换结果进行极坐标反变换
reverse = cv.warpPolar(polar, (gray.shape[1], gray.shape[0]), center, radius, cv.WARP_INVERSE_MAP)
6.对极坐标反变换结果进行二值化
retval_binary, dst_binary