Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run-tests-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ on:

# Global environment variables
env:
SDK_VERSION: '0.1000.4'
SDK_VERSION: '0.1100.3'

jobs:
test-x86_64:
Expand Down
2 changes: 1 addition & 1 deletion Libraries.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Open Source libraries used in the Scanbot Linux SDK version 10.0.0:
Open Source libraries used in the Scanbot Linux SDK version 11.0.0:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Expand Down
2 changes: 1 addition & 1 deletion examples/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(CMAKE_C_STANDARD 99)

# Find or download Scanbot SDK
if(NOT SCANBOTSDK_VERSION)
set(SCANBOTSDK_VERSION "0.1000.4")
set(SCANBOTSDK_VERSION "0.1100.3")
endif()
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
find_package(ScanbotSDK REQUIRED)
Expand Down
1 change: 1 addition & 0 deletions examples/c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ The example supports five modes: **scan**, **analyze**, **enhance**, **parse**,
./scanbotsdk_example analyze analyze_multi_page --file files/doc.pdf --license <KEY>
./scanbotsdk_example analyze crop_analyze --file images/doc.jpg --save out/crop.jpg --license <KEY>
./scanbotsdk_example enhance straighten_document --file images/doc.jpg --license <KEY>
./scanbotsdk_example enhance straighten_document_with_prior_corners --file images/doc.jpg --license <KEY>
./scanbotsdk_example enhance cleanup_document --file ../../test-scripts/test-images/highlighted.png --mask ../../test-scripts/test-images/highlighted_mask_001.png --save out/cleaned.jpg --license <KEY>
./scanbotsdk_example parse mrz --text "P<UTOERIKSSON<<ANNA<MARIA<<<<<<" --license <KEY>
./scanbotsdk_example live barcode --file images/example.jpg --license <KEY>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef DOCUMENT_STRAIGHTENER_WITH_PRIOR_CORNERS_H
#define DOCUMENT_STRAIGHTENER_WITH_PRIOR_CORNERS_H

#include <ScanbotSDK.h>

scanbotsdk_error_code_t straighten_document_with_prior_corners(scanbotsdk_image_t *image);

#endif
7 changes: 7 additions & 0 deletions examples/c/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <snippets/document/crop_and_analyze.h>
#include <snippets/document/document_cleanup.h>
#include <snippets/document/document_straightener.h>
#include <snippets/document/document_straightener_with_prior_corners.h>

#include <snippets/live/live_barcode.h>

Expand Down Expand Up @@ -81,6 +82,12 @@ int main(int argc, char *argv[]) {

ec = straighten_document(image);
}
else if (strcmp(command, "straighten_document_with_prior_corners") == 0) {
ec = load_image_from_path(file_path, &image);
if (ec != SCANBOTSDK_OK) goto cleanup;

ec = straighten_document_with_prior_corners(image);
}
else if (strcmp(command, "cleanup_document") == 0) {
if (!mask_path) { print_usage(argv[0]); ec = SCANBOTSDK_ERROR_INVALID_ARGUMENT; goto cleanup; }

Expand Down
16 changes: 0 additions & 16 deletions examples/c/src/snippets/document/document_cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ scanbotsdk_error_code_t document_cleanup(
scanbotsdk_document_cleanup_configuration_t *configuration = NULL;
scanbotsdk_document_cleanup_t *cleanup = NULL;
scanbotsdk_document_cleanup_result_t *result = NULL;
scanbotsdk_document_cleanup_status_t status;
const char *status_str = NULL;

scanbotsdk_image_t *cleaned_image = NULL;
scanbotsdk_image_info_t *original_info = NULL;
Expand Down Expand Up @@ -43,20 +41,6 @@ scanbotsdk_error_code_t document_cleanup(
goto cleanup;
}

ec = scanbotsdk_document_cleanup_result_get_status(result, &status);
if (ec != SCANBOTSDK_OK) {
fprintf(stderr, "document_cleanup_result_get_status: %d: %s\n", ec, error_message(ec));
goto cleanup;
}

ec = scanbotsdk_document_cleanup_status_t_to_string(status, &status_str);
if (ec != SCANBOTSDK_OK) {
fprintf(stderr, "document_cleanup_status_t_to_string: %d: %s\n", ec, error_message(ec));
goto cleanup;
}

printf("Document cleanup status: %s\n", status_str);

ec = scanbotsdk_image_info(image, &original_info);
if (ec != SCANBOTSDK_OK) {
fprintf(stderr, "image_info(original): %d: %s\n", ec, error_message(ec));
Expand Down
7 changes: 4 additions & 3 deletions examples/c/src/snippets/document/document_straightener.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ scanbotsdk_error_code_t straighten_document(scanbotsdk_image_t *image) {
if (ec != SCANBOTSDK_OK) { fprintf(stderr, "aspect_ratio_create(3:4): %d: %s\n", ec, error_message(ec)); goto cleanup; }

ec = scanbotsdk_document_straightening_parameters_create(
0.03,
SCANBOTSDK_DOCUMENT_STRAIGHTENING_MODE_STRAIGHTEN,
aspect_ratios,
4,
SCANBOTSDK_PARTIALLY_VISIBLE_DOCUMENTS_HANDLING_MODE_INPAINTING,
false,
&straightening_params
);
if (ec != SCANBOTSDK_OK) { fprintf(stderr, "document_straightening_parameters_create: %d: %s\n", ec, error_message(ec)); goto cleanup; }
Expand All @@ -41,8 +44,6 @@ scanbotsdk_error_code_t straighten_document(scanbotsdk_image_t *image) {
straightener,
image,
straightening_params,
NULL,
0,
&result
);
if (ec != SCANBOTSDK_OK) { fprintf(stderr, "document_straighten: %d: %s\n", ec, error_message(ec)); goto cleanup; }
Expand All @@ -67,4 +68,4 @@ scanbotsdk_error_code_t straighten_document(scanbotsdk_image_t *image) {
scanbotsdk_aspect_ratio_free(aspect_ratios[3]);

return ec;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <stdio.h>
#include <stdlib.h>

#include <snippets/document/document_straightener_with_prior_corners.h>
#include <utils/utils.h>

scanbotsdk_error_code_t straighten_document_with_prior_corners(scanbotsdk_image_t *image) {
scanbotsdk_error_code_t ec = SCANBOTSDK_OK;

scanbotsdk_document_straightening_result_t *result = NULL;
scanbotsdk_document_straightening_parameters_t *straightening_params = NULL;
scanbotsdk_document_straightener_t *straightener = NULL;
scanbotsdk_image_t *straightened_image = NULL;

// Apriori known document corners, normalized to [0, 1] and given clockwise:
// top-left, top-right, bottom-right, bottom-left.
// Provide them only if known with high confidence (e.g. from a user interaction).
scanbotsdk_pointf_t prior_corners[4] = {
{0.05f, 0.05f},
{0.95f, 0.05f},
{0.95f, 0.95f},
{0.05f, 0.95f}
};

ec = scanbotsdk_document_straightening_parameters_create_with_defaults(&straightening_params);
if (ec != SCANBOTSDK_OK) { fprintf(stderr, "document_straightening_parameters_create_with_defaults: %d: %s\n", ec, error_message(ec)); goto cleanup; }

ec = scanbotsdk_document_straightener_create(&straightener);
if (ec != SCANBOTSDK_OK) { fprintf(stderr, "document_straightener_create: %d: %s\n", ec, error_message(ec)); goto cleanup; }

ec = scanbotsdk_document_straightener_run_with_prior_corners(
straightener,
image,
prior_corners,
4,
straightening_params,
&result
);
if (ec != SCANBOTSDK_OK) { fprintf(stderr, "document_straighten_with_prior_corners: %d: %s\n", ec, error_message(ec)); goto cleanup; }

ec = scanbotsdk_document_straightening_result_get_straightened_image(result, &straightened_image);
if (ec != SCANBOTSDK_OK) { fprintf(stderr, "document_straightening_result_get_straightened_image: %d: %s\n", ec, error_message(ec)); goto cleanup; }

if (straightened_image == NULL) {
fprintf(stderr, "No straightened image returned.\n");
}

/* straightened_image can be saved or processed further here */

cleanup:
scanbotsdk_document_straightener_free(straightener);
scanbotsdk_document_straightening_result_free(result);
scanbotsdk_document_straightening_parameters_free(straightening_params);

return ec;
}
3 changes: 2 additions & 1 deletion examples/c/src/utils/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void print_usage(const char *prog) {
printf(" medical_certificate | mrz | ocr | text_pattern | vin\n\n");

printf("Available enhance commands:\n");
printf(" straighten_document | cleanup_document\n\n");
printf(" straighten_document | straighten_document_with_prior_corners | cleanup_document\n\n");

printf("Available analyze commands:\n");
printf(" analyze_multi_page | crop_analyze\n\n");
Expand Down Expand Up @@ -132,6 +132,7 @@ void print_usage(const char *prog) {
printf(" %s analyze analyze_multi_page --file files/doc.pdf --license <KEY>\n", prog);
printf(" %s analyze crop_analyze --file images/doc.jpg --save out/crop.jpg --license <KEY>\n", prog);
printf(" %s enhance straighten_document --file images/doc.jpg --license <KEY>\n", prog);
printf(" %s enhance straighten_document_with_prior_corners --file images/doc.jpg --license <KEY>\n", prog);
printf(" %s enhance cleanup_document --file ../../test-scripts/test-images/highlighted.png --mask ../../test-scripts/test-images/highlighted_mask_001.png --save out/cleaned.jpg --license <KEY>\n", prog);
printf(" %s parse mrz --text \"P<UTOERIKSSON<<ANNA<MARIA<<<<<<\" --license <KEY>\n", prog);
printf(" %s live barcode --file images/example.jpg --license <KEY>\n", prog);
Expand Down
1 change: 1 addition & 0 deletions examples/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The example supports four commands: **scan**, **analyze**, **enhance**, and **pa
./gradlew run --args='analyze analyze_multi_page --resource files/doc.pdf --license <KEY>'
./gradlew run --args='analyze crop_analyze --file images/doc.jpg --save out/crop.jpg --license <KEY>'
./gradlew run --args='enhance straighten_document --file images/doc.jpg --license <KEY>'
./gradlew run --args='enhance straighten_document_with_prior_corners --file images/doc.jpg --license <KEY>'
./gradlew run --args='enhance cleanup_document --file ../../test-scripts/test-images/highlighted.png --mask ../../test-scripts/test-images/highlighted_mask_001.png --save out/cleaned.jpg --license <KEY>'
./gradlew run --args='parse mrz --text "P<UTOERIKSSON<<ANNA<MARIA<<<<<<" --license <KEY>'
```
Expand Down
2 changes: 1 addition & 1 deletion examples/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

// TODO Add your SCANBOTSDK_VERSION here.
def SCANBOTSDK_VERSION = "0.1000.4"
def SCANBOTSDK_VERSION = "0.1100.3"

def arch = System.getProperty("os.arch")
def SCANBOTSDK_ARCHITECTURE = (arch.contains("arm") || arch.contains("aarch64")) ? "aarch64" : "x86_64"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public static void main(String[] args) throws Exception {
DocumentStraightenerSnippet.run(image);
}
break;
case "straighten_document_with_prior_corners":
try (ImageRef image = Utils.createImageRef(file, resource)) {
DocumentStraightenerWithPriorCornersSnippet.run(image);
}
break;
case "cleanup_document":
if (mask == null && maskResource == null) { ExampleUsage.print(); return; }
DocumentCleanupSnippet.run(file, resource, mask, maskResource, save);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public static void run(
DocumentCleanup cleanup = new DocumentCleanup(image, new DocumentCleanupConfiguration());
DocumentCleanupResult result = cleanup.run(mask)
) {
System.out.println("Document cleanup status: " + result.getStatus());

ImageInfo originalInfo = image.imageInfo();
ImageInfo cleanedInfo = result.getImage().imageInfo();
System.out.printf("Original WxH: %dx%d%n", originalInfo.getWidth(), originalInfo.getHeight());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void run(ImageRef image) throws Exception {

try (
DocumentStraightener straightener = new DocumentStraightener();
DocumentStraighteningResult result = straightener.run(image, params, List.of())
DocumentStraighteningResult result = straightener.run(image, params)
) {
// The straightened image can be accessed via result.getStraightenedImage() and saved or further processed as needed.
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.scanbot.sdk.snippets.document;

import java.util.List;

import io.scanbot.sdk.documentscanner.DocumentStraightener;
import io.scanbot.sdk.documentscanner.DocumentStraighteningParameters;
import io.scanbot.sdk.documentscanner.DocumentStraighteningResult;
import io.scanbot.sdk.geometry.PointF;
import io.scanbot.sdk.image.ImageRef;

public class DocumentStraightenerWithPriorCornersSnippet {
public static void run(ImageRef image) throws Exception {
// Apriori known document corners, normalized to [0, 1] and given clockwise:
// top-left, top-right, bottom-right, bottom-left.
// Provide them only if known with high confidence (e.g. from a user interaction).
List<PointF> priorCorners = List.of(
new PointF(0.05f, 0.05f),
new PointF(0.95f, 0.05f),
new PointF(0.95f, 0.95f),
new PointF(0.05f, 0.95f)
);

try (
DocumentStraightener straightener = new DocumentStraightener();
DocumentStraighteningResult result = straightener.runWithPriorCorners(image, priorCorners, new DocumentStraighteningParameters())
) {
// The straightened image can be accessed via result.getStraightenedImage() and saved or further processed as needed.
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void print() {
System.out.println(" analyze_multi_page | crop_analyze");
System.out.println();
System.out.println("Available enhance commands:");
System.out.println(" straighten_document | cleanup_document");
System.out.println(" straighten_document | straighten_document_with_prior_corners | cleanup_document");
System.out.println();
System.out.println("Available parse commands:");
System.out.println(" mrz | barcode_doc");
Expand All @@ -41,6 +41,7 @@ public static void print() {
System.out.println(" ./gradlew run --args='analyze analyze_multi_page --resource files/doc.pdf --license <KEY>'");
System.out.println(" ./gradlew run --args='analyze crop_analyze --file images/doc.jpg --save out/crop.jpg --license <KEY>'");
System.out.println(" ./gradlew run --args='enhance straighten_document --file images/doc.jpg --license <KEY>'");
System.out.println(" ./gradlew run --args='enhance straighten_document_with_prior_corners --file images/doc.jpg --license <KEY>'");
System.out.println(" ./gradlew run --args='enhance cleanup_document --file ../../test-scripts/test-images/highlighted.png --mask ../../test-scripts/test-images/highlighted_mask_001.png --save out/cleaned.jpg --license <KEY>'");
System.out.println(" ./gradlew run --args='parse mrz --text \"P<UTOERIKSSON<<ANNA<MARIA<<<<<<\" --license <KEY>'");
System.out.println();
Expand Down
1 change: 1 addition & 0 deletions examples/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ npx ts-node src/index.ts scan barcode --file images/example.jpg --license <KEY>
npx ts-node src/index.ts analyze analyze_multi_page --file files/doc.pdf --license <KEY>
npx ts-node src/index.ts analyze crop_analyze --file images/doc.jpg --save out/crop.jpg --license <KEY>
npx ts-node src/index.ts enhance straighten_document --file images/doc.jpg --license <KEY>
npx ts-node src/index.ts enhance straighten_document_with_prior_corners --file images/doc.jpg --license <KEY>
npx ts-node src/index.ts enhance cleanup_document --file ../../test-scripts/test-images/highlighted.png --mask ../../test-scripts/test-images/highlighted_mask_001.png --save out/cleaned.jpg --license <KEY>
npx ts-node src/index.ts parse mrz --text "P<UTOERIKSSON<<ANNA<MARIA<<<<<<" --license <KEY>
```
Expand Down
8 changes: 4 additions & 4 deletions examples/nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"typescript": "^5.9.2"
},
"dependencies": {
"scanbotsdk": "https://github.com/doo/scanbot-sdk-example-linux/releases/download/standalone-sdk%2Fv0.1000.4/nodejs-scanbotsdk-0.1000.4.tgz"
"scanbotsdk": "https://github.com/doo/scanbot-sdk-example-linux/releases/download/standalone-sdk%2Fv0.1100.3/nodejs-scanbotsdk-0.1100.3.tgz"
}
}
6 changes: 6 additions & 0 deletions examples/nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { AnalyzeMultiPageSnippet } from "./snippets/document/analyze-multipage";
import { CropAndAnalyzeSnippet } from "./snippets/document/crop-analyze";
import { DocumentCleanupSnippet } from "./snippets/document/document-cleanup";
import { DocumentStraightenerSnippet } from "./snippets/document/document-straightener";
import { DocumentStraightenerWithPriorCornersSnippet } from "./snippets/document/document-straightener-with-prior-corners";

async function awaitPromise(promise: Promise<void>, maxAwaitTimeMs: number = 60 * 1000): Promise<void> {
const timer = setTimeout(() => {
Expand Down Expand Up @@ -105,6 +106,11 @@ async function main(): Promise<void> {
await DocumentStraightenerSnippet.run(image);
break;
}
case "straighten_document_with_prior_corners": {
const image = await ScanbotSDK.ImageRef.fromPath(file);
await DocumentStraightenerWithPriorCornersSnippet.run(image);
break;
}
case "cleanup_document":
if (!mask) { printUsage(); return; }
await DocumentCleanupSnippet.run(file, mask, save);
Expand Down
2 changes: 0 additions & 2 deletions examples/nodejs/src/snippets/document/document-cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export class DocumentCleanupSnippet {
);
await using result = await cleanup.run(mask);

console.log("Document cleanup status: " + result.status);

const originalInfo = await image.imageInfo();
const cleanedInfo = await result.image.imageInfo();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as ScanbotSDK from "scanbotsdk";

export class DocumentStraightenerWithPriorCornersSnippet {
public static async run(image: ScanbotSDK.ImageRef): Promise<void> {
// Apriori known document corners, normalized to [0, 1] and given clockwise:
// top-left, top-right, bottom-right, bottom-left.
// Provide them only if known with high confidence (e.g. from a user interaction).
const priorCorners = [
{ x: 0.05, y: 0.05 },
{ x: 0.95, y: 0.05 },
{ x: 0.95, y: 0.95 },
{ x: 0.05, y: 0.95 }
];

await using straightener = await ScanbotSDK.DocumentStraightener.create();
await using result = await straightener.runWithPriorCorners(
image,
priorCorners,
new ScanbotSDK.DocumentStraighteningParameters()
);

// The straightened image can be accessed via result.straightenedImage and saved or further processed as needed.
}
}
3 changes: 2 additions & 1 deletion examples/nodejs/src/snippets/utils/example-usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Usage:
Categories & subcommands:
scan <barcode | document | check | credit_card | document_data_extractor | medical_certificate | mrz | ocr | text_pattern | vin>
analyze <analyze_multi_page | crop_analyze>
enhance <straighten_document | cleanup_document>
enhance <straighten_document | straighten_document_with_prior_corners | cleanup_document>
parse <mrz | barcode_doc>

Flags:
Expand All @@ -23,6 +23,7 @@ Examples:
npx ts-node src/index.ts analyze analyze_multi_page --file files/doc.pdf --license <KEY>
npx ts-node src/index.ts analyze crop_analyze --file images/doc.jpg --save out/crop.jpg --license <KEY>
npx ts-node src/index.ts enhance straighten_document --file images/doc.jpg --license <KEY>
npx ts-node src/index.ts enhance straighten_document_with_prior_corners --file images/doc.jpg --license <KEY>
npx ts-node src/index.ts enhance cleanup_document --file ../../test-scripts/test-images/highlighted.png --mask ../../test-scripts/test-images/highlighted_mask_001.png --save out/cleaned.jpg --license <KEY>
npx ts-node src/index.ts parse mrz --text "P<UTOERIKSSON<<ANNA<MARIA<<<<<<" --license <KEY>
`);
Expand Down
Loading
Loading