Git Product home page Git Product logo

seven-segment-ocr's Introduction

seven-segment-ocr

A program and set of Python modules to parse digits from videos of seven segment displays. This program does not operate on a trained model--rather, it takes a universal approach by taking three line profiles to efficiently and effectively determine which digit is shown.

๐Ÿ‘€ I'm actively revisiting this library after many years (when the core of this was written) to improve code quality, testing, features, architecture, and more as this starts to get organic traction.

Usage

Simply supply a path to a video of a seven segment display and an interval to sample the digits at and an output file will be generated (by default out.csv) with the recognized digits at each sample interval. Before proceeding, the program first presents the first frame of the video and you must click and drag rectangular selections around the digits in the video and then press "d" when done or "r" to redraw rectangles. The program will then go though and recognize and parse the digits at each interval.

python seven_segment_ocr.py --video VIDEO_PATH --output OUTPUT_DATA_FILE --period SAMPLE_PERIOD

This will bring up the first frame of the video where you can draw rectangles around the digits you want to parse throughout the video. When you're done selecting as many digits as you'd like, press "d" and then enter. To redraw rectangles press "r" instead of "d".

Modules

  • image_selection.py: Functions to present the user an image and returns retangular ROIs the user selects (specifically getSelectionsFromImage(img))
  • digit_reader.py: Functions to parse all the seven segment display digits (specified by retangular ROIs) and return the recognized igits (see read_digits(image, roiPoints)).
  • seven_segment_ocr.py: The main entry point for the program is here. Given a video path and a sample interval (in seconds), it gets ROIs from the user and parses digits out of the video at every sample interval.

seven-segment-ocr's People

Contributors

alessandro-gentilini avatar suyashkumar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

seven-segment-ocr's Issues

TypeError: 'float' object cannot be interpreted as an integer

@alessandro-gentilini @suyashkumar I tried to test on your video by running the following line on Command Prompt

python seven_segment_ocr.py --video C:/Users/files/sample_files/test.mov --output C:/Users/files/out.csv --period 1

Unfortunately I received the following error when drag rectangular selections around the digits in the video and then pressed "d"

[(366, 231), (448, 349), (470, 231), (556, 353), (464, 363), (561, 485)]
Traceback (most recent call last):
File "C:\Users\files\seven_segment_ocr.py", line 58, in
digitsReadArray = read_video_digits(args.video, args.period)
File "C:\Users\files\seven_segment_ocr.py", line 20, in read_video_digits
selections=image_selection.getSelectionsFromImage(image)
File "C:\Users\files\image_selection.py", line 56, in getSelectionsFromImage
for selection in range(0, len(refPts)/2):
TypeError: 'float' object cannot be interpreted as an integer

Do you have some ideas how to fix this issue in the code? Thanks in advance!

'NoneType' object has no attribute 'copy'

Hi, would you be able to help with the error below?

Traceback (most recent call last):
  File "seven_segment_ocr.py", line 59, in <module>
    digitsReadArray = read_video_digits(args.video, args.period)
  File "seven_segment_ocr.py", line 20, in read_video_digits
    selections=image_selection.getSelectionsFromImage(image)
  File "C:\obtv\seven-segment-ocr\image_selection.py", line 40, in getSelectionsFromImage
    clone = image.copy()
AttributeError: 'NoneType' object has no attribute 'copy'

Digit Not Recognized

I am having trouble getting any digits recognized even with the sample file you provided. It seems extremely sensitive to how you position the box around the digit. Is there a way to debug this further or better understand how the segments are being read?

FYI I made a few modifications to the file to work with the newest version of OpenCV (3.3.1):

22,24c22,24
-     fps = video.get(cv2.cv.CV_CAP_PROP_FPS) # Get FPS
-     frameInterval = int(round(fps * samplePeriod))
-     totalFrames = video.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT)
+     fps = video.get(cv2.CAP_PROP_FPS) # Get FPS
+     frameInterval = int(round(float(fps) * float(samplePeriod)))
+     totalFrames = video.get(cv2.CAP_PROP_FRAME_COUNT)
29c29
-         video.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, frameNumber*frameInterval) #Set frame to read next
+         video.set(cv2.CAP_PROP_POS_FRAMES, frameNumber*frameInterval) # Set frame to read next```

Add requirements.txt

Revisiting this old library, realized it needs a requirements.txt and potentially a docker build.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.