RED-7669: optimize OCR-module performance
* moar sigsegv
This commit is contained in:
parent
2632d2023d
commit
19747cbca5
@ -1,5 +1,6 @@
|
|||||||
package com.knecon.fforesight.service.ocr.processor.service.threads;
|
package com.knecon.fforesight.service.ocr.processor.service.threads;
|
||||||
|
|
||||||
|
import static com.knecon.fforesight.service.ocr.processor.utils.NativeMemoryAllocationUtils.getDetectionScriptBuffers;
|
||||||
import static net.sourceforge.tess4j.ITessAPI.TRUE;
|
import static net.sourceforge.tess4j.ITessAPI.TRUE;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -15,6 +16,7 @@ import com.knecon.fforesight.service.ocr.processor.model.OcrImage;
|
|||||||
import com.knecon.fforesight.service.ocr.processor.model.OcrResult;
|
import com.knecon.fforesight.service.ocr.processor.model.OcrResult;
|
||||||
import com.knecon.fforesight.service.ocr.processor.service.OcrProgressLogger;
|
import com.knecon.fforesight.service.ocr.processor.service.OcrProgressLogger;
|
||||||
import com.knecon.fforesight.service.ocr.processor.service.Statistics;
|
import com.knecon.fforesight.service.ocr.processor.service.Statistics;
|
||||||
|
import com.knecon.fforesight.service.ocr.processor.utils.NativeMemoryAllocationUtils;
|
||||||
import com.knecon.fforesight.service.ocr.processor.utils.Tesseract2;
|
import com.knecon.fforesight.service.ocr.processor.utils.Tesseract2;
|
||||||
import com.sun.jna.ptr.PointerByReference;
|
import com.sun.jna.ptr.PointerByReference;
|
||||||
|
|
||||||
@ -128,21 +130,15 @@ public class OCRThread extends Thread {
|
|||||||
TessAPI1.TessBaseAPISetImage2(detectionScriptHandle, image.getPix());
|
TessAPI1.TessBaseAPISetImage2(detectionScriptHandle, image.getPix());
|
||||||
TessAPI1.TessBaseAPISetSourceResolution(detectionScriptHandle, image.getDpi());
|
TessAPI1.TessBaseAPISetSourceResolution(detectionScriptHandle, image.getDpi());
|
||||||
|
|
||||||
synchronized (OCRThread.class) { // must synchronize the mallocs here with the mallocs in leptonica binarization.
|
|
||||||
orientationDegreeResultBuffer = IntBuffer.allocate(1);
|
|
||||||
orientationDegreeConfidenceBuffer = FloatBuffer.allocate(1);
|
|
||||||
scriptureNameBuffer = new PointerByReference();
|
|
||||||
scriptureConfidenceBuffer = FloatBuffer.allocate(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int orient_deg = 0;
|
int orient_deg = 0;
|
||||||
int result = TessAPI1.TessBaseAPIDetectOrientationScript(detectionScriptHandle,
|
int result = TessAPI1.TessBaseAPIDetectOrientationScript(detectionScriptHandle,
|
||||||
orientationDegreeResultBuffer,
|
buffers.orient_degB(),
|
||||||
orientationDegreeConfidenceBuffer,
|
buffers.orient_confB(),
|
||||||
scriptureNameBuffer,
|
buffers.script_nameB(),
|
||||||
scriptureConfidenceBuffer);
|
buffers.script_confB());
|
||||||
if (result == TRUE) {
|
if (result == TRUE) {
|
||||||
orient_deg = orientationDegreeResultBuffer.get();
|
orient_deg = buffers.orient_degB().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (OCRThread.class) {
|
synchronized (OCRThread.class) {
|
||||||
|
|||||||
@ -0,0 +1,28 @@
|
|||||||
|
package com.knecon.fforesight.service.ocr.processor.utils;
|
||||||
|
|
||||||
|
import java.nio.FloatBuffer;
|
||||||
|
import java.nio.IntBuffer;
|
||||||
|
|
||||||
|
import com.knecon.fforesight.service.ocr.processor.service.threads.OCRThread;
|
||||||
|
import com.sun.jna.ptr.PointerByReference;
|
||||||
|
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
|
@UtilityClass
|
||||||
|
public class NativeMemoryAllocationUtils {
|
||||||
|
|
||||||
|
synchronized public static DetectionScriptBuffers getDetectionScriptBuffers() {
|
||||||
|
|
||||||
|
IntBuffer orient_degB = IntBuffer.allocate(1);
|
||||||
|
FloatBuffer orient_confB = FloatBuffer.allocate(1);
|
||||||
|
PointerByReference script_nameB = new PointerByReference();
|
||||||
|
FloatBuffer script_confB = FloatBuffer.allocate(1);
|
||||||
|
DetectionScriptBuffers buffers = new DetectionScriptBuffers(orient_degB, orient_confB, script_nameB, script_confB);
|
||||||
|
return buffers;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public record DetectionScriptBuffers(IntBuffer orient_degB, FloatBuffer orient_confB, PointerByReference script_nameB, FloatBuffer script_confB) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user