Python+OpenCV實(shí)現(xiàn)圖片中的圓形檢測(cè)
效果展示



中心的三個(gè)沒(méi)檢測(cè)到
import cv2
import numpy as np
import matplotlib.pyplot as plt
w = 20
h = 5
params = cv2.SimpleBlobDetector_Params()
# Setup SimpleBlobDetector parameters.
print('params')
print(params)
print(type(params))
# Filter by Area.
params.filterByArea = True
params.minArea = 10e1
params.maxArea = 10e3
params.minDistBetweenBlobs = 25
# params.filterByColor = True
params.filterByConvexity = False
# tweak these as you see fit
# Filter by Circularity
# params.filterByCircularity = False
# params.minCircularity = 0.2
# params.blobColor = 0
# # # Filter by Convexity
# params.filterByConvexity = True
# params.minConvexity = 0.87
# Filter by Inertia
# params.filterByInertia = True
# params.filterByInertia = False
# params.minInertiaRatio = 0.01
# img = cv2.imread("circles/circels.jpg",1)
img = cv2.imread("circles/Snap_001.jpg",1)
gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# Detect blobs.
# image = cv2.resize(gray_img, (int(img.shape[1]/4),int(img.shape[0]/4)), 1, 1, cv2.INTER_LINEAR)
# image = cv2.resize(gray_img, dsize=None, fx=0.25, fy=0.25, interpolation=cv2.INTER_LINEAR)
minThreshValue = 120
_, gray = cv2.threshold(gray, minThreshValue, 255, cv2.THRESH_BINARY)
gray = cv2.resize(gray, dsize=None, fx=2, fy=2, interpolation=cv2.INTER_LINEAR)
# plt.imshow(gray)
# cv2.imshow("gray",gray)
detector = cv2.SimpleBlobDetector_create(params)
keypoints = detector.detect(gray)
print(len(keypoints))
fig = plt.figure()
# im_with_keypoints = cv2.drawKeypoints(gray, keypoints, np.array([]), (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
im_with_keypoints = cv2.drawKeypoints(gray, keypoints, np.array([]), (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
plt.imshow(cv2.cvtColor(im_with_keypoints, cv2.COLOR_BGR2RGB),interpolation='bicubic')
fname = "key points"
titlestr = '%s found %d keypoints' % (fname, len(keypoints))
plt.title(titlestr)
plt.show()
# cv2.imshow("graykey",gray)
# cv2.waitKey()
fig.canvas.set_window_title(titlestr)
ret, corners = cv2.findCirclesGrid(gray, (w, h), flags=(cv2.CALIB_CB_SYMMETRIC_GRID + cv2.CALIB_CB_CLUSTERING ), blobDetector=detector )
if corners is not None:
cv2.drawChessboardCorners(img, (w, h), corners, corners is not None)
print("find blob")
# # cv2.imshow('findCorners', img)
# cv2.waitKey()
plt.imshow(img)
plt.show()以上就是Python+OpenCV實(shí)現(xiàn)圖片中的圓形檢測(cè)的詳細(xì)內(nèi)容,更多關(guān)于Python OpenCV圓形檢測(cè)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
pytorch實(shí)現(xiàn)mnist手寫彩色數(shù)字識(shí)別
這篇文章主要介紹了pytorch-實(shí)現(xiàn)mnist手寫彩色數(shù)字識(shí)別,文章圍繞主題展開詳細(xì)的內(nèi)容姐介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-09-09
selenium+超級(jí)鷹實(shí)現(xiàn)模擬登錄12306
這篇文章主要介紹了selenium+超級(jí)鷹實(shí)現(xiàn)模擬登錄12306,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01
Python測(cè)試函數(shù)出現(xiàn)AssertionError:None?!=?‘Janis?Joplin‘問(wèn)題及解決
這篇文章主要介紹了Python測(cè)試函數(shù)出現(xiàn)AssertionError:None?!=?‘Janis?Joplin‘問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-09-09
python設(shè)置檢查點(diǎn)簡(jiǎn)單實(shí)現(xiàn)代碼
這篇文章主要介紹了python設(shè)置檢查點(diǎn)簡(jiǎn)單實(shí)現(xiàn)代碼,需要的朋友可以參考下2014-07-07
解決Tensorflow2.0 tf.keras.Model.load_weights() 報(bào)錯(cuò)處理問(wèn)題
這篇文章主要介紹了解決Tensorflow2.0 tf.keras.Model.load_weights() 報(bào)錯(cuò)處理問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨想過(guò)來(lái)看看吧2020-06-06
python 自動(dòng)提交和抓取網(wǎng)頁(yè)
最近在研究怎么樣做個(gè)自動(dòng)發(fā)帖器,要完成這個(gè)工具難度蠻大的,驗(yàn)證碼就是一個(gè)大問(wèn)題(還沒(méi)有想到解決辦法哦,不管了),先要解決的是如何抓取,分析和提交頁(yè)面的問(wèn)題。2009-07-07
python之broadcast和numpy.sum()函數(shù)用法及說(shuō)明
這篇文章主要介紹了python之broadcast和numpy.sum()函數(shù)用法及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06
Python在字典中獲取帶權(quán)重的隨機(jī)值實(shí)現(xiàn)方式
這篇文章主要介紹了Python在字典中獲取帶權(quán)重的隨機(jī)值,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-11-11
django項(xiàng)目用higcharts統(tǒng)計(jì)最近七天文章點(diǎn)擊量
這篇文章主要介紹了django項(xiàng)目用higcharts統(tǒng)計(jì)最近七天文章點(diǎn)擊量,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-08-08

