Issue with declaring Tesseract OCR TessBaseAPI - visual-studio-2013

I am new to Tesseract API. Currently I am running the sample program from the Wiki on Visual Studio 2013, and the program is as follows.
#include "leptonica\allheaders.h"
#include "iostream"
#include "api\baseapi.h"
#include "stdio.h"
using namespace std;
using namespace tesseract;
int main(int argc, char** argv)
{
char* outText;
TessBaseAPI *api = new TessBaseAPI();
// Initialize tesseract-ocr with English, without specifying tessdata path
if (api->Init(NULL, "eng"))
{
fprintf(stderr, "Could not initialize tesseract.\n");
exit(1);
}
// Open input image with leptonica library
Pix *image = pixRead("/usr/src/tesseract-3.02/phototest.tif");
api->SetImage(image);
// Get OCR result
outText = api->GetUTF8Text();
printf("OCR output:\n%s", outText);
// Destroy used object and release memory
api->End();
delete[] outText;
pixDestroy(&image);
return 0;
}
When I compile this with VS2013, I get the following errors.
1>------ Build started: Project: OCRTest, Configuration: Debug Win32 ------
1> main.cpp
1>c:\tesseract-build\include\leptonica\pix.h(209): warning C4305: 'initializing' : truncation from 'double' to 'const l_float32'
1>c:\tesseract-build\include\leptonica\pix.h(211): warning C4305: 'initializing' : truncation from 'double' to 'const l_float32'
1>c:\tesseract-build\tesseract-ocr\api\baseapi.h(32): fatal error C1083: Cannot open include file: 'platform.h': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I believe I have not built the tesseract source properly, but I cannot be sure. Also, declaring
TessBaseAPI * api = new TessBaseAPI()
throws up errors such as 'type specifier expected' when cursor is moved over TessBaseAPI(). Help would be greatly appreciated, and thank you in advance!

Assuming that you are using Tesseract 3.02.02 & leptonica 1.68 library.
Follow these steps.
Remember to check Tesseract Development files option when installing Tesseract
Add below Include folders in Project solutions -> VC++ Directories
C:\Program Files\Tesseract-OCR\include
C:\Program Files\Tesseract-OCR\include\tesseract
C:\Program Files\Tesseract-OCR\include\leptonica
Add below lib folder in Project solutions -> VC++ Directories
C:\Program Files\Tesseract-OCR\lib
Add additional dependencies in Configuration Properties -> Linker->Input ->Additional Dependencies
libtesseract302.lib
libtesseract302d.lib
liblept168.lib
liblept168d.lib
General program structure
>
> #include <baseapi.h>
> #include <allheaders.h>
> #include <iostream>
>
> using namespace std;
>
> int main(void)
> {
> tesseract::TessBaseAPI api;
> //...
> }
>
>

Related

openssl/conf.h file not found error on MacOS

When trying to compile code (using cmake), I keep getting this error :
In file included from /usr/local/include/cpprest/http_client.h:68:
In file included from /usr/local/include/boost/asio/ssl.hpp:18:
In file included from /usr/local/include/boost/asio/ssl/context.hpp:23:
In file included from /usr/local/include/boost/asio/ssl/context_base.hpp:19:
/usr/local/include/boost/asio/ssl/detail/openssl_types.hpp:23:10: fatal error: 'openssl/conf.h' file not found
#include <openssl/conf.h>
^~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/httpclient.dir/http_client.cpp.o] Error 1
make[1]: *** [CMakeFiles/httpclient.dir/all] Error 2
make: *** [all] Error 2
I have tried to follow these links but nothing helps :
Fatal Error: 'openssl/conf.h' file not found
and
'openssl/conf.h' file not found error on on MacOS Big Sur and 'openssl/conf.h' file not found error on MacOS Sierra
Following is my cmake :
cmake_minimum_required(VERSION 3.9)
find_package(cpprestsdk REQUIRED)
set (CMAKE_CXX_STANDARD 11)
add_executable(httpclient http_client.cpp)
set(OPENSSL_ROOT_DIR /usr/local/opt/openssl#3)
#set(OPENSSL_LIBRARIES /usr/local/opt/openssl#3/lib)
set(OPENSSL_ROOT_DIR /usr/local/opt/openssl#3/*)
set(OPENSSL_LIBRARIES /usr/local/opt/openssl#3/lib)
include(FindOpenSSL)
target_include_directories(httpclient INTERFACE ${OPENSSL_ROOT_DIR}/include)
target_link_libraries(httpclient PRIVATE cpprestsdk::cpprest
openssl)
I have also tried setting LDFLAGS and CPPFLAGS, it din't help.
Also tried re-installing boost - din't work.
Please help me understand how to resolve this.
Thanks!
I'm facing the same problem. Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.22)
project(Test)
set(CMAKE_CXX_STANDARD 14)
set(OPENSSL_ROOT_DIR /usr/local/opt/openssl) # it points to openssl#3
find_package(Boost COMPONENTS system filesystem REQUIRED)
find_package(cpprestsdk REQUIRED)
add_executable(Test main.cpp)
target_link_libraries(
Test
PRIVATE Boost::system
PRIVATE Boost::filesystem
)
Here is C++ test code (the Boost tutorial code):
#include <ctime>
#include <iostream>
#include <string>
#include <boost/asio.hpp>
#include <cpprest/http_msg.h> // the code can be compiled with this "include"
// #include <cpprest/http_client.h> // compilation with this "include" ends with the same openssl error
using boost::asio::ip::tcp;
std::string make_daytime_string()
{
using namespace std; // For time_t, time and ctime;
time_t now = time(0);
return ctime(&now);
}
int main() {
std::cout << "Ahoj" << std::endl;
try
{
boost::asio::io_context io_context;
tcp::acceptor acceptor(io_context, tcp::endpoint(tcp::v4(), 13));
for (;;)
{
tcp::socket socket(io_context);
acceptor.accept(socket);
std::string message = make_daytime_string();
boost::system::error_code ignored_error;
boost::asio::write(socket, boost::asio::buffer(message), ignored_error);
}
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}
return 0;
}
OS: macOS Monterey 12.4
XCODE: 13.4.1
Build tool: Ninja
IDE: CLion 2022.1.3
btw. According to https://github.com/microsoft/cpprestsdk documentation, the cmake configuration is minimalistic for cpprestsdk but it does not work on mac (on windows is a problem as well - cpprestsdk package -> #include <cpprest/http_listener.h> -> build error C2338 static_assert failed: 'type is not supported for extraction from a stream').

Why is the library not included?

Visual Studio Code project
CMake connects files
As a beginner I want to integrate testlib.h
and testlib.c which I can call in the main.c
testlib.c and .h should also call boot.h - but this doesn't work!
Including my teslib.h and testlib.c in main,c works. But In testlib.h I need access e.g. to boot.h ... but I cannot include this file!
Here is the code:
#include "testlib.h"
#include <stdint.h>
#include "boot.h" // why there comes an error when I want to include this?
#include <stddef.h>
int f123(void){
int a = 2;
return a;
}
void print_uart_22(const char text[])
{
int a;
(void)a;
(void)text;
}
Why there comes the error message?
There must be something wrong with the paths...
but main.c is next to testlib.h
main.c also includes "boot.h" without error
/testlib.c:4:10: fatal error: boot.h: No such file or directory
[build] #include "boot.h"
[build] ^~~~~~~~
[build] compilation terminated.
Why?
hahaaha
main.c is located next to testlib.h and testlib.c!
main.c includes also boot.h and there is no error.

basic setup of C++/CLI code so that it can be consumed by unmanaged C/++

I am trying to learn C++/CLI, with the plan of writing a DLL which will be consumed by (unmanaged) C code. However, I cannot get the most basic example to build, as is reproducible below:
I am working in Visual Studio Express 2013.
Create new project -> CLR ->class library
LearnCli.h:
extern "C" __declspec(dllexport)
int __stdcall TestFunc();
LearnCli.cpp:
#include "stdafx.h"
#include "LearnCli.h"
int __stdcall TestFunc()
{
return 3;
}
Build with no problems.
Add Project -> Win32 ->Console Application
From the context menu in solution explorer for the new console project:
Add -> reference -> LearnCli
stdafx.h
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
#include "..\LearnCli\LearnCli.h"
ConsoleApplication.cpp
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int z;
z=TestFunc();
cout << "Function returns:" << z << endl;
cin.get();
return 0;
}
intellisense has no problems, but on build:
Error 1 error LNK2019: unresolved external symbol _TestFunc#0 referenced in function _wmain [path]\Projects\LearnCli\ConsoleApplication1\ConsoleApplication1.obj ConsoleApplication1
What am I missing which is not allowing the win32 console app to find the function? Cheers.
Edit
Thanks to the comment and link, I have change the LearnCli.h file to
#ifdef LEARNCLIAPI_EXPORTS
#define LearnCliApi_DECLSPEC __declspec(dllexport)
#else
#define LearnCliApi_DECLSPEC __declspec(dllimport)
#endif
And gone to Project -> Properties -> C/C++ -> Preprocessor ->Definitions
and added LEARNCLIAPI_EXPORTS. unfortuately the error is unchanged
You need to link your application(exe) project with the .lib built from dll project.
You can add that from Project settings >> Linker >> Input files or simply put a line on your source.
i.e.
pragma(comment, "lib:<your_lib.lib>")

Linker issue in opencv

I am using OpenCV 2.4.6 in Visual Studio 2012 and I have testing one of the sample programs , name matcher_simple.cpp -- which matches two sample images , image1 and image2.
#include <stdio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/opencv.hpp"
using namespace cv;
static void help()
{
printf("\nThis program demonstrates using features2d detector, descriptor extractor and simple matcher\n"
"Using the SURF desriptor:\n"
"\n"
"Usage:\n matcher_simple <image1> <image2>\n");
}
int main(int argc, char** argv)
{
if(argc != 3)
{
help();
return -1;
}
//cv::initModule_nonfree();
Mat img1 = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
Mat img2 = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
if(img1.empty() || img2.empty())
{
printf("Can't read one of the images\n");
return -1;
}
// detecting keypoints
SurfFeatureDetector detector(400);
vector<KeyPoint> keypoints1, keypoints2;
detector.detect(img1, keypoints1);
detector.detect(img2, keypoints2);
// computing descriptors
SurfDescriptorExtractor extractor;
Mat descriptors1, descriptors2;
extractor.compute(img1, keypoints1, descriptors1);
extractor.compute(img2, keypoints2, descriptors2);
// matching descriptors
BFMatcher matcher(NORM_L2);
vector<DMatch> matches;
matcher.match(descriptors1, descriptors2, matches);
// drawing the results
namedWindow("matches", 1);
Mat img_matches;
drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches);
imshow("matches", img_matches);
waitKey(0);
return 0;
}
On compiling I get this error :
1>------ Build started: Project: opencvreinstated, Configuration: Release x64 ------
1>matcher_simple.obj : error LNK2001: unresolved external symbol "public: __cdecl cv::SURF::SURF(void)" (??0SURF#cv##QEAA#XZ)
1>matcher_simple.obj : error LNK2001: unresolved external symbol "public: __cdecl cv::SURF::SURF(double,int,int,bool,bool)" (??0SURF#cv##QEAA#NHH_N0#Z)
1>C:\Users\motiur\documents\visual studio 2012\Projects\opencvreinstated\x64\Release\opencvreinstated.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I have testing this in release mode 64 bit , I also have successfully ran simple other opencv samples , for example streaming live video . I did not have these sort of issues there . Help is appreciated . Thanks.
You have to link in the nonfree module, since this is where the Surf features are implemented.
Go to project Properties -> Linker -> Input, and add smth like opencv_nonfree246d.dll to Additional Dependencies field.
For details, please, see http://docs.opencv.org/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html#the-local-method

opencv with visual studio 2010 error

I am trying to build my first opencv application, I added the include directories and the library directories and then added the linking input which is some opencv.lib files after running this code:
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat im = imread("c:/full/path/to/lena.jpg");
if (im.empty())
{
cout << "Cannot load image!" << endl;
return -1;
}
imshow("Image", im);
waitKey(0);
}
but I got this error:
The program can't start because libgcc_s_dw2-1.dll is missing from your computer.
the error list include:
Warning 1 warning D9002: ignoring unknown option '-static-libgcc' c:\Users\Kato\documents\visual studio 2010\Projects\cvtest\cvtest\cl cvtest
I added -static-libgcc to command line additional options but the same error.

Resources