Python+OpenCV实现图片中的圆形检测
效果展示
中心的三个没检测到
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实现图片中的圆形检测的详细内容,更多关于Python OpenCV圆形检测的资料请关注脚本之家其它相关文章!
X 关闭
X 关闭
- 15G资费不大降!三大运营商谁提供的5G网速最快?中国信通院给出答案
- 2联想拯救者Y70发布最新预告:售价2970元起 迄今最便宜的骁龙8+旗舰
- 3亚马逊开始大规模推广掌纹支付技术 顾客可使用“挥手付”结账
- 4现代和起亚上半年出口20万辆新能源汽车同比增长30.6%
- 5如何让居民5分钟使用到各种设施?沙特“线性城市”来了
- 6AMD实现连续8个季度的增长 季度营收首次突破60亿美元利润更是翻倍
- 7转转集团发布2022年二季度手机行情报告:二手市场“飘香”
- 8充电宝100Wh等于多少毫安?铁路旅客禁止、限制携带和托运物品目录
- 9好消息!京东与腾讯续签三年战略合作协议 加强技术创新与供应链服务
- 10名创优品拟通过香港IPO全球发售4100万股 全球发售所得款项有什么用处?