国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

指針式儀表識別讀數(shù) Python(已開源數(shù)據(jù)集)

這篇具有很好參考價值的文章主要介紹了指針式儀表識別讀數(shù) Python(已開源數(shù)據(jù)集)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。


一、前言

第一個版本的指針式儀表識別讀數(shù)程序?qū)懙糜悬c亂,有空重新整理下代碼,寫成了類MeterDetection進行封裝。
原始指針儀表識別地址
基于深度學習方法的指針識別
程序地址:指針式儀表讀數(shù)源碼github
數(shù)據(jù)集為coco.zip,在github中
記得點個star

二、使用方法


1.安裝相關(guān)的庫

pip install -r requirments.txt

numpy==1.19.5
opencv_python==4.5.5.64

2.運行

python main.py

<main.py>

from MeterClass import *
if __name__ =="__main__":  

    #多張圖片,修改輸入文件夾

    # imglist=glob.glob('input/*.jpg')  
    # for imgpath in  imglist: 
    #     A=MeterDetection(imgpath)
    #     A.Readvalue()
    #一張圖片
    imgpath='images/1.jpg'
    A=MeterDetection(imgpath) 	#創(chuàng)建類對象
    readValue=A.Readvalue()		#調(diào)用類方法

三、方法說明

MeterDetection類說明

<MeterClass.py>

類參數(shù)

定義了類中的相關(guān)參數(shù)

class MeterDetection:
    def __init__(self,path):
        self.imageName=path.split('/')[-1].split('.')[0]
        self.outputPath=os.getcwd()+'/outputs/'
        self.image=cv2.imread(path)
        self.circleimg=None
        self.panMask=None           #霍夫圓檢測切割的表盤圖片
        self.poniterMask =None      #指針圖片
        self.numLineMask=None       #刻度線圖片
        self.centerPoint=None       #中心點[x,y]
        self.farPoint=None          #指針端點[x,y]
        self.zeroPoint=None         #起始點[x,y]
        self.r=None                 #半徑
        self.divisionValue=100/360  #分度值
        self.makeFiledir()
        self.markZeroPoint()

主函數(shù)

調(diào)用類中其他的方法進行儀表讀數(shù)

 def Readvalue(self):
        try:
            self.ImgCutCircle()
            self.ContoursFilter()
            self.FitNumLine()
            self.getIntersectionPoints()
            self.FitPointerLine()
            v1=[self.zeroPoint[0]-self.centerPoint[0],self.centerPoint[1]-self.zeroPoint[1]]
            v2=[self.farPoint[0]-self.centerPoint[0],self.centerPoint[1]-self.farPoint[1]]
            theta=Functions.GetClockAngle(v1,v2)
            readValue=self.divisionValue*theta
            print(theta,readValue)
            return readValue
        except Exception as e:# 寫一個except
            print("程序錯誤:",e)

self.ImgCutCircle() 截取表盤區(qū)域,濾除背景

    def ImgCutCircle(self):
        #截取表盤區(qū)域,濾除背景
        img=self.image
        dst = cv2.pyrMeanShiftFiltering(img, 10, 100)
        cimage = cv2.cvtColor(dst, cv2.COLOR_BGR2GRAY)
        circles = cv2.HoughCircles(cimage, cv2.HOUGH_GRADIENT, 1, 80, param1=100, param2=20, minRadius=80, maxRadius=0)
        circles = np.uint16(np.around(circles))  # 把類型換成整數(shù)
        r_1 = circles[0, 0, 2]
        c_x = circles[0, 0, 0]
        c_y = circles[0, 0, 1]
        circle = np.ones(img.shape, dtype="uint8")
        circle = circle * 255
        cv2.circle(circle, (c_x, c_y), int(r_1), 0, -1)
        bitwiseOr = cv2.bitwise_or(img, circle)
        cv2.imwrite(self.outputPath+self.imageName + '_1_imgCutCircle.jpg' , bitwiseOr)
        self.cirleData = [r_1, c_x, c_y]
        self.panMask=bitwiseOr
       
        return bitwiseOr

指針式儀表識別讀數(shù) Python(已開源數(shù)據(jù)集)

self.ContoursFilter() 對輪廓進行篩選

    def ContoursFilter(self):
        #對輪廓進行篩選
        """
        :funtion : 提取刻度線,指針
        :param a: 高斯濾波 GaussianBlur,自適應二值化adaptiveThreshold,閉運算
        :param b: 輪廓尋找 findContours,
        :return:lineSet,new_needleset
        """
        r_1, c_x, c_y = self.cirleData

        img = self.image.copy()
        # cv2.circle(img, (c_x, c_y), 20, (23, 28, 28), -1)
        img = cv2.GaussianBlur(img, (3, 3), 0)
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        binary = cv2.adaptiveThreshold(~gray, 255,
                                    cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 15, -10)
        # cv2.circle(binary, (c_x, c_y), int(r_1*0.5), (0, 0, 0),5)
        # 閉運算
        # kernel = np.ones((3, 3), np.uint8)
        #膨脹
        # dilation = cv2.dilate(binary, kernel, iterations=1)
        # kernel2 = np.ones((3, 3), np.uint8)
        #腐蝕
        # erosion = cv2.erode(dilation, kernel2, iterations=1)
        
        #輪廓查找,根據(jù)版本不同,返回參數(shù)不同
        if cv2.__version__ >'4.0.0':
            contours, hier = cv2.findContours(binary, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
        else:
            aa,contours, hier = cv2.findContours(binary, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
        cntset = []  # 刻度線輪廓集合
        cntareas = []  # 刻度線面積集合

        needlecnt = []  # 指針輪廓集合
        needleareas = []  # 指針面積集合
        radiusLength = [r_1 * 0.6, r_1 * 1] # 半徑范圍

      
        # cv2.drawContours(img, contours, -1, (255, 90, 60), 2)
        # cv2.imwrite(self.outputPath+self.imageName + '_2_----numLineMask.jpg' , img)
        localtion = []
        for cnt in contours:
            rect = cv2.minAreaRect(cnt)
            # print(rect)
            #(中心點坐標,(寬度,高度),旋轉(zhuǎn)的角度)=   = rect
            a, (w, h), c = rect  
            w = int(w)
            h = int(h)
            ''' 滿足條件:“長寬比例”,“面積”'''
            if h == 0 or w == 0:
                pass
            else:
                dis = Functions.Disttances((c_x, c_y), a)
                # if (radiusLength[0] < dis and radiusLength[1] > dis):
                if (radiusLength[0] < dis and radiusLength[1] > dis):
                    #矩形篩選
                    if h / w > 4 or w / h > 4:
                        localtion.append(dis)
                        cntset.append(cnt)
                        cntareas.append(w * h)
                else:
                    if w > r_1 / 2 or h > r_1 / 2:
                        needlecnt.append(cnt)
                        needleareas.append(w * h)
        cntareas = np.array(cntareas)
        areasMean = Functions.couputeMean(cntareas)  # 中位數(shù),上限區(qū)
        new_cntset = []
        # 面積
        for i, cnt in enumerate(cntset):
            if (cntareas[i] <= areasMean * 1.5 and cntareas[i] >= areasMean * 0.8):
                new_cntset.append(cnt)

        self.r = np.mean(localtion)
        mask = np.zeros(img.shape[0:2], np.uint8)
        self.poniterMask = cv2.drawContours(mask, needlecnt, -1, (255, 255, 255), -1)  # 生成掩膜
        mask = np.zeros(img.shape[0:2], np.uint8)
        self.numLineMask = cv2.drawContours(mask, new_cntset, -1, (255, 255, 255), -1)  # 生成掩膜

        cv2.imwrite(self.outputPath+self.imageName + '_2_numLineMask.jpg' , self.numLineMask)
        cv2.imwrite(self.outputPath+self.imageName + '_3_poniterMask.jpg' , self.poniterMask)
        # for cnt in needlecnt:
        #     cv2.fillConvexPoly(mask,cnt , 255)
        self.new_cntset=new_cntset
        
        return new_cntset

指針式儀表識別讀數(shù) Python(已開源數(shù)據(jù)集)指針式儀表識別讀數(shù) Python(已開源數(shù)據(jù)集)

self.FitNumLine()輪廓擬合直線

    def FitNumLine(self):
        """ 輪廓擬合直線"""
        lineSet = []  # 擬合線集合
        img=self.image.copy()
        for cnt in self.new_cntset:
            rect = cv2.minAreaRect(cnt)
            # 獲取矩形四個頂點,浮點型
            box = cv2.boxPoints(rect)
            box = np.int0(box)
            cv2.polylines(img, [box], True, (0, 255, 0), 1)  # pic
            output = cv2.fitLine(cnt, 2, 0, 0.001, 0.001)
            k = output[1] / output[0]
            k = round(k[0], 2)
            b = output[3] - k * output[2]
            b = round(b[0], 2)
            x1 = 1
            x2 = img.shape[0]
            y1 = int(k * x1 + b)
            y2 = int(k * x2 + b)
            # cv2.line(img, (x1, y1), (x2, y2), (0, 255, 0), 1)
            #lineSet:刻度線擬合直線數(shù)組,k斜率 b
            lineSet.append([k, b])  # 求中心點的點集[k,b]
        cv2.imwrite(self.outputPath+self.imageName + '_4_fitNumLine.jpg' , img)
        self.lineSet=lineSet
        return lineSet

指針式儀表識別讀數(shù) Python(已開源數(shù)據(jù)集)

self.getIntersectionPoints()獲取刻度線交點

    def getIntersectionPoints(self):
        #獲取刻度線交點
        img = self.image
        lineSet=self.lineSet
        w, h, c = img.shape
        point_list = []
        xlist=[]
        ylist=[]
        if len(lineSet) > 2:
            # print(len(lineSet))
            np.random.shuffle(lineSet)
            lkb = int(len(lineSet) / 2)
            kb1 = lineSet[0:lkb]
            kb2 = lineSet[lkb:(2 * lkb)]
            # print('len', len(kb1), len(kb2))
            kb1sample = random.sample(kb1, int(len(kb1) / 2))
            kb2sample = random.sample(kb2, int(len(kb2) / 2))
        else:
            kb1sample = lineSet[0]
            kb2sample = lineSet[1]
        for i, wx in enumerate(kb1sample):
            # for wy in kb2:
            for wy in kb2sample:
                k1, b1 = wx
                k2, b2 = wy
                # print('kkkbbbb',k1[0],b1[0],k2[0],b2[0])
                # k1-->[123]
                try:
                    if (b2 - b1) == 0:
                        b2 = b2 - 0.1
                    if (k1 - k2) == 0:
                        k1 = k1 - 0.1
                    x = (b2 - b1) / (k1 - k2)
                    y = k1 * x + b1
                    x = int(round(x))
                    y = int(round(y))
                except:
                    x = (b2 - b1 - 0.01) / (k1 - k2 + 0.01)
                    y = k1 * x + b1
                    x = int(round(x))
                    y = int(round(y))
                # x,y=solve_point(k1, b1, k2, b2)
                if x < 0 or y < 0 or x > w or y > h:
                    break
                # point_list.append([x, y])
                xlist.append(x)
                ylist.append(y)
                # cv2.circle(img, (x, y), 2, (122, 22, 0), 2)
        # print('point_list',point_list)
        cx=int(np.mean(xlist))
        cy=int(np.mean(ylist))
        self.centerPoint=[cx,cy]
        cv2.circle(img, (cx, cy), 2, (0, 0, 255), 2)
        cv2.imwrite(self.outputPath+self.imageName + '_5_IntersectionPoints.jpg' , img)
        return img

指針式儀表識別讀數(shù) Python(已開源數(shù)據(jù)集)

self.FitPointerLine()擬合指針直線段

    def FitPointerLine(self):
        #擬合指針直線段
        img =self.poniterMask
        orgin_img=self.image.copy()
        # kernel = np.ones((3, 3), np.uint8)
        # mask = cv2.dilate(img, kernel, iterations=1)
        # img = cv2.erode(mask, kernel, iterations=1)
        lines = cv2.HoughLinesP(img, 1, np.pi / 180, 100, minLineLength=int(self.r / 2), maxLineGap=2)
        # nmask = np.zeros(img.shape, np.uint8)
        # lines = mential.findline(self=0, cp=[x, y], lines=lines)
        # print('lens', len(lines))
        dmax=0
        pointerLine=[]
        #最長的線段為指針
        for line in lines:
            x1, y1, x2, y2 = line[0]
            d1=Functions.Disttances((x1, y1),(x2, y2))
            if(d1>dmax):
                dmax=d1
                pointerLine=line[0]      
        x1, y1, x2, y2 = pointerLine
        d1=Functions.Disttances((x1, y1),(self.centerPoint[0],self.centerPoint[1]))
        d2=Functions.Disttances((x2, y2),(self.centerPoint[0],self.centerPoint[1]))
        if d1 > d2:
            self.farPoint = [x1, y1]
        else:
            self.farPoint = [x2, y2]

        cv2.line(orgin_img, (x1, y1), (x2, y2), 20, 1, cv2.LINE_AA)
        cv2.circle(orgin_img,(self.farPoint[0],self.farPoint[1]), 2, (0, 0, 255),2)
        cv2.imwrite(self.outputPath+self.imageName + '_6_PointerLine.jpg' , img)
        cv2.imwrite(self.outputPath+self.imageName + '_7_PointerPoint.jpg' , orgin_img)

指針式儀表識別讀數(shù) Python(已開源數(shù)據(jù)集)
指針式儀表識別讀數(shù) Python(已開源數(shù)據(jù)集)

讀數(shù)

計算夾角

            v1=[self.zeroPoint[0]-self.centerPoint[0],self.centerPoint[1]-self.zeroPoint[1]]
            v2=[self.farPoint[0]-self.centerPoint[0],self.centerPoint[1]-self.farPoint[1]]
            theta=Functions.GetClockAngle(v1,v2)
            readValue=self.divisionValue*theta

總結(jié)

對程序重新進行封裝,提高了可讀性
程序地址:指針式儀表讀數(shù)源碼github
記得點個star
創(chuàng)作不易,有需要開發(fā)的可以聯(lián)系我,在校研究生文章來源地址http://www.zghlxwxcb.cn/news/detail-417883.html

到了這里,關(guān)于指針式儀表識別讀數(shù) Python(已開源數(shù)據(jù)集)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務器費用

相關(guān)文章

  • 基于深度學習的指針式儀表傾斜校正方法——論文解讀

    基于深度學習的指針式儀表傾斜校正方法——論文解讀

    中文論文題目:基于深度學習的指針式儀表傾斜校正方法 英文論文題目:Tilt Correction Method of Pointer Meter Based on Deep Learning 周登科、楊穎、朱杰、王庫.基于深度學習的指針式儀表傾斜校正方法[J].計算機輔助設計與圖形學學報, 2020, 32(12):9.DOI:10.3724/SP.J.1089.2020.18288. ? ? ? ?針對儀

    2024年02月12日
    瀏覽(26)
  • 一個指針式的時鐘,12小時內(nèi)時針和分針重復多少次,分別是什么時間

    之前看過一個雞湯,說中國學生和國外學生,老師提出這個問題,僅是問重合多少次。中國學生拿出筆悶頭算,國外學生直接拿出表直接調(diào)時間………… 但是這個問題如果是重合的具體時間如何用C語言算 結(jié)果 重復時間 小時: 1 ?分鐘 5? 重復時間 小時: 1 ?分鐘 6? 重復時間

    2024年02月10日
    瀏覽(19)
  • PYTHON+YOLOV5+OPENCV,實現(xiàn)數(shù)字儀表自動讀數(shù),并將讀數(shù)結(jié)果進行輸出顯示和保存

    PYTHON+YOLOV5+OPENCV,實現(xiàn)數(shù)字儀表自動讀數(shù),并將讀數(shù)結(jié)果進行輸出顯示和保存

    最近完成了一個項目,利用python+yolov5實現(xiàn)數(shù)字儀表的自動讀數(shù),并將讀數(shù)結(jié)果進行輸出和保存,現(xiàn)在完成的7788了,寫個文檔記錄一下, 若需要數(shù)據(jù)集和源代碼可以私信。 最后實現(xiàn)的結(jié)果如下: 首先查閱文獻和文檔,好家伙,不看不知道,做相似項目的很多資料都是碩士研

    2024年02月03日
    瀏覽(27)
  • 水表表盤讀數(shù)識別新體驗,帶你進入華為云ModelArts算法套件的世界

    水表表盤讀數(shù)識別新體驗,帶你進入華為云ModelArts算法套件的世界

    數(shù)字時代,數(shù)字化服務已經(jīng)發(fā)展到各行各業(yè),我們的生活中也隨處可見。 數(shù)字化服務的便捷了我們的衣食住行的方方面面,除了我們?nèi)粘;某鲂?、飲食、購物,其實住方面也已有了很深的發(fā)展。 水電燃氣這三項和我們生活息息相關(guān)的能源,也已經(jīng)基本上數(shù)字化、線上化了

    2024年02月21日
    瀏覽(17)
  • Qt(C++)繪制指針儀表盤顯示當前溫度

    Qt(C++)繪制指針儀表盤顯示當前溫度

    當前文章要實現(xiàn)的功能: 使用Qt繪制一個儀表盤,用來顯示當前的溫度,繪制刻度、繪制數(shù)字、繪制溫度指針。儀表盤全程使用QPainter進行繪制,QPainter是Qt框架中非常重要的一個類,繪制功能的實現(xiàn)離不開它。如果想要使用Qt進行高質(zhì)量的繪圖或UI設計,必須掌握QPainter的使用

    2024年02月07日
    瀏覽(20)
  • 巡檢機器人之儀表識別系統(tǒng)

    巡檢機器人之儀表識別系統(tǒng)

    作者主頁:愛笑的男孩。 博客簡介:分享機器學習、深度學習、python相關(guān)內(nèi)容、日常BUG解決方法及WindowsLinux實踐小技巧。 如發(fā)現(xiàn)文章有誤,麻煩請指出,我會及時去糾正。有其他需要可以私信我或者發(fā)我郵箱:zhilong666@foxmail.com 目錄 一、前言 二、項目介紹 三、項目展示 數(shù)字

    2024年02月05日
    瀏覽(13)
  • Selenium 點擊、輸入、截圖、讀數(shù)、切換頁(Chrome109.0.5414.75;python 3.7.9)

    selenium入門超詳細教程——網(wǎng)頁自動化操作 入門指南 | Selenium python命令行運行找不到自定義模塊 excel:讀取賬號密碼(pandas)、記錄讀數(shù)(openpyxl) word:操作word(pipywin32) 網(wǎng)頁操作:seleinium 截圖裁剪:PIL 窗口獲?。骸敬瓿伞?windows 批處理文件bat中當前目錄。 BAT腳本中

    2024年03月25日
    瀏覽(17)
  • 畢設開源 python 機器視覺 車牌識別

    畢設開源 python 機器視覺 車牌識別

    ?? 基于python 機器視覺 的車牌識別系統(tǒng) ??學長這里給一個題目綜合評分(每項滿分5分) 難度系數(shù):3分 工作量:3分 創(chuàng)新點:2分 ?? 選題指導, 項目分享:見文末 車牌識別其實是個經(jīng)典的機器視覺任務了,通過圖像處理技術(shù)檢測、定位、識別車牌上的字符,實現(xiàn)計算機對車牌

    2024年03月13日
    瀏覽(10)
  • 幾種python入門級OCR開源庫中文識別效果對比

    幾種python入門級OCR開源庫中文識別效果對比

    目錄 ? 素材圖片 pytesseract easyocr PaddleOCR 總結(jié) pytesseract是google做的ocr庫,一般用在驗證碼的識別。實測中文的識別速度最快,但是效果也是最差的。 安裝: 下載中文語言包,把語言包放在tessdata目錄: chi_sim.traineddata 編碼: 結(jié)果: 支持CUDA的顯示進行運算,因筆者沒有此類顯

    2024年02月16日
    瀏覽(14)
  • 基于python-opencv,svm的開源人臉識別項目

    基于python-opencv,svm的開源人臉識別項目

    ? 前言 ? ? ? 本項目是我自己在學校里完成的一個小項目,本項目為基于python-opencv,svm的人臉識別開源項目,不同于其他的直接從kaggle等獲取劃分好的數(shù)據(jù)集,本項目致力于從無到有的完成機器學習的所有步驟,即: 目錄 項目展示: 一、數(shù)據(jù)采集 1.創(chuàng)建爬蟲項目 2.修改set

    2024年02月08日
    瀏覽(17)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包