最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python+OpenCV實現(xiàn)尋找到圓點標(biāo)定板的角點

 更新時間:2022年11月06日 10:27:06   作者:天人合一peng  
這篇文章主要為大家詳細(xì)介紹了Python+OpenCV實現(xiàn)找到圓點標(biāo)定板所有點后通過距離找兩個角點,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下

圖像大小按原圖計算

dis_mm是標(biāo)定板上的實際距離,要根據(jù)真實情況計算。

示例代碼

# 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)最近和最遠(yuǎn)的點
    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)最近和最遠(yuǎn)的點
        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)最近和最遠(yuǎn)的點
        kpUpRight = []
        disUpRight=[]
        for i in range(len(keypoints)):
            # 最大距離坐標(biāo)
            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)

到此這篇關(guān)于Python+OpenCV實現(xiàn)尋找到圓點標(biāo)定板的角點的文章就介紹到這了,更多相關(guān)Python OpenCV尋找角點內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python 批量讀取文件中指定字符的實現(xiàn)

    Python 批量讀取文件中指定字符的實現(xiàn)

    這篇文章主要介紹了Python 批量讀取文件中指定字符的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • jupyter notebook快速入門及使用詳解

    jupyter notebook快速入門及使用詳解

    這篇文章主要介紹了jupyter notebook快速入門及使用詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • python中self原理實例分析

    python中self原理實例分析

    這篇文章主要介紹了python中self原理,較為詳細(xì)的分析了self的原理與相關(guān)的使用技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-04-04
  • python爬蟲beautifulsoup解析html方法

    python爬蟲beautifulsoup解析html方法

    這篇文章主要介紹了python爬蟲beautifulsoup解析html方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • python udp如何實現(xiàn)同時收發(fā)信息

    python udp如何實現(xiàn)同時收發(fā)信息

    這篇文章主要介紹了python udp如何實現(xiàn)同時收發(fā)信息,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • pandas中提取DataFrame某些列的一些方法

    pandas中提取DataFrame某些列的一些方法

    dataframe是pandas包的重要對象,熟練掌握dataframe的基本操作是很有必要的,下面這篇文章主要給大家介紹了關(guān)于pandas中提取DataFrame某些列的一些方法,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-06-06
  • pytorch 調(diào)整某一維度數(shù)據(jù)順序的方法

    pytorch 調(diào)整某一維度數(shù)據(jù)順序的方法

    今天小編就為大家分享一篇pytorch 調(diào)整某一維度數(shù)據(jù)順序的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • Python?ORM數(shù)據(jù)庫框架Sqlalchemy的使用教程詳解

    Python?ORM數(shù)據(jù)庫框架Sqlalchemy的使用教程詳解

    對象關(guān)系映射(Object?Relational?Mapping,簡稱ORM)模式是一種為了解決面向?qū)ο笈c關(guān)系數(shù)據(jù)庫存在的互不匹配的現(xiàn)象的技術(shù)。本文主要介紹了其使用的相關(guān)資料,感興趣的小伙伴可以學(xué)習(xí)一下
    2022-10-10
  • Python 使用生成器代替線程的方法

    Python 使用生成器代替線程的方法

    這篇文章主要介紹了Python 使用生成器代替線程的方法,文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-08-08
  • Python3中的2to3轉(zhuǎn)換工具使用示例

    Python3中的2to3轉(zhuǎn)換工具使用示例

    這篇文章主要介紹了Python3中的2to3轉(zhuǎn)換工具使用示例,本文詳細(xì)講解了使用的步驟,并總結(jié)了一些使用注意事項,需要的朋友可以參考下
    2015-06-06

最新評論

宣武区| 象州县| 全州县| 江北区| 苍溪县| 蕉岭县| 宁海县| 濮阳市| 罗城| 霍邱县| 凤山县| 南靖县| 寻甸| 九台市| 崇州市| 龙岩市| 苗栗市| 明水县| 忻州市| 怀柔区| 平顺县| 潮安县| 九龙城区| 乐清市| 张家界市| 阿克苏市| 广西| 霍林郭勒市| 长兴县| 余干县| 佛坪县| 广灵县| 海口市| 江口县| 东乡族自治县| 青阳县| 新昌县| 翁牛特旗| 玉屏| 兴文县| 嘉定区|