<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
影象大小按原圖計算
dis_mm是標定板上的實際距離,要根據真實情況計算。
範例程式碼
# coding:utf-8 import math import cv2 import numpy as np import xml.etree.ElementTree as ET import matplotlib.pyplot as plt global DPI DPI = 0.00245 def mainFigure(img): 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 = 10e4 # 圖大要修改 100 params.minDistBetweenBlobs = 100 # 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 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 = 60 _, gray = cv2.threshold(gray, minThreshValue, 255, cv2.THRESH_BINARY) # gray = cv2.resize(gray, dsize=None, fx=1, fy=1, interpolation=cv2.INTER_LINEAR) # gray = cv2.resize(gray, dsize=None, fx=2, fy=2, interpolation=cv2.INTER_LINEAR) # plt.imshow(gray) # cv2.imshow("gray",gray) # 找到距離原點(0,0)最近和最遠的點 h, w = img.shape[:2] detector = cv2.SimpleBlobDetector_create(params) keypoints = detector.detect(gray) print("檢測點為", len(keypoints)) # opencv im_with_keypoints = cv2.drawKeypoints(gray, keypoints, np.array([]), (0, 255, 0), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) # plt # fig = plt.figure() # im_with_keypoints = cv2.drawKeypoints(gray, keypoints, np.array([]), (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) color_img = cv2.cvtColor(im_with_keypoints, cv2.COLOR_BGR2RGB) DPIall = [] if keypoints is not None: # 找到距離(0,0)最近和最遠的點 kpUpLeft = [] disUpLeft = [] for i in range(len(keypoints)): dis = math.sqrt(math.pow(keypoints[i].pt[0],2) + math.pow(keypoints[i].pt[1],2)) disUpLeft.append(dis) kpUpLeft.append(keypoints[i].pt) # cv2.circle(img, (int(keypoints[i].pt[0]), int(keypoints[i].pt[1])), 10, (0, 255, 0), 2) # 找到距離(640*2,0)最近和最遠的點 kpUpRight = [] disUpRight=[] for i in range(len(keypoints)): # 最大距離座標 dis2 = math.sqrt(math.pow(abs(keypoints[i].pt[0]-w),2) + math.pow(abs(keypoints[i].pt[1]),2)) disUpRight.append(dis2) kpUpRight.append(keypoints[i].pt) if disUpRight and disUpLeft: disDownLeftIndex = disUpRight.index(max(disUpRight)) pointDL = kpUpRight[disDownLeftIndex] disUpRightIndex = disUpRight.index(min(disUpRight)) pointUR = kpUpLeft[disUpRightIndex] disDownRightIndex = disUpLeft.index(max(disUpLeft)) pointDR = kpUpLeft[disDownRightIndex] disUpLeftIndex = disUpLeft.index(min(disUpLeft)) pointUL = kpUpLeft[disUpLeftIndex] if (pointDR is not None) and (pointUL is not None) and (pointDL is not None) and (pointUR is not None): # cv2.circle(color_img, (int(pointDR[0]),int(pointDR[1])), 30, (0, 255, 0),2) # cv2.circle(color_img, (int(pointUL[0]),int(pointUL[1])), 30, (0, 255, 0),2) # cv2.line(color_img,(int(pointDR[0]),int(pointDR[1])), (int(pointDL[0]),int(pointDL[1])),(0, 0, 255),2) # # cv2.circle(color_img, (int(pointDL[0]),int(pointDL[1])), 30, (0, 255, 0),2) # cv2.circle(color_img, (int(pointUR[0]),int(pointUR[1])), 30, (0, 255, 0),2) # cv2.line(color_img, (int(pointDL[0]),int(pointDL[1])), (int(pointUR[0]),int(pointUR[1])), (0, 0, 255), 2) # cv2.line(color_img, (int(pointUL[0]),int(pointUL[1])), (int(pointUR[0]),int(pointUR[1])), (0, 0, 255), 2) # 顯示在原圖上 原圖減半因為之前放大了 # cv2.circle(img, (int(pointDR[0]/2), int(pointDR[1]/2)), 10, (0, 255, 0), 2) # cv2.circle(img, (int(pointUL[0]/2), int(pointUL[1]/2)), 10, (0, 255, 0), 2) # cv2.line(img,(int(pointDR[0]/2),int(pointDR[1]/2)), (int(pointUL[0]/2),int(pointUL[1]/2)),(0, 0, 255),2) # dis_UR_DL = math.sqrt(math.pow(pointUR[0]-pointDL[0], 2) + math.pow(pointUR[1]-pointDL[1], 2))/2 cv2.circle(img, (int(pointDR[0] ), int(pointDR[1] )), 10, (0, 255, 0), 2) cv2.circle(img, (int(pointUL[0] ), int(pointUL[1] )), 10, (0, 255, 0), 2) cv2.line(img, (int(pointDR[0] ), int(pointDR[1] )), (int(pointUL[0] ), int(pointUL[1] )), (0, 0, 255), 2) dis_UR_DL = math.sqrt(math.pow(pointUR[0] - pointDL[0], 2) + math.pow(pointUR[1] - pointDL[1], 2)) DPIall.append(dis_UR_DL) global DPI # 只計算斜對角線,約束條件簡單一些,增加適用性 # 單邊長a = 0.05*19 對角線 # DPI = (math.sqrt(1.3435)) / sum(DPIall) dis_mm = math.sqrt(math.pow(15, 2) + math.pow(15, 2)) print("兩點的畫素距離為", dis_UR_DL, "實際距離為", dis_mm) DPI = dis_mm / dis_UR_DL print("DPI", DPI) # configFile_xml = "wellConfig.xml" # tree = ET.parse(configFile_xml) # root = tree.getroot() # secondRoot = root.find("DPI") # print(secondRoot.text) # # secondRoot.text = str(DPI) # tree.write("wellConfig.xml") # print("DPI", DPI) else: pass print(DPI) # plt.imshow(color_img,interpolation='bicubic') # fname = "key points" # titlestr = '%s found %d keypoints' % (fname, len(keypoints)) # plt.title(titlestr) # # fig.canvas.set_window_title(titlestr) # plt.show() # cv2.imshow('findCorners', color_img) cv2.namedWindow('findCorners',2) cv2.imshow('findCorners', img) cv2.waitKey() if __name__ == "__main__": # # # 單張圖片測試 # DPI hole # 0.01221465904139037 # # DPI needle # 0.012229753249515942 # img = cv2.imread("TwoBiaoDing/ROI_needle.jpg",1) img = cv2.imread("TwoBiaoDing/ROI_holes.jpg",1) img_roi = img.copy() # img_roi = img[640:2000, 1530:2800] # cv2.namedWindow("img_roi",2) # cv2.imshow("img_roi", img_roi) # cv2.waitKey() # img = cv2.imread("circles/Snap_0.jpg",1) mainFigure(img_roi) # # 所有圖片測試 # for i in range(15): # fileName = "Snap_" + str(i) + ".jpg" # # img = cv2.imread("circles/Snap_007.jpg",1) # img = cv2.imread("circles/" + fileName,1) # print(fileName) # mainFigure(img)
到此這篇關於Python+OpenCV實現尋找到圓點標定板的角點的文章就介紹到這了,更多相關Python OpenCV尋找角點內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45