技术控

    今日:0| 主题:49390
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] Automatically grading multiple choice exams from photos using Python and OpenCV

[复制链接]
你穿过的墙 发表于 2016-10-3 22:00:03
207 2

立即注册CoLaBug.com会员,免费获得投稿人的专业资料,享用更多功能,玩转个人品牌!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

Automatically grading multiple choice exams from photos using Python and OpenCV-1 (techniques,afternoon,including,knowledge,multiple)
  
  Over the past few months I’ve gotten quite the number of requests landing in my inbox to build a bubble sheet/Scantron-like test reader using computer vision and image processing techniques.
  And while I’ve been having a lot of fun doing this series on machine learning and deep learning, I’d be    lyingif I said this little mini-project wasn’t a short, welcome break. One of my favorite parts of running the PyImageSearch blog is demonstrating how to build     actualsolutions to problems using computer vision.  
  In fact, what makes this project    so specialis that we are going to combine the techniques from     manyprevious blog posts, including    building a document scanner,contour sorting, and    perspective transforms. Using the knowledge gained from these previous posts, we’ll be able to make quick work of this bubble sheet scanner and test grader.  
  You see, last Friday afternoon I quickly Photoshopped an example bubble test paper, printed out a few copies,    and then set to work on coding up the actual implementation.  
  Overall, I am quite pleased with this implementation and I think you’ll absolutely be able to use this bubble sheet grader/OMR system as a starting point for your own projects.
  To learn more about utilizing computer vision, image processing, and OpenCV to automatically grade bubble test sheets,     keep reading.  
      Looking for the source code to this post?
Jump right to the downloads section.    Bubble sheet scanner and test grader using OMR, Python, and OpenCV

  In the remainder of this blog post, I’ll discuss what exactly    Optical Mark Recognition(OMR) is. I’ll then demonstrate how to implement a bubble sheet test scanner and grader using     strictlycomputer vision and image processing techniques, along with the OpenCV library.  
  Once we have our OMR system implemented, I’ll provide sample results of our test grader on a few example exams, including ones that were filled out with nefarious intent.
  Finally, I’ll discuss some of the shortcomings of this current bubble sheet scanner system and how we can improve it in future iterations.
  What is Optical Mark Recognition (OMR)?

  Optical Mark Recognition, or OMR for short, is the process of    automaticallyanalyzing human-marked documents and interpreting their results.  
  Arguably, the most famous, easily recognizable form of OMR are          bubble sheet multiple choice tests    , not unlike the ones you took in elementary school, middle school, or even high school.  
  If you’re unfamiliar with “bubble sheet tests” or the trademark/corporate name of “Scantron tests”, they are simply multiple-choice tests that you take as a student. Each question on the exam is a multiple choice — and you use a #2 pencil to mark the “bubble” that corresponds to the correct answer.
  The most notable bubble sheet test you experienced (at least in the United States) were taking the SATs during high school, prior to filling out college admission applications.
  I    believethat the SATs use the software provided by Scantron to perform OMR and grade student exams, but I could easily be wrong there. I only make note of this because Scantron is used in over 98% of all US school districts.  
  In short, what I’m trying to say is that there is a    massive marketfor Optical Mark Recognition and the ability to grade and interpret human-marked forms and exams.  
  Implementing a bubble sheet scanner and grader using OMR, Python, and OpenCV

  Now that we understand the basics of OMR, let’s build a computer vision system using Python and OpenCV that can    readand     gradebubble sheet tests.  
  Of course, I’ll be providing lots of visual example images along the way so you can understand    exactly what techniques I’m applyingand     why I’m using them.  
  Below I have included an example filled in bubble sheet exam that I have put together for this project:

Automatically grading multiple choice exams from photos using Python and OpenCV-2 (techniques,afternoon,including,knowledge,multiple)
    Figure 1:The example, filled in bubble sheet we are going to use when developing our test scanner software.   
    We’ll be using this as our example image as we work through the steps of building our test grader. Later in this lesson, you’ll also find additional sample exams.
  I have also included a    blank exam templateas a .PSD (Photoshop) file so you can modify it as you see fit. You can use the           “Downloads”    section at the bottom of this post to download the code, example images, and template file.  
  The 7 steps to build a bubble sheet scanner and grader

  The goal of this blog post is to build a bubble sheet scanner and test grader using Python and OpenCV.
  To accomplish this, our implementation will need to satisfy the following 7 steps:
  
       
  •       Step #1:Detect the exam in an image.   
  •       Step #2:Apply a perspective transform to extract the top-down, birds-eye-view of the exam.   
  •       Step #3:Extract the set of bubbles (i.e., the possible answer choices) from the perspective transformed exam.   
  •       Step #4:Sort the questions/bubbles into rows.   
  •       Step #5:Determine the marked (i.e., “bubbled in”) answer for each row.   
  •       Step #6:Lookup the correct answer in our answer key to determine if the user was correct in their choice.   
  •       Step #7:Repeat for all questions in the exam.  
  The next section of this tutorial will cover the actual    implementationof our algorithm.  
  The bubble sheet scanner implementation with Python and OpenCV

  To get started, open up a new file, name it                  test_grader        .        py          , and let’s get to work:  
  [code]# import the necessary packages
from imutils.perspectiveimport four_point_transform
from imutilsimport contours
import numpyas np
import argparse
import imutils
import cv2
 
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path to the input image")
args = vars(ap.parse_args())
 
# define the answer key which maps the question number
# to the correct answer
ANSWER_KEY = {0: 1, 1: 4, 2: 0, 3: 3, 4: 1}
[/code]  On    Lines 2-7we import our required Python packages.  
  You should already have OpenCV and Numpy installed on your system, but you    mightnot have the most recent version of    imutils, my set of convenience functions to make performing basic image processing operations easier. To install                  imutils          (or upgrade to the latest version), just execute the following command:  
  [code]$ pipinstall --upgradeimutils
[/code]  Lines 10-12parse our command line arguments. We only need a single switch here,                  --        image          , which is the path to the input bubble sheet test image that we are going to grade for correctness.  
  Line 17then defines our                  ANSWER_KEY          .  
  As the name of the variable suggests, the                  ANSWER_KEY          provides integer mappings of the     question numbersto the     index of the correct bubble.  
  In this case, a key of    0indicates the     first question, while a value of     1signifies     “B”as the correct answer (since     “B”is the index     1in the string     “ABCDE”). As a second example, consider a key of     1that maps to a value of     4— this would indicate that the answer to the second question is     “E”.  
  As a matter of convenience, I have written the entire answer key in plain english here:
  
       
  •       Question #1:B   
  •       Question #2: E   
  •       Question #3: A   
  •       Question #4: D   
  •       Question #5: B  
  Next, let’s preprocess our input image:
  [code]# load the image, convert it to grayscale, blur it
# slightly, then find edges
image = cv2.imread(args["image"])
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
edged = cv2.Canny(blurred, 75, 200)
[/code]  On    Line 21 we load our image from disk, followed by converting it to grayscale (    Line 22), and blurring it to reduce high frequency noise (    Line 23).  
  We then apply the Canny edge detector on    Line 24to find the     edges/outlinesof the exam.  
  Below I have included a screenshot of our exam after applying edge detection:
更多图片 小图 大图
组图打开中,请稍候......
友荐云推荐




上一篇:watchOS by Tutorials Updated for Swift 3 and watchOS 3
下一篇:Animate Your React Native App
酷辣虫提示酷辣虫禁止发表任何与中华人民共和国法律有抵触的内容!所有内容由用户发布,并不代表酷辣虫的观点,酷辣虫无法对用户发布内容真实性提供任何的保证,请自行验证并承担风险与后果。如您有版权、违规等问题,请通过"联系我们"或"违规举报"告知我们处理。

weeks_less 发表于 2016-10-4 02:35:30
我小学十年,中学十二年,我被评为全校最熟悉的面孔,新老师来了都跟我打听学校内幕……
回复 支持 反对

使用道具 举报

心想事成1 发表于 2016-10-5 18:52:04
你穿过的墙很是无聊啊
回复 支持 反对

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

我要投稿

推荐阅读

扫码访问 @iTTTTT瑞翔 的微博
回页顶回复上一篇下一篇回列表手机版
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 )|网站地图 酷辣虫

© 2001-2016 Comsenz Inc. Design: Dean. DiscuzFans.

返回顶部 返回列表