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

opencv+python識(shí)別七段數(shù)碼顯示器的數(shù)字(數(shù)字識(shí)別)

 更新時(shí)間:2022年01月12日 11:14:23   作者:bashendixie5  
本文主要介紹了opencv+python識(shí)別七段數(shù)碼顯示器的數(shù)字(數(shù)字識(shí)別),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

一、什么是七段數(shù)碼顯示器

        七段LCD數(shù)碼顯示器有很多叫法:段碼液晶屏、段式液晶屏、黑白筆段屏、段碼LCD液晶屏、段式顯示器、TN液晶屏、段碼液晶顯示器、段碼屏幕、筆段式液晶屏、段碼液晶顯示屏、段式LCD、筆段式LCD等。

        如下圖,每個(gè)數(shù)字都由一個(gè)七段組件組成。

圖 2:?jiǎn)蝹€(gè)七段顯示器的示例。 每個(gè)段都可以“打開(kāi)”或“關(guān)閉”以表示特定的數(shù)字。

        七段顯示器總共可以呈現(xiàn) 128 種可能的狀態(tài):

        我們要識(shí)別其中的0-9,如果用深度學(xué)習(xí)的方式有點(diǎn)小題大做,并且如果要進(jìn)行應(yīng)用還有很多前序工作需要進(jìn)行,比如要確認(rèn)識(shí)別什么設(shè)備的,怎么找到數(shù)字區(qū)域并進(jìn)行分割等等。

二、創(chuàng)建opencv數(shù)字識(shí)別器

         我們這里進(jìn)行使用空調(diào)恒溫器進(jìn)行識(shí)別,首先整理下流程。

        1、定位恒溫器上的 LCD屏幕。

        2、提取 LCD的圖像。

        3、提取數(shù)字區(qū)域

        4、識(shí)別數(shù)字。

 我們創(chuàng)建名稱(chēng)為recognize_digits.py的文件,代碼如下。僅思路供參考(因?yàn)榇a中的一些參數(shù)只適合測(cè)試圖片)

# import the necessary packages
from imutils.perspective import four_point_transform
from imutils import contours
import imutils
import cv2
# define the dictionary of digit segments so we can identify
# each digit on the thermostat
 
DIGITS_LOOKUP = {
	(1, 1, 1, 0, 1, 1, 1): 0,
	(0, 0, 1, 0, 0, 1, 0): 1,
	(1, 0, 1, 1, 1, 1, 0): 2,
	(1, 0, 1, 1, 0, 1, 1): 3,
	(0, 1, 1, 1, 0, 1, 0): 4,
	(1, 1, 0, 1, 0, 1, 1): 5,
	(1, 1, 0, 1, 1, 1, 1): 6,
	(1, 0, 1, 0, 0, 1, 0): 7,
	(1, 1, 1, 1, 1, 1, 1): 8,
	(1, 1, 1, 1, 0, 1, 1): 9
}
 
# load the example image
image = cv2.imread("example.jpg")#
# pre-process the image by resizing it, converting it to
# graycale, blurring it, and computing an edge map
image = imutils.resize(image, height=500)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
edged = cv2.Canny(blurred, 50, 200, 255)
 
# find contours in the edge map, then sort them by their
# size in descending order
cnts = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
cnts = sorted(cnts, key=cv2.contourArea, reverse=True)
displayCnt = None
# loop over the contours
for c in cnts:
	# approximate the contour
	peri = cv2.arcLength(c, True)
	approx = cv2.approxPolyDP(c, 0.02 * peri, True)
	# if the contour has four vertices, then we have found
	# the thermostat display
	if len(approx) == 4:
		displayCnt = approx
		break
 
# extract the thermostat display, apply a perspective transform
# to it
warped = four_point_transform(gray, displayCnt.reshape(4, 2))
output = four_point_transform(image, displayCnt.reshape(4, 2))
 
# threshold the warped image, then apply a series of morphological
# operations to cleanup the thresholded image
thresh = cv2.threshold(warped, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (1, 5))
thresh = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel)
 
# find contours in the thresholded image, then initialize the
# digit contours lists
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
digitCnts = []
# loop over the digit area candidates
for c in cnts:
	# compute the bounding box of the contour
	(x, y, w, h) = cv2.boundingRect(c)
	# if the contour is sufficiently large, it must be a digit
	if w >= 15 and (h >= 30 and h <= 40):
		digitCnts.append(c)
 
# sort the contours from left-to-right, then initialize the
# actual digits themselves
digitCnts = contours.sort_contours(digitCnts, method="left-to-right")[0]
digits = []
 
# loop over each of the digits
for c in digitCnts:
	# extract the digit ROI
	(x, y, w, h) = cv2.boundingRect(c)
	roi = thresh[y:y + h, x:x + w]
	# compute the width and height of each of the 7 segments
	# we are going to examine
	(roiH, roiW) = roi.shape
	(dW, dH) = (int(roiW * 0.25), int(roiH * 0.15))
	dHC = int(roiH * 0.05)
	# define the set of 7 segments
	segments = [
		((0, 0), (w, dH)),	# top
		((0, 0), (dW, h // 2)),	# top-left
		((w - dW, 0), (w, h // 2)),	# top-right
		((0, (h // 2) - dHC) , (w, (h // 2) + dHC)), # center
		((0, h // 2), (dW, h)),	# bottom-left
		((w - dW, h // 2), (w, h)),	# bottom-right
		((0, h - dH), (w, h))	# bottom
	]
	on = [0] * len(segments)
 
	# loop over the segments
	for (i, ((xA, yA), (xB, yB))) in enumerate(segments):
		# extract the segment ROI, count the total number of
		# thresholded pixels in the segment, and then compute
		# the area of the segment
		segROI = roi[yA:yB, xA:xB]
		total = cv2.countNonZero(segROI)
		area = (xB - xA) * (yB - yA)
		# if the total number of non-zero pixels is greater than
		# 50% of the area, mark the segment as "on"
		if total / float(area) > 0.5:
			on[i]= 1
	# lookup the digit and draw it on the image
	digit = DIGITS_LOOKUP[tuple(on)]
	digits.append(digit)
	cv2.rectangle(output, (x, y), (x + w, y + h), (0, 255, 0), 1)
	cv2.putText(output, str(digit), (x - 10, y - 10),
		cv2.FONT_HERSHEY_SIMPLEX, 0.65, (0, 255, 0), 2)
 
# display the digits
print(u"{}{}.{} \u00b0C".format(*digits))
cv2.imshow("Input", image)
cv2.imshow("Output", output)
cv2.waitKey(0)

原始圖片

邊緣檢測(cè)

識(shí)別的結(jié)果圖片

到此這篇關(guān)于opencv+python識(shí)別七段數(shù)碼顯示器的數(shù)字(數(shù)字識(shí)別)的文章就介紹到這了,更多相關(guān)opencv數(shù)字識(shí)別內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 詳解python使用遞歸、尾遞歸、循環(huán)三種方式實(shí)現(xiàn)斐波那契數(shù)列

    詳解python使用遞歸、尾遞歸、循環(huán)三種方式實(shí)現(xiàn)斐波那契數(shù)列

    本篇文章主要介紹了python使用遞歸、尾遞歸、循環(huán)三種方式實(shí)現(xiàn)斐波那契數(shù)列,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2018-01-01
  • python 將字符串中的數(shù)字相加求和的實(shí)現(xiàn)

    python 將字符串中的數(shù)字相加求和的實(shí)現(xiàn)

    這篇文章主要介紹了python 將字符串中的數(shù)字相加求和的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • python連接讀寫(xiě)操作redis的完整代碼實(shí)例

    python連接讀寫(xiě)操作redis的完整代碼實(shí)例

    這篇文章主要介紹了python連接讀寫(xiě)操作redis的完整代碼實(shí)例,包括redis連接與讀寫(xiě)操作,redis-sentinel哨兵模式下Python操作redis,redis-cluster(集群)模式下Python操作redis,需要的朋友可以參考下
    2023-01-01
  • python 獲取文件列表(或是目錄例表)

    python 獲取文件列表(或是目錄例表)

    在python的應(yīng)用過(guò)程中,經(jīng)常會(huì)用到獲取文件列表的方法,常規(guī)的做法是這樣的
    2009-03-03
  • python dotenv管理多環(huán)境配置的方法

    python dotenv管理多環(huán)境配置的方法

    python-dotenv 是一個(gè)很好的工具,能幫助你管理項(xiàng)目中的配置和環(huán)境變量,特別是在涉及敏感數(shù)據(jù)時(shí),這篇文章主要介紹了python dotenv管理多環(huán)境配置,需要的朋友可以參考下
    2024-12-12
  • Python利用matplotlib繪制折線(xiàn)圖的新手教程

    Python利用matplotlib繪制折線(xiàn)圖的新手教程

    這篇文章主要給大家介紹了關(guān)于Python利用matplotlib繪制折線(xiàn)圖的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • TensorFlow實(shí)現(xiàn)MLP多層感知機(jī)模型

    TensorFlow實(shí)現(xiàn)MLP多層感知機(jī)模型

    這篇文章主要為大家詳細(xì)介紹了TensorFlow實(shí)現(xiàn)MLP多層感知機(jī)模型,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • python使用Pillow將照片轉(zhuǎn)換為1寸報(bào)名照片的教程分享

    python使用Pillow將照片轉(zhuǎn)換為1寸報(bào)名照片的教程分享

    在現(xiàn)代科技時(shí)代,我們經(jīng)常需要調(diào)整和處理照片以適應(yīng)特定的需求和用途,本文將介紹如何使用wxPython和Pillow庫(kù),通過(guò)一個(gè)簡(jiǎn)單的圖形界面程序,將選擇的照片轉(zhuǎn)換為指定尺寸的JPG格式,并保存在桌面上,需要的朋友可以參考下
    2023-09-09
  • Python字符串通過(guò)''+''和join函數(shù)拼接新字符串的性能測(cè)試比較

    Python字符串通過(guò)''+''和join函數(shù)拼接新字符串的性能測(cè)試比較

    今天小編就為大家分享一篇關(guān)于Python字符串通過(guò)'+'和join函數(shù)拼接新字符串的性能測(cè)試比較,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧
    2019-03-03
  • Pycharm創(chuàng)建文件時(shí)自動(dòng)生成文件頭注釋(自定義設(shè)置作者日期)

    Pycharm創(chuàng)建文件時(shí)自動(dòng)生成文件頭注釋(自定義設(shè)置作者日期)

    這篇文章主要介紹了Pycharm創(chuàng)建文件時(shí)自動(dòng)生成文件頭注釋(自定義設(shè)置作者日期),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11

最新評(píng)論

邵东县| 铜山县| 合肥市| 和静县| 凤城市| 祁门县| 惠安县| 潜山县| 宁德市| 尚志市| 乌兰浩特市| 库车县| 琼结县| 黎平县| 双牌县| 林州市| 邳州市| 阳高县| 林西县| 和平区| 榆林市| 织金县| 保康县| 寻乌县| 景谷| 尖扎县| 深圳市| 安图县| 马关县| 眉山市| 建昌县| 钟山县| 建平县| 阳西县| 新疆| 临沂市| 满城县| 榆中县| 梨树县| 松滋市| 历史|