Skip to content

Commit

Permalink
Convert image to tsv file
Browse files Browse the repository at this point in the history
  • Loading branch information
dannnylo committed Oct 25, 2020
1 parent cec4d43 commit 25ee33e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ Convert imagem into PDF with text.
iex> TesseractOcr.PDF.read("test/resources/world.png", "/tmp/test")
"/tmp/test.pdf"
```
Convert imagem into TSV with text.

```elixir
iex> TesseractOcr.TSV.read("test/resources/world.png", "/tmp/test")
"/tmp/test.tsv"
```
24 changes: 24 additions & 0 deletions lib/tesseract_ocr/tsv.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
defmodule TesseractOcr.TSV do
@moduledoc """
Documentation for TesseractOcr.TSV.
"""

import TesseractOcr.Utils

@doc """
This function reads the words on image by OCR and returns the TSV's file's path
## Examples
iex> TesseractOcr.TSV.read("test/resources/world.png", "/tmp/test")
"/tmp/test.tsv"
"""
def read(path, output, options \\ %{}) when is_binary(path) do
options = Map.merge(options, %{c: "tessedit_create_tsv=1"})

command(path, output, options)

"#{output}.tsv"
end
end
11 changes: 11 additions & 0 deletions test/tesseract_ocr/tsv_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule TesseractOcr.TSVTest do
use ExUnit.Case
doctest TesseractOcr.TSV

test "read image and saves on a TSV" do
tsv_path = TesseractOcr.TSV.read("test/resources/world.png", "test/test", %{lang: "eng", psm: 7, oem: 1})

assert tsv_path === "test/test.tsv"
File.rm(tsv_path)
end
end
6 changes: 6 additions & 0 deletions test/test.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
level page_num block_num par_num line_num word_num left top width height conf text
1 1 0 0 0 0 0 0 295 71 -1
2 1 1 0 0 0 2 2 183 54 -1
3 1 1 1 0 0 2 2 183 54 -1
4 1 1 1 1 0 2 2 183 54 -1
5 1 1 1 1 1 2 2 183 54 95 world

0 comments on commit 25ee33e

Please sign in to comment.