How to extract multiple lines from an image using Tesseract OCR? - visual-studio-2010

We have passed an image with single line having the text "Hello World" and the Tesseract OCR perfectly show the result 'Hello World'.
But when we passed an image with multiple lines text
Hello world
How are you
it doesn't show anything.
Here is our codes:
#include "stdafx.h"
#include <iostream>
#include <baseapi.h>
#include <allheaders.h>
#include <fstream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
tesseract::TessBaseAPI api;
api.Init("", "eng", tesseract::OEM_DEFAULT);
api.SetPageSegMode(static_cast<tesseract::PageSegMode>(7));
api.SetOutputName("out");
cout<<"File name:";
char image[256];
cin>>image;
PIX *pixs = pixRead(image);
STRING text_out;
api.ProcessPages(image, NULL, 0, &text_out);
cout<<text_out.string();
ofstream files;
files.open("out.txt");
files << text_out.string()<<endl;
files.close();
cin>> image;
return 0;
}
input with 1 line
output with 1 line
input with 2 lines
output with 2 lines

Page Segmentation Mode 7 treats the image as a single text line. Try 3, which is Fully automatic page segmentation, but no OSD (default).

Related

Visual Studio VS 2022 won't display cout simplest Code

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
string fileTxt;
cout << "disply ok";
return 0;
}
i was working on file handling C++ ifstream but i can't get the Code to open my .txt, so i start troubleshoot and removing all the Codes to only have "hello world" program remaining...
And that still won't work, all i got is a Terminal that goes off instantly...without any text i asked it to display eg. "dsply ok";

How do you run code up until a certain line on Xcode?

#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
cout << argv[0]; //ONLY WANT TO RUN TILL HERE
for(int x = 1; x < argc; x++)
{
string s(argv[x]);
if(
}
return 0;
}
I added and enabled a breakpoint on that line, but it still runs the whole program.
Screenshot of code:
You need to fix the errors in your code. The line with the red dot next to it has a syntax error that needs to be solved. Once you fix the error the program will run as desired.

Save list of files in array

I am making a C++ program which should be able to list the files from particular directory and save each file name as a string(which will be processed further for conversion). Do I need array of strings? Which functionality should I use. The number of files is not fixed.
Main thing is I can't enter the names manually. I must accept the names from the list generated.
In this case you want to use a vector:
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<string> file_names;
file_names.push_back("file1.txt");
file_names.push_back("file2.txt");
file_names.push_back("file3.txt");
file_names.push_back("file4.txt");
return 0;
}
Have you thought about using some command line tools to deal with this? Even input redirection will work for this. Example:
./Cpp < echo somedir/*
Where Cpp is the name of your compiled binary, and somedir is the directory you want to read from
Then in your c++ program, you simply use std::cin to read each filename from standard in.
#include <vector>
#include <string>
#include <iterator> // std::istream_iterator, std::back_inserter
#include <algorithm> //std::copy
#include <iostream> // std::cin
int main()
{
std::vector<string> file_names;
// read the filenames from stdin
std::copy(std::istream_iterator<std::string>(std::cin), std::istream_iterator<std::string>(), std::back_inserter(file_names));
// print the filenames
std::copy(file_names.begin(), file_names.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
return 0;
}

opencv videocapture empty frame

i'm trying to acquire image from an wireless cam with EasyCAP tuner. I can get images with any other video capture programs and matlab but in opencv i get empty frames. This code worked with my laptop webcam and with a logitec webcam. With tuner it sends me in infinite loop here beacuse of empty frame.
while (frame.empty())
cap>>frame;
I'm using visual stuido 2010 , i have tuner on the 2nd slot(first is webcam)and my code is:
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <windows.h>
#include <stdio.h>
using namespace cv;
using namespace std;
VideoCapture cap(1);
Mat frame;
void main()
{
char key;
namedWindow("imag", WINDOW_AUTOSIZE);
Sleep(1000);
cap.set(CV_CAP_PROP_FRAME_WIDTH,160);
cap.set(CV_CAP_PROP_FRAME_HEIGHT,120);
cap.set(CV_CAP_PROP_FPS,15);
cap.set(CV_CAP_PROP_FOURCC,CV_FOURCC('B', 'G', 'R', '3'));
while (1)
{
cap>>frame;
while (frame.empty())
cap>>frame;
imshow("imag",frame);
waitKey(33);
}
}
without set proprieties is the same

Problems with eval function skipping newlines in $(eval echo $myvar)

I am currently working on a script meant to add a new project generation for any basic editor.
I am using the following structure in order to generate the right basic program (hello, world) according to the language selected by the user :
#!/bin/sh
#this is a short example in the case the user selected C as the language
TXTMAIN="\$TXTMAIN_C"
$TXTMAIN_C="#include <stdlib.h>
#include <stdio.h>
int main(int argc, char const* argv[])
{
printf(\"hello, world\n\");
return EXIT_SUCCESS;
}"
MAIN="./main.c"
touch MAIN
echo -n "$(eval echo $TXTMAIN)" >> "$MAIN"
gedit MAIN
This piece of code gives the following output when you edit main.c :
#include <stdlib.h> #include <stdio.h> int main(int argc, char const* argv[]) { printf("hello, world\n"); return EXIT_SUCCESS; }
However, when replacing line 13 by echo -n "$TXTMAIN_C" >> "$MAIN", it gives the right output :
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char const* argv[])
{
printf("hello, world\n");
return EXIT_SUCCESS;
}
I still don't know wether that's an echo or eval issue, or if there is a way around for my pointer-like problem.
Any advice is very welcome !
There are a few errors in your script, and it's more complicated than it should be.
If you want to use an indirect variable like that, use the ${!FOO} syntax, and put quotes where appropriate:
#!/bin/sh
#this is a short example in the case the user selected C as the language
TXTMAIN=TXTMAIN_C # don't force a $ here
TXTMAIN_C="#include <stdlib.h>
#include <stdio.h>
int main(int argc, char const* argv[])
{
printf(\"hello, world\n\");
return EXIT_SUCCESS;
}"
MAIN="./main.c"
echo "${!TXTMAIN}" > "$MAIN" # overwrite here, if you want to
# append, use >>. `touch` is useless

Resources