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)文章
Python實(shí)現(xiàn)的基數(shù)排序算法原理與用法實(shí)例分析
這篇文章主要介紹了Python實(shí)現(xiàn)的基數(shù)排序算法,簡(jiǎn)單說(shuō)明了基數(shù)排序的原理并結(jié)合實(shí)例形式分析了Python實(shí)現(xiàn)與使用基數(shù)排序的具體操作技巧,需要的朋友可以參考下2017-11-11
Python eval的常見(jiàn)錯(cuò)誤封裝及利用原理詳解
這篇文章主要介紹了Python eval的常見(jiàn)錯(cuò)誤封裝及利用原理詳解,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-03-03
python使用pyecharts庫(kù)畫(huà)地圖數(shù)據(jù)可視化的實(shí)現(xiàn)
這篇文章主要介紹了python使用pyecharts庫(kù)畫(huà)地圖數(shù)據(jù)可視化的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03
創(chuàng)建SparkSession和sparkSQL的詳細(xì)過(guò)程
SparkSession 是 Spark SQL 的入口,Builder 是 SparkSession 的構(gòu)造器。 通過(guò) Builder, 可以添加各種配置,并通過(guò) stop 函數(shù)來(lái)停止 SparkSession,本文給大家分享創(chuàng)建SparkSession和sparkSQL的詳細(xì)過(guò)程,一起看看吧2021-08-08
Django重裝mysql后啟動(dòng)報(bào)錯(cuò):No module named ‘MySQLdb’的解決方法
這篇文章主要給大家介紹了關(guān)于Django重裝mysql后啟動(dòng)報(bào)錯(cuò):No module named ‘MySQLdb’的解決方法,分享出來(lái),對(duì)同樣遇到這個(gè)問(wèn)題的朋友們一個(gè)參考學(xué)習(xí),需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2018-04-04
python百行代碼實(shí)現(xiàn)漢服圈圖片爬取
這篇文章主要為大家介紹了使用python百行代碼來(lái)實(shí)現(xiàn)漢服圈的圖片爬取,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2021-11-11
詳解Python Celery和RabbitMQ實(shí)戰(zhàn)教程
這篇文章主要介紹了詳解Python Celery和RabbitMQ實(shí)戰(zhàn)教程,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01
Pandas數(shù)據(jù)清洗和預(yù)處理的實(shí)現(xiàn)示例
本文主要介紹了Pandas數(shù)據(jù)清洗和預(yù)處理的實(shí)現(xiàn)示例,包括處理缺失值、異常值,進(jìn)行數(shù)據(jù)轉(zhuǎn)換和規(guī)范化,以及處理重復(fù)數(shù)據(jù)等操作,感興趣的可以了解一下2024-01-01

