本文整理汇总了Python中cv2.HoughCircles方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.HoughCircles方法的具体用法?Python cv2.HoughCircles怎么用?Python cv2.HoughCircles使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2
的用法示例。
在下文中一共展示了cv2.HoughCircles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: findPiccircle
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughCircles [as 别名]
def findPiccircle(frame, color):
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
color_dict = color_list.getColorList()
mask = cv2.inRange(hsv, color_dict[color][0], color_dict[color][1])
dilated = cv2.dilate(mask, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)), iterations=2)
## 需要修改minRadius以及maxRadius,用来限制识别圆的大小,排除其他的干扰
circles = cv2.HoughCircles(dilated, cv2.HOUGH_GRADIENT, 1, 1000, param1=15, param2=10, minRadius=15, maxRadius=50)
center = None
if circles is not None:
x, y, radius = circles[0][0]
center = (x, y)
cv2.circle(frame, center, radius, (0, 255, 0), 2)
cv2.circle(frame, center, 2, (0,255,0), -1, 8, 0 );
print('圆心:{}, {}'.format(x, y))
cv2.imshow('result', frame)
if center != None:
return center
示例2: hough_circles
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughCircles [as 别名]
def hough_circles(self):
src = self.cv_read_img(self.src_file)
if src is None:
return
dst = cv.pyrMeanShiftFiltering(src, 10, 100)
cimage = cv.cvtColor(dst, cv.COLOR_BGR2GRAY)
circles = cv.HoughCircles(cimage, cv.HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=0, maxRadius=0)
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
cv.circle(src, (i[0], i[1]), i[2], (0, 0, 255), 2)
cv.circle(src, (i[0], i[1]), 2, (255, 0, 255), 2)
self.decode_and_show_dst(src)
# 轮廓发现
示例3: CountCoins
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughCircles [as 别名]
def CountCoins(img, cimg):
circles = []
try:
circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,20,
param1=50,param2=30,minRadius=0,maxRadius=0)
except:
circles = cv2.HoughCircles(img, cv.CV_HOUGH_GRADIENT,1,20,param1=50,param2=30,minRadius=0,maxRadius=0)
if(circles is None):
return
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), 2)
# draw the center of the circle
cv2.circle(cimg, (i[0], i[1]), 2, (0, 0, 255), 3)
示例4: FindWand
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughCircles [as 别名]
def FindWand():
global rval,old_frame,old_gray,p0,mask,color,ig,img,frame
try:
rval, old_frame = cam.read()
cv2.flip(old_frame,1,old_frame)
old_gray = cv2.cvtColor(old_frame,cv2.COLOR_BGR2GRAY)
equalizeHist(old_gray)
old_gray = GaussianBlur(old_gray,(9,9),1.5)
dilate_kernel = np.ones(dilation_params, np.uint8)
old_gray = cv2.dilate(old_gray, dilate_kernel, iterations=1)
clahe = cv2.createCLAHE(clipLimit=3.0, tileGridSize=(8,8))
old_gray = clahe.apply(old_gray)
#TODO: trained image recognition
p0 = cv2.HoughCircles(old_gray,cv2.HOUGH_GRADIENT,3,50,param1=240,param2=8,minRadius=4,maxRadius=15)
if p0 is not None:
p0.shape = (p0.shape[1], 1, p0.shape[2])
p0 = p0[:,:,0:2]
mask = np.zeros_like(old_frame)
ig = [[0] for x in range(20)]
print "finding..."
threading.Timer(3, FindWand).start()
except:
e = sys.exc_info()[1]
print "Error: %s" % e
exit
示例5: read_captured_circles
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughCircles [as 别名]
def read_captured_circles(self):
img = cv2.cvtColor(self.query, cv2.COLOR_BGR2GRAY)
img = cv2.medianBlur(img, 7)
cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, 30,
param1=50, param2=30, minRadius=20, maxRadius=50)
if circles is None:
return
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
if i[1] < 400:
continue
self.circlePoints.append((i[0], i[1]))
if self._debug:
self.draw_circles(circles, cimg)
示例6: capture_white_circles
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughCircles [as 别名]
def capture_white_circles(self):
self.prep_for_white_circles()
img = cv2.cvtColor(self.white_query, cv2.COLOR_BGR2GRAY)
img = cv2.medianBlur(img, 1)
cimg = cv2.cvtColor(self.query, cv2.COLOR_BGR2RGB)
circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, img.shape[0] / 15,
param1=50, param2=22, minRadius=5, maxRadius=60)
if circles is None:
return
circles = np.uint16(np.around(circles))
new_circles = []
for i in circles[0, :]:
if self.in_box(i[0], i[1]) and not self.in_blacklist(i[0], i[1]):
self.circlePoints.append((i[0], i[1]))
new_circles.append(i)
if self._debug:
# self.draw_circles(circles, cimg)
if len(new_circles) > 0:
self.draw_circles(np.array([new_circles]), cimg)
示例7: findCircles
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughCircles [as 别名]
def findCircles(hue, intensity):
houghCirclesMask = np.zeros(hue.shape, dtype=np.uint8)
blurred_hue = cv2.GaussianBlur(hue, (9, 9), 2)
blurred_intensity = cv2.GaussianBlur(intensity, (9, 9), 2)
hue_circles = cv2.HoughCircles(blurred_hue, cv2.cv.CV_HOUGH_GRADIENT, 0.5, hue.shape[0] / 8, param1=10, param2=25, maxRadius=100)
intensity_circles = cv2.HoughCircles(blurred_intensity, cv2.cv.CV_HOUGH_GRADIENT, 0.5, hue.shape[0] / 8, param1=185, param2=20, maxRadius=100)
circles = np.vstack((hue_circles[0] if hue_circles is not None else np.empty((0, 3)),
intensity_circles[0] if intensity_circles is not None else np.empty((0, 3))))
for (x, y, r) in circles:
cv2.circle(houghCirclesMask, (int(round(x)), int(round(y))), int(round(r)), 255, -1)
return houghCirclesMask
示例8: detect_circles
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughCircles [as 别名]
def detect_circles(self,gray,img):
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 100, param2=150, minRadius=160)
circles = np.uint16(np.around(circles)) # 把circles包含的圆心和半径的值变成整数
cir = img.copy()
for i in circles[0, :]:
cv2.circle(cir, (i[0], i[1]), i[2], (0, 255, 0), 2, cv2.LINE_AA) # 画圆
cv2.circle(cir, (i[0], i[1]), 2, (0, 255, 0), 2, cv2.LINE_AA) # 画圆心
cv2.imshow("circles", cir)
return cir
# 霍夫直线变换:检测指针
示例9: detect_blob
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughCircles [as 别名]
def detect_blob(self, img, filters):
"""
"filters" must be something similar to:
filters = {
'R': (150, 255), # (min, max)
'S': (150, 255),
}
"""
acc_mask = ones(img.shape[:2], dtype=uint8) * 255
rgb = img.copy()
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
for c, (min, max) in filters.items():
img = rgb if c in 'RGB' else hsv
mask = img[:, :, self.channels[c]]
mask[mask < min] = 0
mask[mask > max] = 0
acc_mask &= mask
kernel = ones((5, 5), uint8)
acc_mask = cv2.dilate(cv2.erode(acc_mask, kernel), kernel)
circles = cv2.HoughCircles(acc_mask, cv2.HOUGH_GRADIENT, 3, img.shape[0] / 5.)
return circles.reshape(-1, 3) if circles is not None else []
示例10: find_circular_wells
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughCircles [as 别名]
def find_circular_wells(self):
"""Simply use Hough transform to find circles in MultiWell Plate rgb image.
The parameters used are optimised for 24 or 48WP"""
dwnscl_factor = self.img_shape[0]/self.blur_im.shape[0]
# find circles
# parameters in downscaled units
circle_goodness = 70;
highest_canny_thresh = 10;
min_well_dist = self.blur_im.shape[1]/3; # max 3 wells along short side. bank on FOV not taking in all the entirety of the well
min_well_radius = self.blur_im.shape[1]//7; # if 48WP 3 wells on short side ==> radius <= side/6
max_well_radius = self.blur_im.shape[1]//4; # if 24WP 2 wells on short side. COnsidering intrawells space, radius <= side/4
# find circles
_circles = cv2.HoughCircles(self.blur_im,
cv2.HOUGH_GRADIENT,
dp=1,
minDist=min_well_dist,
param1=highest_canny_thresh,
param2=circle_goodness,
minRadius=min_well_radius,
maxRadius=max_well_radius)
_circles = np.squeeze(_circles); # because why the hell is there an empty dimension at the beginning?
# convert back to pixels
_circles *= dwnscl_factor;
# output back into class property
self.wells['x'] = _circles[:,0].astype(int)
self.wells['y'] = _circles[:,1].astype(int)
self.wells['r'] = _circles[:,2].astype(int)
return
示例11: cropImage
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughCircles [as 别名]
def cropImage(self, screenshot, captureTime, captureLat, captureLng, src_path):
p = None
raidNo = 0
processes = []
hash = str(time.time())
orgScreen = screenshot
height, width, channel = screenshot.shape
gray=cv2.cvtColor(screenshot,cv2.COLOR_BGR2GRAY)
gray=cv2.GaussianBlur(gray, (7, 7), 2)
minRadius = int(((width / 4.736)) / 2)
maxRadius = int(((width / 4.736)) / 2)
log.debug('Searching for Raid Circles with Radius from %s to %s px' % (str(minRadius), str(maxRadius)))
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 20, param1=50,param2=30, minRadius=minRadius, maxRadius=maxRadius)
if circles is not None:
circles = np.round(circles[0, :]).astype("int")
for (x, y, r) in circles:
log.debug('Found Circle with x:%s, y:%s, r:%s' % (str(x), str(y), str(r)))
raidNo += 1
raidCropFilepath = os.path.join(args.temp_path, str(hash) + "_raidcrop" + str(raidNo) +".jpg")
new_crop = orgScreen[y-r-int((r*2*0.03)):y+r+int((r*2*0.75)), x-r-int((r*2*0.03)):x+r+int((r*2*0.3))]
cv2.imwrite(raidCropFilepath, new_crop)
if args.ocr_multitask:
p = multiprocessing.Process(target=RaidScan.process, name='OCR-crop-analysis-' + str(raidNo), args=(raidCropFilepath, hash, raidNo, captureTime, captureLat, captureLng, src_path, r))
else:
p = Thread(target=RaidScan.process, name='OCR-processing', args=(raidCropFilepath, hash, raidNo, captureTime, captureLat, captureLng, src_path, r))
processes.append(p)
p.daemon = True
p.start()
示例12: cropImage
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughCircles [as 别名]
def cropImage(self, image, raidNo, radius):
gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
gray=cv2.GaussianBlur(gray, (7, 7), 2)
output = image.copy()
height, width, channel = output.shape
output = output[0:height*2/3,0:width]
image_cols, image_rows, _ = image.shape
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 20, param1=50,param2=30, minRadius=radius, maxRadius=radius)
if circles is not None:
circles = np.round(circles[0, :]).astype("int")
for (x, y, r) in circles:
log.debug('[Crop: ' + str(raidNo) + ' (' + str(self.uniqueHash) +') ] ' + 'cropImage: Detect crop coordinates x: ' + str(x) +' y: ' + str(y) +' with radius: ' + str(r))
new_crop = output[y-r:y+r, x-r:x+r]
return new_crop
return False
示例13: FindNewPoints
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughCircles [as 别名]
def FindNewPoints():
global old_frame,old_gray,p0,mask,color,ig,img,frame
try:
try:
old_frame = cam.capture(stream, format='jpeg')
except:
print("resetting points")
data = np.fromstring(stream.getvalue(), dtype=np.uint8)
old_frame = cv2.imdecode(data, 1)
cv2.flip(old_frame,1,old_frame)
old_gray = cv2.cvtColor(old_frame,cv2.COLOR_BGR2GRAY)
#cv2.equalizeHist(old_gray,old_gray)
#old_gray = cv2.GaussianBlur(old_gray,(9,9),1.5)
#dilate_kernel = np.ones(dilation_params, np.uint8)
#old_gray = cv2.dilate(old_gray, dilate_kernel, iterations=1)
#TODO: trained image recognition
p0 = cv2.HoughCircles(old_gray,cv2.HOUGH_GRADIENT,3,100,param1=100,param2=30,minRadius=4,maxRadius=15)
p0.shape = (p0.shape[1], 1, p0.shape[2])
p0 = p0[:,:,0:2]
mask = np.zeros_like(old_frame)
ig = [[0] for x in range(20)]
print("finding...")
TrackWand()
#This resets the scene every three seconds
threading.Timer(3, FindNewPoints).start()
except:
e = sys.exc_info()[1]
print("FindWand Error: %s" % e )
End()
exit
示例14: predict_from_cam
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughCircles [as 别名]
def predict_from_cam():
ret,image_data = cap.read()
if ret:
predict(image_data)
else:
logger.error("image capture faild")
# Use OpenCV HoughCircles to find sushi saucer.
示例15: _get_circles
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import HoughCircles [as 别名]
def _get_circles(image_segment, params):
temp = cv2.HoughCircles(image_segment.segmented_image, cv2.HOUGH_GRADIENT, params.dp, params.minDist,
param1=params.param1, param2=params.param2,
minRadius=params.minRadius, maxRadius=params.maxRadius)
if temp is None:
return []
circle_tuples = temp[0]
if len(circle_tuples) > params.max_num:
circle_tuples = circle_tuples[:params.max_num]
circles = [instantiators['circle'](instantiators['point'](x, y), radius)
for x, y, radius in circle_tuples]
return circles