What is the correct way to specify Tesseract options for page segmentation?

I've been trying to understand how to configure tesseract options for page segmentation. I attempted to use tessedit_pageseg_mode: '1', but encountered a halt in the text recognition process. If I input it as number 1, the process completes, but the mode remains default SINGLE_BLOCK.

Currently, I'm running Tesseract version: 1.0.19. I also experimented with 2.0.0-alpha.13, with identical results.

this.tesseract = Tesseract.create({
    workerPath: '../../assets/tesseract/worker.js',
    langPath: '../../assets/tesseract/trained-data',
    corePath: '../../assets/tesseract/core.js',
});
this.tesseract.recognize(this.image, {
    lang: 'eng',
    tessedit_pageseg_mode: '1'
})
.progress((p) => {
    console.log('progress', p);
    this.ocrResult = p.status + ', Progress: ' + Math.round(p.progress * 100) + '%';
})
.then((data) => {
    console.log(data.psm);
    this.ocrResult = data.text;
}).catch((err) => {
    console.error('Error occurred while recognizing text', err);
});

Your assistance would be highly appreciated. Thank you!

Update: I managed to identify the problem. My previous code was written like this

window.Tesseract = Tesseract.create({...
but was directly using Tesseract.recognize(.. which led to downloading the worker, language, and core files from the internet instead of utilizing the provided file path. The file download was somehow getting interrupted when I included the option tessedit_pageseg_mode: '1'.

Uncaught abort() at Error at Na (https://cdn.jsdelivr.net/gh/naptha/[email protected]/index.js:36:26)

Therefore, I am now attempting to utilize local files by adding file:///android_asset/www (as described in this blog post) within the assets folder. However, I am encountering an issue where it fails with this message.

Failed to load file:///android_asset/www/assets/plugins/tesseract/worker.js: Cross origin requests are only supported for protocol schemes: http, data, chrome, https.`

Answer №1

Consider utilizing localhost instead of a relative path, as shown here:


this.tesseract = Tesseract.create({
    workerPath: 'http://localhost/assets/tesseract/worker.js', 
    langPath: 'http://localhost/assets/tesseract/trained-data',
    corePath: 'http://localhost/assets/tesseract/core.js',
});

Source

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Modify Ripple Color on Material UI < Button /> Click Event

This is my custom button component called <MyButton /> import React from 'react'; import { withStyles } from '@material-ui/core/styles'; import Button from '@material-ui/core/Button'; const styles = theme => ({ bu ...

Resetting the AngularJS ui-select component to clear all selections can be achieved without the red color error highlight that appears when the ui-select is marked

I am attempting to clear all selections in an angularjs ui-select. However, the ui-select is set as a required field. When I try to set the ui-select element as undefined using the code below. $scope.country.selected = undefined; The ui-select elemen ...

jquery click event triggers changes on several elements sharing a common class

I am looking to incorporate auto play functionality for a YouTube video on my video style page, which can be found at . Currently, I am able to trigger the video to auto play by clicking on an image thumbnail using the code below. However, I am encounterin ...

Use AppScript to exclude the first row (which contains the column names) when filtering a table

Considering the limitations of Google Sheets with the ImportRange function, I decided to develop an AppScript as a replacement. Although I am new to JavaScript, here is what I have so far: function My_ImportRange() { var clearContent = SpreadsheetApp.ge ...

Encountered an Error in Express.js: Unable to POST /users

I am currently in the process of learning the MEAN stack by following a tutorial and have encountered an error. Unfortunately, I am having difficulty identifying exactly where I went wrong. While attempting to test routes in Postman by creating a user, I ...

Whenever I attempt to execute yarn build within next.js, an error always seems to occur

When attempting to compile my next.js project using the yarn build command, an error consistently occurs: Error: Export encountered errors on following paths: /settings at D:\web3\futnft\frontend\node_modules\next\ ...

Struggling with Angular Components?

Although I have come across discussions on the topic such as this one at How to import component into another root component in Angular 2, my issue remains unresolved. I am facing a similar dilemma. My current challenge involves Angular-Cli - after succe ...

Scroll positioning determines the height of an entity

Here's a code snippet I'm working with: HTML: <div id="wrap"> <div id="column"></div> </div> CSS: #wrap { display: block; height: 2000px; width: 400px } #column { display: block; height: 20px; ...

Executing React's useEffect hook twice

As I work on developing an API using express.js, I have implemented an authentication system utilizing JWT tokens for generating refresh and access tokens. During testing with Jest, Supertest, and Postman, everything appears to be functioning correctly. O ...

State does not contain the specified property - Navigating with React Router Hooks in TypeScript

I've been experiencing issues when using react-router-dom hooks with TypeScript. Whenever I try to access a state property, I get an error stating that it doesn't exist. For more information, you can visit: https://i.sstatic.net/K5NGl.png To ...

Is there a way to incorporate margins into a React component using TypeScript?

I am currently facing a challenge in passing CSS attributes to a component that I am working with. The reason behind this is that I need to modify the margins to fit a specific space, hence my attempt to directly pass the margins. Does anyone have any sug ...

Customizing the Style of Mat-Form-Field

I have designed a search bar using mat-form-field and attempted to personalize the appearance. Currently, there is a gray border-like region surrounding the input field and icons. Moreover, clicking on the input field results in a visible border: <form ...

Steps for personalizing the dataset on a PrimeNG bar graph

I'm currently working with primeng in an Angular project and I need to create a bar chart where the last two horizontal bars have different colors. Right now, the last two bars are incorrectly being assigned to represent dogs and cats. My goal is to ...

typescript code: transforming object values into keys in typescript

Here is a scenario: const obj1 = { a: 'x', b: 'y', c: 'z', } I am looking to automatically create a type like this: type Type = { x: number, y: number, z: number, } I initially considered the following approach: ...

Using Azure AD for authentication: Implementing Msal authentication in a React Next.js application with TypeScript and App Router

Working on a React Next.js web application with Microsoft Authentication Library (MSAL) login integration, using Azure. The app utilizes Next.js with the App Router for routing. But encountering an error when attempting to run the app: createContext only w ...

Problem with IE off-canvas scrolling

Currently, I am facing an issue with the scrolling functionality of an off-canvas sidebar on my Joomla 3 website. It seems to be working fine in Chrome and Firefox, but when it comes to Internet Explorer, the visible scroll bar refuses to move when attempt ...

The reCAPTCHA feature in Next.js form is returning an undefined window error, possibly due to an issue with

Trying to incorporate reCAPTCHA using react-hook-form along with react-hook-recaptcha is posing some challenges as an error related to 'window' being undefined keeps popping up: ReferenceError: window is not defined > 33 | const { recaptchaL ...

Creating an animated background slide presentation

After creating a button group, I wanted the background of the previous or next button to move/slide to the selected one when the user clicks on it. I achieved this effect using pure CSS and simply adding or removing the 'active' class with jQuery ...

Retrieving text from Node.js with the help of regular expressions

I need to extract testcase ids from a list of testcases with titles. Each title includes an id and a description. I want to extract only the id. Here are some examples: TC-ABC-98.1.010_1-Verify the layout credit page TC-RegPMP-1.1.001_2-Verify the [MangerD ...

"Every time ajax is called, it will always generate

function lks() { var groupname = document.getElementById('groupname').value; $.ajax ({ url: 'verifyGroup.php?groupname='+groupname, type: 'get', ...