thermography image issue

85 views
Skip to first unread message

vizier87

unread,
Jul 14, 2024, 2:13:38 AM (13 days ago) Jul 14
to tesseract-ocr
Hi everyone, I need some help with the flow of the Tesseract pre-procesing.

Here's a thermography image I'm attempting to detect:
6.png


the code I'm using in .NET is the following:
    Try

        ' Load the image using OpenCvSharp
        Dim src As Mat = Cv2.ImRead(imagePath, ImreadModes.Grayscale)


        ' Apply preprocessing steps
        Dim processedImage As New Mat()
        Cv2.Resize(src, processedImage, New Size(src.Width * size, src.Height * size)) ' Resize to double the size

        Cv2.Threshold(processedImage, processedImage, threshold, maxval, ThresholdTypes.Otsu) ' Apply thresholding

        ' Save the preprocessed image to a temporary file on the desktop
        Dim desktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
        Dim tempImagePath As String = System.IO.Path.Combine(desktopPath, "temp_image.png")
        Cv2.ImWrite(tempImagePath, processedImage)



        Using engine As New TesseractEngine("C:\Program Files\Tesseract-OCR\tessdata", "eng", EngineMode.Default)
            ' Load the preprocessed image
            Using img As Pix = Pix.LoadFromFile(tempImagePath)
                ' Perform OCR
                Using page As Page = engine.Process(img)
                    ' Get the recognized text
                    Dim recognizedText As String = page.GetText()
                    Return recognizedText
                End Using
            End Using
        End Using






    Catch ex As Exception
        Return "Error performing OCR: " & ex.Message
    End Try
End Function


admittedly, this was done with the help of a particular AI, but I've been tuning it in all the places (size, threshold and maxval) and still got nothing.

Quite sure the flow is incorrect. Can anyone suggest any additional pre-processing?

Thanks.


vizier87

unread,
Jul 14, 2024, 11:39:21 PM (13 days ago) Jul 14
to tesseract-ocr
Anyone?

Thanks!

René JM Clais

unread,
Jul 15, 2024, 8:29:38 AM (12 days ago) Jul 15
to tesser...@googlegroups.com
If you have a python knowledge I can help. 

--
You received this message because you are subscribed to the Google Groups "tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tesseract-oc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tesseract-ocr/98b7b7c2-a80d-4b66-98d9-d8bea769856bn%40googlegroups.com.

vizier87

unread,
Jul 16, 2024, 2:41:43 AM (11 days ago) Jul 16
to tesseract-ocr
Yeah my python is rusty but I do have experience with it. What do you suggest I begin with?

René JM Clais

unread,
Jul 16, 2024, 8:10:56 AM (11 days ago) Jul 16
to tesser...@googlegroups.com
Are you a windows user ? If yes do you install tesseract from Mannheim ?
Do you install a language for tesseract  (example eng   for english) ?
Can you install opencv and pytesseract     python packages ? 
If yes I can send you a sample to try.
Afterwards we will discuss your case in detail.

Rgs 

René

vizier87

unread,
Jul 19, 2024, 3:22:37 AM (8 days ago) Jul 19
to tesseract-ocr
Here's the tesseract installed for quite some time ago:

>tesseract --version
tesseract v5.3.3.20231005
 leptonica-1.83.1
  libgif 5.2.1 : libjpeg 8d (libjpeg-turbo 2.1.4) : libpng 1.6.40 : libtiff 4.6.0 : zlib 1.2.13 : libwebp 1.3.2 : libopenjp2 2.5.0
 Found AVX
 Found SSE4.1
 Found libarchive 3.7.2 zlib/1.3 liblzma/5.4.4 bz2lib/1.0.8 liblz4/1.9.4 libzstd/1.5.5
 Found libcurl/8.3.0 Schannel zlib/1.3 brotli/1.1.0 zstd/1.5.5 libidn2/2.3.4 libpsl/0.21.2 (+libidn2/2.3.3) libssh2/1.11.0

I'm currently setting up on OpenCV and pytesseract. I do have experience in OpenCV though. I'll let you know once ready.

Thanks.

Tom Morris

unread,
Jul 19, 2024, 1:00:20 PM (8 days ago) Jul 19
to tesseract-ocr
It's going to be hard to solve a problem that you don't understand, but to start with you almost certainly don't want to be using Otsu thresholding. I would threshold precisely on the white that is used in the digits (assuming those are what you're trying to detect).

Do you want just the average temp? If so, and it's in a fixed location, that should simplify the problem.

If you want the SP1 & SP2 temps and they can be in variable places, that's going to be a little trickier and the first thing you probably want to do is to locate the registration marks and the text in the image.

Tom

vizier87

unread,
Jul 20, 2024, 2:13:08 AM (7 days ago) Jul 20
to tesseract-ocr
Hi Tom.

The position of text in thermography images are usually arbitrary. The code I used for Otsu worked for some images, but not this. Seems like I will have to optimize it. I need to be able to extract SP1, SP2 and Average only.

I actually just need the numericals.

My usual MO during the times I use OpenCV would be just a binary thresholding but it wasn't for text detection back then.

I wish I could share more images; I'm on mobile right now. You might me able to see what I mean better.

Vizier87

Lorenzo Blz

unread,
Jul 20, 2024, 8:29:15 AM (7 days ago) Jul 20
to tesseract-ocr
Hi,
it seems like the text has a fixed color with few shades all with low saturation.

Drop everything with high saturation and different shades (working in HSV or Lab) by setting it to black. 

Something like:

img[sat > 10] = [0,0,0]

img[hue > x or hue < y] = [0,0,0]


Open/close to remove "dust", you should have something to work on.

Do not upscale the image because this will add new shades.

If you have control over the image generation, choosing the font size/color of course may help.


Bye,

Lorenzo
Reply all
Reply to author
Forward
0 new messages