Skip to content

Commit

Permalink
Init stripe reassembly
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlyqing00 committed Oct 8, 2018
1 parent ab953a0 commit 0ce7084
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.o
StripeReassembly
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
OPT_FLAGS = -O3
CXX = g++
CXX_FLAGS = $(OPT_FLAGS) --std=c++17 -Wall

LIBS = -llept -ltesseract
INCLUDES = -I./include/

src_dir = ./src/
dst_dir = ./
src = $(wildcard $(src_dir)*.cpp)
obj = $(patsubst %.cpp, %.o, $(src))

default: StripeReassembly
.PHONY: clean

StripeReassembly: $(obj)
$(CXX) $< $(LIBS) -o $(dst_dir)$@

%.o: %.cpp
$(CXX) $< $(CXX_FLAGS) $(INCLUDES) -c -o $@

clean:
rm $(dst)StripeReassembly $(src_dir)*.o
Binary file added data/test0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions include/generate_stripes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef GENERATE_STRIPES_H
#define GENERATE_STRIPES_H

class GenerateStripes {

public:
GenerateStripes();
};

#endif
2 changes: 2 additions & 0 deletions src/generate_stripes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include <generate_stripes.h>

45 changes: 45 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>

int main()
{

tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
// Initialize tesseract-ocr with English, without specifying tessdata path
if (api->Init(NULL, "eng+chi_sim")) {
fprintf(stderr, "Could not initialize tesseract.\n");
exit(1);
}

// Open input image with leptonica library
Pix *image = pixRead("./data/test0.png");
api->SetImage(image);

// Get OCR result
// char * outText = api->GetUTF8Text();
// int conf = api->MeanTextConf();
// printf("OCR output:\n%s", outText);
// printf("Confidence: %d\n", conf);
// delete [] outText;

api->Recognize(0);
tesseract::ResultIterator* ri = api->GetIterator();
tesseract::PageIteratorLevel level = tesseract::RIL_SYMBOL;
if (ri != 0) {
do {
const char* word = ri->GetUTF8Text(level);
float conf = ri->Confidence(level);
int x1, y1, x2, y2;
ri->BoundingBox(level, &x1, &y1, &x2, &y2);
printf("word: '%s'; \tconf: %.2f; BoundingBox: %d,%d,%d,%d;\n",
word, conf, x1, y1, x2, y2);
delete[] word;
} while (ri->Next(level));
}

// Destroy used object and release memory
api->End();
pixDestroy(&image);

return 0;
}

0 comments on commit 0ce7084

Please sign in to comment.