element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
STEM Projects
  • Learn
  • Learning Center
  • STEM Academy
  • STEM Projects
  • More
  • Cancel
STEM Projects
Blog Exercise sheet sorter machine. Part5. Document detection.
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join STEM Projects to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Anonymous-237891
  • Date Created: 8 Aug 2015 8:19 PM Date Created
  • Views 494 views
  • Likes 2 likes
  • Comments 2 comments
  • raspberry
  • computervision
  • teachers_pet
  • opencv
  • raspberrypi
  • teachers pet robotics design challenge
  • camera
  • exercise_sheet_sorter
Related
Recommended

Exercise sheet sorter machine. Part5. Document detection.

Anonymous-237891
Anonymous-237891
8 Aug 2015

Hi,

It is me again.

Today, was the first time I lost so much time doing such a sraight forward thing.

I just needed to record this f****g screen on video, and the raspberry spent literally 1h14 to encode a video that finally turned out to be completely screwed up on the color, it was all red(ish) what a lost of time.

image

I used the package called recordmydesktop, it has good reviews but didn't quite work out for me.

 

Anyway on the good things now.

I changed my mind on the sheet detection system... I decided not to detect the color of a blob on the sheet but the number of dots present on it.

For the dot color, I asked myself: What do I cary all day long with me at school ?

And my mind settled on this kind of hi-lighter,

Stabilo boss orange

 

Then I wrote a piece of code, with bits from the last blog post and some found online and some from my own making (yeah I do write some lines now and then image ).

And so far I have got this:

 

# import the necessary packages
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
import numpy as np


# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(640, 480))


# allow the camera to warmup
time.sleep(0.1)


# capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):


    # grab the raw NumPy array representing the image, then initialize the timestamp
    # and occupied/unoccupied text
    image = frame.array


    # smooth it
    image = cv2.blur(image, (3, 3))


    # convert to hsv and find range of colors
    hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
    thresh = cv2.inRange(hsv, np.array((0, 80, 80)), np.array((20, 255, 255)))
    thresh2 = thresh.copy()


    # find contours in the threshold image
    contours, hierarchy = cv2.findContours(thresh, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)


    # finding contour with maximum area and store it as best_cnt
    max_area = 1000
    best_cnt = 0
    found_item = 0


    for cnt in contours:
        area = cv2.contourArea(cnt)


        if area > max_area:
            found_item += 1
            # finding centroids of best_cnt and draw a circle there
            M = cv2.moments(cnt)
            cx,cy = int(M['m10']/M['m00']), int(M['m01']/M['m00'])
            cv2.circle(image,(cx,cy),5,255,-1)


    if found_item == 1 :
        cv2.putText(image,"docum_type_1", (20,25), cv2.FONT_HERSHEY_SIMPLEX, 1, 255, 2)


    elif found_item == 2 :
        cv2.putText(image,"docum_type_2", (20,25), cv2.FONT_HERSHEY_SIMPLEX, 1, 255, 2)


    elif found_item == 3 :
        cv2.putText(image,"docum_type_3", (20,25), cv2.FONT_HERSHEY_SIMPLEX, 1, 255, 2)


    else :
        cv2.putText(image,"type_not_found", (20,20), cv2.FONT_HERSHEY_SIMPLEX, 1, 255, 2)


    # Show it, if key pressed is 'Esc', exit the loop
    cv2.imshow('frame', image)
    cv2.imshow('thresh', thresh2)


    key = cv2.waitKey(1) & 0xFF


    # clear the stream in preparation for the next frame
    rawCapture.truncate(0)


    # if the `q` key was pressed, break from the loop
    if key == ord("q"):
        break

 

For the demo I had to get a vnc server running in order to record a screen capture stream from my laptop, which does it flawlessly (and the encoding took 24 sec, this raspberry is really limited on video encoding power.

 

But anyway here is the video of the document detection in action.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Sorry for the quality, I had to compress it quite a bit since my bandwidth at home is not that great image

 

Overall I am pretty thrilled with how this thing turned out so far... I will now try to integrate some sort of switch to stop the feed system when a paper sheet get below the camera to analyse it when it is still and the restart the feed system to get the following sheet.... and so on

 

Then the only thing left is to mount the servo motor and the mechanical assembly that will guide the sheets into their belonging receptacle.

 

I hope, that you learn something or at least enjoyed reading/watching through my post.

And I would love to see you on the next one.

Bye.

  • Sign in to reply

Top Comments

  • Anonymous-237891
    Anonymous-237891 over 10 years ago in reply to madhugovindarajan +1
    Yeah this is a nice video. I know a little bit about Matlab but I am no expert. I tend to prefer going for Python or C/C++ instead whenever possible.
  • Anonymous-237891
    Anonymous-237891 over 10 years ago in reply to madhugovindarajan

    Yeah this is a nice video. I know a little bit about Matlab but I am no expert. I tend to prefer going for Python or C/C++ instead whenever possible. image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • madhugovindarajan
    madhugovindarajan over 10 years ago

    After reading your blog, the first thing that came to my mind was this video - https://www.youtube.com/watch?v=oqjitgPM2f0

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube