In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to use OpenCV-Python to achieve identification answer card marking function", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use OpenCV-Python to achieve identification answer card marking function" this article.
Task
Identify the answer card taken with the camera and judge the final score (assuming the correct answer is B, E, A, D, B)
Main steps
Outline recognition-- Edge recognition of answer Card
Perspective transformation-- extracting the main body of the answer card
Outline recognition-identify all circle options and eliminate extraneous contours
Check which item is selected for each line, store the results, and record the correct number
Calculate the final score and mark it in the diagram
Step by step implementation
Outline recognition-- Edge recognition of answer Card
Input image
Import cv2 as cvimport numpy as np # correct answer right_key = {0: 1, 1: 4, 2: 0, 3: 3, 4: 1} # input image img = cv.imread ('. / images/test_01.jpg') img_copy = img.copy () img_gray = cv.cvtColor (img, cv.COLOR_BGR2GRAY) cvshow ('img-gray', img_gray)
Image preprocessing # Image preprocessing # Gaussian noise reduction img_gaussian = cv.GaussianBlur (img_gray, (5,5), 1) cvshow ('gaussianblur', img_gaussian) # canny Edge Detection img_canny = cv.Canny (img_gaussian, 80150) cvshow (' canny', img_canny)
Outline recognition-- Edge recognition of answer Card
# Contour recognition-answer card edge recognition cnts, hierarchy = cv.findContours (img_canny, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE) cv.drawContours (img_copy, cnts,-1, (0,0,255), 3) cvshow ('contours-show', img_copy)
Perspective transformation-- extracting the main body of the answer card
Fit each profile to change the polygon outline into a quadrilateral
DocCnt = None # ensure that if len (cnts) > 0: # sort by contour size cnts = sorted (cnts, key=cv.contourArea, reverse=True) # traverse each profile for c in cnts: # approximate peri = cv.arcLength (c, True) # arclength calculates the length of a curve or the perimeter of a closed curve # the first parameter inputs a two-dimensional vector, and the second parameter calculates whether the curve is closed approx = cv.approxPolyDP (c, 0.02 * peri, True) # approximate the curve / polygon with a curve / polygon with fewer vertices So that the distance between them = 20 and h > = 20 and ar > = 0.9 and ar 0: # sort by contour size cnts = sorted (cnts, key=cv.contourArea, reverse=True) # traverse each profile for c in cnts: # approximate peri = cv.arcLength (c, True) # arclength calculates the length of a curve or the perimeter of a closed curve # the first parameter inputs a two-dimensional vector, and the second parameter calculates whether the curve is closed approx = cv.approxPolyDP (c, 0.02 * peri, True) # approximate the curve / polygon with a curve / polygon with fewer vertices so that the distance between them = 20 and h > = 20 and ar > = 0.9 and ar
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.