-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimageTrans.cpp
More file actions
62 lines (52 loc) · 1.54 KB
/
imageTrans.cpp
File metadata and controls
62 lines (52 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#ifdef WINDOWS
#include<tesseract/api/baseapi.h>
#include<tesseract/ccutil/strngs.h>
#else
#include<tesseract/baseapi.h>
#include<tesseract/strngs.h>
#endif
#include<leptonica/allheaders.h>
#include<iostream>
#include<sstream>
using namespace std;
int main() {
cv::VideoCapture camera(0);
if(!camera.isOpened()) return -1;
//Making the tesseract object
tesseract::TessBaseAPI *myOCR = new tesseract::TessBaseAPI();
const char* lan = "eng";
//Leave the webcam open until a key press
if (myOCR->Init(NULL, lan, tesseract::OEM_DEFAULT))
{
std::cout << "error" << std::endl;
return -1;
}
while(1)
{
if(cv::waitKey(30) >= 0) break;
cv::Mat cameraFrame;
camera >> cameraFrame;
//Creates a Grayscale matrix
cv::Mat gray;
cv::cvtColor(cameraFrame, gray, CV_BGR2GRAY);
//Changes Grayscale matrix black/white
cv::Mat thresh;
cv::adaptiveThreshold(gray, thresh, 255, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY_INV, 11, 5);
//saving the transformed image
imwrite("test.jpg", thresh);
PIX *pixs = pixRead("test.jpg");
//This will send an image for tesseract to extract the text off of it
myOCR->SetImage(pixs);
char *text;
text = myOCR->GetUTF8Text();
pixFreeData(pixs);
//print the text from the image to the console
std::cout << text << std::endl;
//this will display the webcam to the user
imshow("cam", cameraFrame);
}
cv::waitKey(0);
return(0);
}