# Using Julia to extract information from a ballot

**URL:** <https://discourse.julialang.org/t/using-julia-to-extract-information-from-a-ballot/47239>\
**Category:** Machine Learning\
**Tags:** images\
**Created:** [September 25, 2020, 2:39am UTC](https://discourse.julialang.org/t/using-julia-to-extract-information-from-a-ballot/47239 "2020-09-25T02:39:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)\
**Post date:** [September 25, 2020, 2:39am UTC](https://discourse.julialang.org/t/using-julia-to-extract-information-from-a-ballot/47239/1 "2020-09-25T02:39:03Z")

</div>

I would like to identify tools in the Julia ecosystem to parse a model ballot. For example, from the following PDF,

 ![001-1](https://global.discourse-cdn.com/julialang/original/3X/e/4/e414a653b1288fa96924ddc38cdfc1059b96783f.png)

obtain

- Candidature
- Candidate’s name
- Party Affiliation

---

<div class="post-metadata">

**Author:** ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)\
**Post date:** [September 25, 2020, 3:06am UTC](https://discourse.julialang.org/t/using-julia-to-extract-information-from-a-ballot/47239/2 "2020-09-25T03:06:59Z")

</div>

@sambitdash would it be possible to use the PDF structure to scrape those fields with PDFIO.jl?

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [September 25, 2020, 4:53am UTC](https://discourse.julialang.org/t/using-julia-to-extract-information-from-a-ballot/47239/3 "2020-09-25T04:53:14Z")

</div>

A search shows Avik has written a package called Taro

> **[Taro.jl](http://aviks.github.io/Taro.jl/)**
>
> Work with document files in Julia

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [September 25, 2020, 2:18pm UTC](https://discourse.julialang.org/t/using-julia-to-extract-information-from-a-ballot/47239/4 "2020-09-25T14:18:38Z")

</div>

If all rectangles have the same size you can probably find them with a 2D [matched filter](https://en.wikipedia.org/wiki/Matched_filter)?

Simply extract one rectangle and correlate the image with your little rectangle pattern (kernel). The correlation image will have peaks located on all rectangles in the image.

---

<div class="post-metadata">

**Author:** ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)\
**Post date:** [September 26, 2020, 12:39am UTC](https://discourse.julialang.org/t/using-julia-to-extract-information-from-a-ballot/47239/5 "2020-09-26T00:39:06Z")

</div>

Ended up using OCReract.jl  
Ref: [https://github.com/Nosferican/CandidatosEleccionesGeneralesPR2020](https://github.com/Nosferican/CandidatosEleccionesGeneralesPR2020)

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [September 26, 2020, 12:58am UTC](https://discourse.julialang.org/t/using-julia-to-extract-information-from-a-ballot/47239/6 "2020-09-26T00:58:29Z")

</div>

In this specific case, isn’t possible to find the data in an other format?

---

<div class="post-metadata">

**Author:** ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)\
**Post date:** [September 26, 2020, 1:17am UTC](https://discourse.julialang.org/t/using-julia-to-extract-information-from-a-ballot/47239/7 "2020-09-26T01:17:53Z")

</div>

Highly unlikely. The PR government is known for not being great at government transparency / openness. I was able to programmatically get the political contributions by using Twitter to contact the Electoral Board Comptroller Office and have them tweak an internal API so I could get the data. Right now I have the executive and legislative ballots done. The municipal is a bit trickier because the location / dimensions are not consistent due to some minority parties that don’t list candidates for all local governments.

---

<div class="post-metadata">

**Author:** ![sambitdash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sambitdash/32/1377_2.png) [@sambitdash](https://discourse.julialang.org/u/sambitdash)\
**Post date:** [November 12, 2020, 10:14am UTC](https://discourse.julialang.org/t/using-julia-to-extract-information-from-a-ballot/47239/8 "2020-11-12T10:14:13Z")

</div>

Sorry for my delay in response as I do not login to the forum as often. If you can estimate the rectangular regions, we could use the suggestion given in issue: [https://github.com/sambitdash/PDFIO.jl/issues/55](https://github.com/sambitdash/PDFIO.jl/issues/55)
