日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

opencv 仪表数字切割

發(fā)布時(shí)間:2025/4/5 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 opencv 仪表数字切割 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Thu Mar 21 12:42:15 2019@author: lg """import cv2 import numpy as np# 形態(tài)學(xué)處理 def Process(img):# 高斯平滑gaussian = cv2.GaussianBlur(img, (3, 3), 0, 0, cv2.BORDER_DEFAULT)# 中值濾波median = cv2.medianBlur(gaussian, 5)# Sobel算子# 梯度方向: xsobel = cv2.Sobel(median, cv2.CV_8U, 1, 0, ksize=3)# 二值化ret, binary = cv2.threshold(sobel, 170, 255, cv2.THRESH_BINARY)# 核函數(shù)element1 = cv2.getStructuringElement(cv2.MORPH_RECT, (9, 1))element2 = cv2.getStructuringElement(cv2.MORPH_RECT, (9, 7))# 膨脹dilation = cv2.dilate(binary, element2, iterations=1)# 腐蝕erosion = cv2.erode(dilation, element1, iterations=1)# 膨脹dilation2 = cv2.dilate(erosion, element2, iterations=3)return dilation2def GetRegion(img):regions = []# 查找輪廓contours, hierarchy = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)for contour in contours:area = cv2.contourArea(contour)if (area < 5000):continueeps = 1e-3 * cv2.arcLength(contour, True)approx = cv2.approxPolyDP(contour, eps, True)rect = cv2.minAreaRect(contour)box = cv2.boxPoints(rect)box = np.int0(box)height = abs(box[0][1] - box[2][1])width = abs(box[0][0] - box[2][0])ratio =float(width) / float(height)if (ratio < 5 and ratio > 1.8):regions.append(box)return regionsdef detect(img):gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)prc = Process(gray)regions = GetRegion(prc)return regions#輸入的參數(shù)為圖片的路徑 img = cv2.imread('red.jpg') b=detect(img) b1=b[0]hm=b1[:,1].max() hn=b1[:,1].min()cm=b1[:,0].max() cn=b1[:,0].min()# -*- coding=GBK -*- import cv2 as cv import numpy as np#截取圖片中的指定區(qū)域或在指定區(qū)域添加某一圖片 def jie_image(src1):src2 = src1[hn:hm,cn:cm]#截取第5行到89行的第500列到630列的區(qū)域cv.imshow("截取", src2)cv2.imwrite('jiequ.jpg', src2) # src1[105:189, 300:430] = src2#指定位置填充,大小要一樣才能填充 # cv.imshow("合成", src1)src = cv.imread("cc.jpeg") #cv.imshow("原來", src) jie_image(src) cv.waitKey(0) cv.destroyAllWindows()


總結(jié)

以上是生活随笔為你收集整理的opencv 仪表数字切割的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。