In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the relevant knowledge of "how to create an opencv digital recognizer". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to create an opencv digital recognizer" can help you solve the problem.
What is a seven-segment digital display
Seven-segment LCD digital display has many names: segment LCD screen, segment LCD screen, black-and-white pen segment screen, segment code LCD LCD screen, segment display, TN LCD screen, segment code LCD display, segment code screen, pen type LCD screen, segment code LCD screen, segment LCD, pen segment LCD and so on.
As shown in the following figure, each number consists of a seven-segment component.
A total of 128 possible states can be displayed on a seven-segment display:
We have to identify the 0-9, if we make a mountain out of a molehill with deep learning, and if we want to apply, there is still a lot of pre-order work to be done, such as identifying what devices are identified, how to find and segment the digital area, and so on.
Second, create an opencv digital recognizer
We use air-conditioning thermostat to identify here, first sort out the process.
1. Locate the LCD screen on the thermostat.
2. Extract the image of LCD.
3. Extract the digital region
4. Identify the number.
We create a file named recognize_digits.py with the following code. Ideas are for reference only (because some parameters in the code are only suitable for testing pictures)
# import the necessary packagesfrom imutils.perspective import four_point_transformfrom imutilsimport contoursimport imutilsimport 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,0): 2, (1,0,1,1,1,1): 3 (0, 1, 1, 1, 0, 1, 0): 4, (1, 1, 0, 1, 0, 1, 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, 1): 8, (1, 1, 1, 1, 0, 1) 1): 9} # load the example imageimage = cv2.imread ("example.jpg") # # pre-process the image by resizing it, converting it to# graycale, blurring it, and computing an edge mapimage = 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 ordercnts = 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 contoursfor 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 itwarped = 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 imagethresh = 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 listscnts = cv2.findContours (thresh.copy (), cv2.RETR_EXTERNAL Cv2.CHAIN_APPROX_SIMPLE) cnts = imutils.grab_contours (cnts) digitCnts = [] # loop over the digit area candidatesfor 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 0.5: on [I] = 1 # lookup the digit and draw it on the image digit = DIGITS_ lockup [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 digitsprint (u "{} {}. {}\ u00b0C" .format (* digits)) cv2.imshow ("Input", image) cv2.imshow ("Output", output) cv2.waitKey (0) about "how to create an opencv digital recognizer". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.