Skip to content

Commit

Permalink
Adding tessdata parent dir as arg
Browse files Browse the repository at this point in the history
  • Loading branch information
sumedhghaisas committed Feb 23, 2016
1 parent ad1f500 commit ccab0f5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
cmake_minimum_required(VERSION 3.0)

set(HUNTER_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/.hunter/")

include("cmake/HunterGate.cmake")

HunterGate(
Expand Down
2 changes: 1 addition & 1 deletion example.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ var util = require('util');
var result;

console.log('-----------------------------------------------------');
result = sceneText.GetTextSync('sample_images/3.jpg');
result = sceneText.GetTextSync('sample_images/3.jpg', __dirname);
console.log(util.inspect(result, {depth: 9, colors: true}));

19 changes: 10 additions & 9 deletions src/ocr/ocr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class outputOCR{

};

OutputOCR Ocr(string path);
OutputOCR Ocr(string path, string languageFile);
outputOCR Ocr(string path,Rect box);

Rect groups_draw(Mat &src, vector<Rect> &groups);
Expand All @@ -55,11 +55,11 @@ void er_draw(vector<Mat> &channels, vector<vector<ERStat> > &regions, vector<Vec

vector<Rect> computeGroupsWithMinArea(Mat &src,vector<Mat> &channels,float minArea);

vector<DecodedText> doOCR(Mat &image,vector<Mat> channels,vector<vector<ERStat> > regions,vector< vector<Vec2i> > nm_region_groups,vector<Rect> nm_boxes);
vector<DecodedText> doOCR(string languageFile, Mat &image,vector<Mat> channels,vector<vector<ERStat> > regions,vector< vector<Vec2i> > nm_region_groups,vector<Rect> nm_boxes);

Regions computeRegionGroups(Mat &src,vector<Mat> &channels,float minArea);

OutputOCR detectAndDecode(Mat &src);
OutputOCR detectAndDecode(string languageFile, Mat &src);


outputOCR Ocr(string path,Rect box) {
Expand Down Expand Up @@ -104,14 +104,14 @@ outputOCR Ocr(string path,Rect box) {
return output;
}

OutputOCR Ocr (string path) {
OutputOCR Ocr (string path, string languageFile) {
// namedWindow("grouping",WINDOW_NORMAL);
Mat src = imread(path);
cout << "image loaded" << endl;
return detectAndDecode(src);
return detectAndDecode(languageFile, src);
}

OutputOCR detectAndDecode(Mat &src){
OutputOCR detectAndDecode(string languageFile, Mat &src){

// Extract channels to be processed individually
vector<Mat> channels;
Expand All @@ -138,7 +138,7 @@ OutputOCR detectAndDecode(Mat &src){
// draw groups
Rect group_box= groups_draw(src, groups_boxes);
imwrite("save.jpg",src);
vector<DecodedText> decodedTxt=doOCR(src,channels,region.regions,region.region_groups,groups_boxes);
vector<DecodedText> decodedTxt=doOCR(languageFile, src,channels,region.regions,region.region_groups,groups_boxes);


OutputOCR output(Box(group_box.tl().x, group_box.br().x, group_box.tl().y, group_box.br().y), decodedTxt);
Expand All @@ -150,11 +150,12 @@ OutputOCR detectAndDecode(Mat &src){
}
return output;
}
vector<DecodedText> doOCR(Mat &image,vector<Mat> channels,vector<vector<ERStat> > regions,vector< vector<Vec2i> > nm_region_groups,vector<Rect> nm_boxes){
vector<DecodedText> doOCR(string languageFile, Mat &image,vector<Mat> channels,vector<vector<ERStat> > regions,vector< vector<Vec2i> > nm_region_groups,vector<Rect> nm_boxes){
// Text Recognition (OCR)
double t_r = (double)getTickCount();

Ptr<OCRTesseract> ocr = OCRTesseract::create();
cout << languageFile << endl;
Ptr<OCRTesseract> ocr = OCRTesseract::create(languageFile.c_str());
string output;
Mat out_img;
Mat out_img_detection;
Expand Down
2 changes: 1 addition & 1 deletion src/ocr/ocr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ using namespace std;
using namespace cv;
using namespace cv::text;

OutputOCR Ocr(std::string);
OutputOCR Ocr(std::string, std::string);
OutputOCR Ocr(std::string, Rect box);
4 changes: 3 additions & 1 deletion src/sync.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ using Nan::Set;
NAN_METHOD(GetTextSync) {
// get the value of path
v8::String::Utf8Value p(info[0]);
v8::String::Utf8Value p2(info[1]);
string path = string(*p);
string languageFile = string(*p2);
// if the second argument is passed, we use it
if (info.Length() > 1){
//detectRegions = To<bool>(info[1]).FromJust();
}
// call the decoder here
OutputOCR decodedText = Ocr(path);
OutputOCR decodedText = Ocr(path, languageFile);
// set the return value
info.GetReturnValue().Set(Nan::New(decodedText.ToLocal()));
}
Expand Down

0 comments on commit ccab0f5

Please sign in to comment.