Skip to Content
Learning OpenCV 4 Computer Vision with Python 3 - Third Edition
book

Learning OpenCV 4 Computer Vision with Python 3 - Third Edition

by Joseph Howse, Joe Minichino
February 2020
Intermediate to advanced
372 pages
9h 26m
English
Packt Publishing
Content preview from Learning OpenCV 4 Computer Vision with Python 3 - Third Edition

Detecting circles

OpenCV also has a function for detecting circles, called HoughCircles. It works in a very similar fashion to HoughLines, but where minLineLength and maxLineGap were the parameters to be used to discard or retain lines, HoughCircles has a minimum distance between a circle's centers, as well as minimum and maximum values for a circle's radius. Here is the obligatory example:

import cv2import numpy as npplanets = cv2.imread('planet_glow.jpg')gray_img = cv2.cvtColor(planets, cv2.COLOR_BGR2GRAY)gray_img = cv2.medianBlur(gray_img, 5)circles = cv2.HoughCircles(gray_img,cv2.HOUGH_GRADIENT,1,120,                           param1=100,param2=30,minRadius=0,maxRadius=0)circles = np.uint16(np.around(circles))for i in circles[0,:]:    # draw the outer circle cv2.circle(planets,(i[0],i[1]),i[2],(0,255,0),2) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Building Computer Vision Projects with OpenCV 4 and C++

Building Computer Vision Projects with OpenCV 4 and C++

David Millan Escriva, Prateek Joshi, Vinicius G. Mendonca, Roy Shilkrot

Publisher Resources

ISBN: 9781789531619Supplemental Content