Polytechnic University of Bucharest [622685]

Polytechnic University of Bucharest

Faculty of Electronics, Telecommunications and Information Technology

Automatic scanning and processing of ballot

papers

Diploma Project

Presented as a partial requirement for obtaining the title of Engineer

in Electronics and Telecommunications domain, for the study

program: Applied Electronics

Scientific Coordinators:

Student: [anonimizat]. Horia CUCU
Vlad UBLEA

Bucharest

2020

Lista figuri, tabele si acronime

CAPITOLUL 1

INTRODUCERE

1.1 Motivation

Most elections, whether the ones inside educational institutions (for example in faculties, voting

for students’ councils or professors’ departments leaders) or countries affairs (more specifically,

in politics, for choosing candidat: [anonimizat], are paper based and

can take a long time to scan using people, and there is potential for errors when introducing the

results on a computer using a keyboard (accidental keypresses). Generally the elections are

counted at night when the voting ends (from 9PM to 3AM for example). This project aims to

reduce the time and errors of such verification. Paper voting is still popular compared to

electronic voting since it is more secure, since it offers physical proof of the vote and it can be

checked afterwards. Also, there are no hacking problems to consider compared to electronic

voting.

1.2 Objectives

For this project the following objectives have been proposed:

1.
Create a template for the ballot paper in Excel, a graphical common

program used and known by many users for simplicity.

2.
Create software for processing the data in the Excel file and the data

coming from a PNG file exported from the Excel file, representing the

scanned paper.

3.
Create a mounting device that holds the papers and webcam fixed.

4.
Modify the software to work for real world images

Capitolul 2:

Electronic hardware

Camera and image ( Lika Arlind):

https://en.wikipedia.org/wiki/Camera

https://en.wikipedia.org/wiki/Digital_camera#Image_sensors

https://en.wikipedia.org/wiki/Webcam

https://en.wikipedia.org/wiki/USB

Raspberry Pi

( a01041
2B rev1.1,1GB RAM) (Namelic: Andrei Gaita)

(

https://en.wikipedia.org/wiki/Raspberry_Pi

)

The Raspberry Pi is a single board computer (SBC) with small dimensions,

approximately the same as a credit card, at an accessible price for the

general public. Since it is a computer, it can be connected to a monitor or a

television and can be controlled using a keyboard and mouse. Unlike

microcontrollers (like the Arduino for example), the Raspberry Pi has a

dedicated Linux based desktop operating system called Raspbian, based on

Debian, and doesn’t require an external computer to program it (unlike the

Arduino which requires programming on a separate PC using the Arduino

IDE). This SBC allows people with any level of programming background to

explore the world of programming and information processing using different

programming languages like Scratch or Python. The Raspberry Pi has

performance similar to an entry level desktop, meaning it can perform basic

tasks like Internet browsing, playing video games, managing documents and

spreadsheets.

Additionally, the Raspberry Pi has the ability to interact with the outer world;

it was and continues to be used in a great number of digital projects,

ranging from audio applications (home-made pianos with push buttons),

weather stations (with different temperature and pressure sensors) or

security surveillance (with infrared sensors). One of the primary reasons this

system was invented was to allow children to discover the world of

programming, to understand how computers work and to learn how to use

them.

*from me*

The most used connector for such home projects is the General Purpose

Input Output header (GPIO), which offers the Raspberry Pi the ability to

send and receive digital signals for example. It uses 3.3V output, which may

require some adapters to use some 5V devices intended for Arduino

projects.

*fm*

Raspberry Pi was created by the Raspberry Pi Foundation, a foundation

registered as an educational and charity one in Great Britain. The scope of

this foundation is to advance the education of children and adults, especially

in the IT domain, computer science and adjacent domains.

Currently, there are 5 generations of Raspberry Pi on the market, in

chronological order: 1,2, Zero, 3,4. Each generation has multiple models, as

presented in the table below.

Family

Model

RAM

Ethern
et

Wireles
s

GPIO

Releas
ed

Discont
inued

CPU

Raspberry

Pi 1

B (

512

MB)

Yes

No

26-pin

2012

Yes

1 Core,

700MHz

A (

256MB)

No

2013

Yes

1 Core,

700MHz

B+(

512

MB)

Yes

40-pin

2014

1 Core,

700MHz

A+(

512

MB)

No

2014

1 Core,

700MHz

Raspberry

Pi 2

B

1 GiB

Yes

No

2015

4 Cores,

900 MHz

Raspberry

Pi Zero

Zero

512

MiB

No

No

2015

1 Core,

1 GHz

W/WH

512

MiB

Yes

2017

1 Core,

1 GHz

Raspberry

Pi 3

B

1 GiB

Yes

Yes

2016

4 Cores,

1.2 GHz

A+

512

No

2018

4 Cores,

1.4 GHz

B+

1 GiB

Yes

2018

4 Cores,

1.4 GHz

Raspberry

Pi 4

B (1 GiB)

Yes

Yes

2019

4 Cores,

1.5 GHz

B (2 GiB)

B (4 GiB)

Although different from a processing power standpoint, all Rpi models have

some common software and hardware characteristics. Firstly, all the

processing happens on a single chip, hence the name system on a chip

(SOC), made by Broadcom. This chip contains a central processing unit

(CPU) that is ARM compatible and a graphics processing unit, namely the

Broadcom VideoCore IV. The speed and number of cores of the CPU varies

according to the model, as the amount of RAM. Since the Raspberry Pi does

not have any non volatile memory on board, a microSD (or SD card for older

models) is needed to store an operating system and user data. All models

include at least one USB port for peripherals like mice, keyboards, USB

memory sticks, webcams and an HDMI video and audio output for digital

monitors. There is also a 3.5mm composite jack for analog video and audio.

Most models have built in networking capabilities, either through an RJ45

Ethernet jack or using WiFi 802.11n.

The Cortex A7 Processor – ARMv7 Architecture.

The ARM architecture forms the basis for any ARM processor. Over time, the

ARM architecture evolved by including architecture attributes that satisfy the

increasing demands regarding new functionality, better security and higher

performance. The ARM architecture supports implementations in a large

range of performance points, establishing itself at the peak of many

markets. This architecture type is used in a large range of applications, from

simple implementations to advanced implementations using cutting edge

micro-architecture techniques. The key attributes of the ARM architecture

are the implementation dimensions, the performance and the small power

consumption.

The ARM architecture is similar to a RISC architecture, incorporating the

following typical attributes:

-Uniform register storage architecture, meaning the data processing takes

place only in the content of the registers, not directly in the memory

-Simple addressing modes, with storage addresses determined only by the

content of the registers and the instruction field.

Additionally, the ARM architecture bring the following improvements:

-Ability to control the ALU and the shifter in the majority of data processing

instructions to maximize their usage

-Addressing modalities with auto incrementation and auto decrementation to

optimize program loops

-Loading and storing multiple instructions to maximize the data quantity

-Conditional execution of the majority of the instructions to maximize the

execution rate.

These improvements made to a base RISC architecture allows ARM

processors to obtain a good balance between high performance, low sizes of

written code, low power consumption and low silicon areas.

The processor inside the Raspberry Pi is a multimedia Broadcom BCM2836

system on a chip (SOC). Most of the system components, including the CPU

and GPU, together with the audio unit and the hardware communication part

are housed together on a single chip. The random access memory (RAM) is

located on a separate chip, as with the networking controller. This SoC

construction, along with the ARM instruction set architecture (ISA)

differentiates it from ordinary laptops or desktops.

The ARM architecture, developed by Acom Computer around the end of the

1980’s, is not so common on desktops. Instead, it excels in the area of

mobile equipment, as an example, most modern Android and iOS based

smartphones have a processing core based on the ARM architecture. Having

a reduced instruction set and a low power consumption, an ARM processor is

the ideal choice for portable devices, instead of using common desktop x86

based processors.

Since the BCM2836 is based on the ARM architecture, this enables its small

size: low power consumption means it can be powered from a phone charger

or portable battery pack using an USB connector at 5V with a maximum

current of 3A for the most powerful models (15W under full load). Another

advantage is that no active cooling is required, keeping the cost, noise and

size at low levels.

(end Andrei Gaita), to insert picture of raspberry highlighting ports and

components

LCD

(

How to control a character I2C LCD with Arduino



)

(

https://electronicshobbyists.com/raspberry-pi-lcd-display-interfacing/

)

An LCD is an electronic display module which uses liquid crystal to produce a

visible image.

The 16×2 LCD display used in this project is a basic

module commonly used for outputting information in microcontroller or

single board computer projects. The 16×2 refers to a display with 16

characters per line in 2 such lines. In this LCD each character is

displayed in a

5×7

pixel matrix.

The LCD has 16 pins, but we use an I2C interface in order to have

fewer connections…

There are only 4 pins, 2 for power (+5V and Ground) and 2 for the I2C

communication, SCL (the clock signal) and SDA (the data signal). The

I2C protocol is synchronous and serial, meaning that the clock dictates

the flow of data, and only one bit is sent at a time.

https://en.wikipedia.org/wiki/File:I2C_data_transfer.svg

The LCD is used to display information about the capturing process (if

the scan is successful or if there are errors encountered) and about the

final results, displaying the winner for each election.

Button (include timeout to prevent multiple clicks, allow after image has

finished processing)

The push buttons are used to control the functioning of the main program.

A button simply alters the state of the circuit between an open or short

circuit.

LED (indicatii+led pt lumina foaie!)

The Light Emitting Diodes are used for easy visual signalling of the program

status, namely the red colour will indicate an error in identifying the paper

sheet (for example, the markers are not detected properly, due to a

improper positioning), the yellow colour will announce that the sheet paper

has been successfully scanned, but there are invalid votes as defined by the

limit of votes per election in the Excel file. Lastly, the green colour will signal

the total success of the scan; all the votes are valid.

Buzzer

The speaker is used to acoustically warn the user of an error, or if he/she

may proceed.

Capitolul y

Support Hardware (mounting mechanism)

For the non-electrical hardware, we use the following objects:

1)A paper tray, without angles, to prevent anomalies in the scanning

procedure, due to the slight changes in distances between square markers.

2)Wood beams, 15×15 mm size

3)Glue for fixating the components together

Capitolul z

Software (Namelic: manolescu vlad stefan)

A programming language is a collection of words and rules for a computer in

order to perform certain tasks.

The role of it is to allow a programmer to transmit to a computer, via the

use of programs, the actions it must perform in an exact manner specifying

also the order of operations and the data to use.

We can classify the programming languages into two large categories:

1.Low level languages, dependent on the hardware being used

-The machine language, which is regarded as a primitive, lowest level,

hardware dependent programming language. It is rarely being used since it

is error prone and tedious, the programmer having to manually manage

individual addresses allocations, for example. The instructions, represented

as a series of binary 1s and 0s, differ from one computer to another.

The assembly language is based on a piece of software called assembler,

which converts a program into machine code. This language allows the

programmer great control over everything that happens inside the

computer.

2. High level languages, independent on the hardware being used

Initially called autocodes, they rely on a compiler to convert a source text

program code to an executable program in lower level code that can be

understood by the computer. The first ones were for example, COBOL, for

economic use, introduced in 1959, or Fortran, for mathematics and science

use, introduced in 1957.

Procedural programming (i.e. Pascal, C), introduced in the 1970’s, appeared

with the purpose to create programs capable to be safe in functioning for a

long time. It is a programming method that decomposes complex problems

into simpler subproblems called modules. This approach has the name

“top-down”. Any algorithm can be composed from only three control

structures, according to the Bohm and Jacopini theorem:

-The sequential structure – the sequence

-The alternative structure – the decision

-The repetitive structure – the loop

Object oriented programming (OOP) (i.e. C++, Java, Python), introduced in

the 1980’s, proposes the grouping of data and codes from one structure into

individual code blocks that interact with each other. Objects in OOP are

representations of real life entities most of the time, and that led to a better

understanding of the programs and how to debug them.

Another important characteristic that is used to classify programming

languages is by the modality of translation:

-Compiled languages:

For example C,C++, Java, Pascal. Using a compiler, the source text code

program is translated into machine language and produces a separate file

which can then be executed. The advantage is that the programs run faster,

because it is only compiled once, and then an optimized machine code is

produced, which can be run multiple times. The compiled file can then be

used on other machines, without the presence of a source file, which is

advantageous for intellectual property protection, although there are

decompilers that can create a source code from the compiled file. Another

advantage is that during the compilation process, the compiler will check the

entire code and can warn users about errors, so the program can be

executed only if it is correct from a syntax perspective at least, it does not

prevent runtime errors, like division by 0, stack overflows, etc..

-Interpreted languages:

For example PHP, Javascript, Python, Matlab. These languages rely on an

interpreter, which converts the source code to machine code line by line.

They are slower than compiled languages, because each time the program is

executed, the code must be translated. Another disadvantage is that the

code is verified for errors as it is being executed, which may lead to time

losses, because the code has to be run in order to be verified. Nevertheless,

modern computers are able to perform the translation quickly, using various

techniques like prefetching and caching. Additionally, if the program is

modified frequently, the difference between compiling it after a change or

interpreting it after a modification becomes less apparent.

Therefore, as a conclusion, the ideal programming language for many use

cases, except in time critical applications where the code must run at a very

specific timing, is a high level one, since the time spent developing the

application is lower due to more friendly syntax and less constraints to be

considered, for example managing the memory addresses and registers.

Object oriented programming languages are easier to use since they are

easier to understand and easier to modify, using the philosophy of

polymorphism for example, an object can be added or changed requiring

major changes to the original program. Since the computers today are very

powerful compared to when programming emerged, the time difference

between compiled and interpreted languages can be considered negligible.

End Manolescu Vlad stefan

Python (namelic: manolescu vlad stefan)

Python is a very popular programming language in the IT domain, according

to the latest statistics on Github. This programming language appeared in

the year 1991 and was created by Guido van Rossum. Currently, Python is

used by companies like Google and Yahoo for web applications but also for

embedded projects. Youtube and Amazon are websites that were developed

using Python. A big advantage that lead to the high popularity of the Python

programming language is its implementation using CPython. CPython can be

defined as both an interpreter and a compiler as it compiles Python code into

bytecode before interpreting it. CPython is included in operating systems like

Linux and Mac OSX. Due to the fact that it is interpreted and the CPython

utility can be found on many devices, it is possible to run a Python

program on any operating system without any additional adjustments.

A fundamental concept that is at the basis of Python programming language

is indentation. The indentation is the placement of the code on lines under a

set of rules which helps the IDE interpret the code written by the

programmer. This modality of writing code has helped reduce the number of

lines a programmer has to write to obtain the same algorithm (for example,

omission of curly braces “{,}” in loops like in the C programming language),

but at the same time it forces the maintaining of a clean and easy to read

code. A well written and easy to read code is a serious argument for a

company to adopt and code in that programming language since it makes

team work more efficient.

From a programming type perspective, Python can be used both in

functional object oriented programming and in procedural programming,

especially used for embedded systems. Similarly to Java, the memory

administration is managed through a service called garbage collector, which

automatically deletes from memory variables that are not being used

anymore, unlike C.

The concept “Batteries included” suggests that any programming language,

no matter the mode it was thought and projected, requires a set of libraries

to have a practical utility. The popularity of Python resulted in an important

advantage of this open-source programming language since it led to a very

large quantity of libraries that can be accessed by any programmer. The

Python

Application Programming Interfaces (API) offer a wide range of

functionalities from basic ones (modifying a string) to work with processes

and threads. An example can be implementing a Python code with the scope

of executing commands that are usually done with Matlab (which is a

non-free, proprietary software), like for example working with matrices and

plotting graphs. This is possible with the help of “matplotlib”. Another

example is the wxPython package which offers methods and data structures

specific to the creation of a graphical user interface.

Another characteristic that makes the code written in Python to be more

compact is its permissive nature of the language to allow not specifying the

type of a variable when declaring it. With the help of the interpreter, the

type of the variable is given by the content the programmer gives it. For

example:

variable_a=10

#the interpreter will consider this variable of type integer

variable_b=”this is a string”

#the interpreter will consider this variable of type string

Python does not allow operation with different types of objects and has the

concept of mutable and immutable variables. An immutable variable is a

variable whose contents cannot be modified after being initialized. For

example:

variable_c=”home”

variable_c[2]=”l”

#will result in an error:TypeError: 'str' object does not support item

assignment

The term “sugar coding” appeared recently in programming ,replacing the

functions from C like strstr that had the function of checking if a substring is

present in a string, with an expression used in Python

if(string_1 in string_2==True):

Functions in Python are different from classical ones found in C and Java. In

C, the function can either be void, if it returns nothing, or of a specific type

in case the function has to return that type in the main program or in

another function. In Python, the functions are declared with “def” followed

by the name of the function and the parameters it has to receive inside

brackets, like other programming languages. The difference is that the

programmer does not need to think ahead if his function needs to return

something, it can actually return multiple types if there is an if-else

statement, including void.

Python 2 vs Python 3

Excel

Excel is a spreadsheet editor software. A spreadsheet is a grid of cells

arranged in numbered rows and letter-named columns to organize data

manipulations like arithmetic operations.

Linux: (copy from gheorghe alin)

Python: (how to install python), the libraries and the IDE

Client-Server networking stuff:

Putty: remote assistance!!!

Cuprins:

-Definitii – imagine (extragere fisheye, posibil binarizare, si fill percent!!!!!!!)

-Hardware -raspberry pi

-Software -despre python (avantaje, dezavantaje)

Premise: practical product (simple for the user to use, cheap to produce) for scanning many

complex votes (lots of boxes and conditions for validity)

Excel: popular program, known by many users, graphical interface, not inserting in console

Squares in corners for detection

Rules: Only on even rows, where to write Election/Candidates (which column),

can be continued on second part, outside print area how many votes are allowed(A,B-n,C,etc),

equal/constant row/column size!!!(debug, challenges)

Two sheets: for voting and results

Advantage of python: can be run on Windows/Mac/Linux computer or Raspberry Pi if no

computer present

For saving costs, a laptop/desktop can be used, or if not possible a RPi.

RPi: LCD and buttons for operating: Button for scanning each picture and finishing, and then

scroll the results (describe lcd i2c)

Hardware: Off the shelf paper tray (cheaper and faster than 3D printing), wood for support(easy

to make), usual webcam for compatibility reasons, insert measurements for distances

-Despre Raspberry Pi(hard, soft, GPIO, Power(battery, boost,etc)), f versatil (sistem fisiere,

internet,gpio,etc)

Python libraries used:

*os:for opening folder with images

*counter:for titles/ number of candidates voted per title for validation

*xlrd:for opening excel file

*pil:for image processing

*openpyxl:for writing report

Program workflow:

-We specify the location of the excel and forder with pics

-Open the excel and process it:

-Create vector with the candidates(what we see in excel: blank, candidate, blank, candidate

for easy association with image)

[A11, , A12, ,A13, ]

-Create vector with titles

-Create vector with types of votes

-Remove blank title vector elements

-Remove blank type vector elements

-Parese types of votes(A,B-N)=>vector[1,99,2]

-Use counter to associate types of votes to titles

-Create count votes vector, all 0, and backup for invalidation

-Give approximate coordinate of upper left marker

-Create vector for displaying valid/invalid

-Open image, scan for exact boundaries of first marker, then search for second and third marker

-Given the distances, calculate the distance vertically between boxes

-Scan the image: if pixel is black, annotate in votes vector and title vector

-Check if there are more votes than imposed for each election

-If there are, remove all votes for that election

-Update counter for invalid/invalid

-Write in excel the results: valid/invalid votes for each election, and results

-Real image: have threshold for distances of squares(vert/horiz),try and detect rotation,fill

percent for voting boxes, rgb to gray (describe rgb2gray), color threshold~100 out of 255

-Describe camera(fisheye effect)

-Show performance on raspberry (slow init but fast processing, maybe compare with pc)

-improve:rigidity, automatic scrolling like in printers

-Add buzzer, streetlight leds (processing, ok/error in detecting/error too many votes)

-Send results to server via http (describe internet, ip, protocol http)

-Config file (initial pixel location, where to find excel and pictures, id for sending to server)

-Write about terminal commands to configure (install pip, etc) (despre autostart(headless))

-Make something simple, reliable (not over the top, fixed position)

-Rpi block diagram cpu etc, orcad connections external

Anexa: Codul final

-> make flowchart(s)

https://docs.google.com/document/d/1lYmuWl-X4-sWHxhouIgD7mgf792tHOVmj
d0Krb_aAjo/edit

http://etti.pub.ro/absolvire/vizualizeaza.php

https://docs.google.com/spreadsheets/d/1HVfTPX1EGi_JnReBTEsmlsOnn9PUdtk
__J8F2GMidP0/edit?ts=5db80358#gid=394587576

Similar Posts