2

I have had an OCR app on the MacOS App Store using Vision API's VNRecognizeTextRequest. It works fine on this very long image in Catalina. But on Big Sur, it gives garbage output. I have been able to reproduce it with the below code which is very simple Apple's example code without my app's logic.

I tested with a cropped version of the image and it works fine at 822 × 4080 pixels but it fails at my original 822 × 4564 size. Even the cropped smaller 822 × 4080 image sometimes fails and gives garbage output. But much smaller images always work.

Both the large and smaller images always work fine on Catalina.

I have attached the cropped and original images at the bottom.

Simple demo code to reproduce:

let request = VNRecognizeTextRequest { request, error in
            if let observations = request.results as? [VNRecognizedTextObservation] {
                for observation in observations {
                    guard let bestCandidate = observation.topCandidates(1).first  else {
                        continue
                    }
                    print(bestCandidate.string)
                }
            }
        }
                    
        request.progressHandler = {(request, value, error) in
            print(value)
        }
        
        
        request.recognitionLevel = .accurate
        
        let handler = VNImageRequestHandler(cgImage: (NSImage(named: "test5.png")?.cgImage(forProposedRect: nil, context: nil, hints: nil))!, options: [:])
        try? handler.perform([request])
    

The garbage output looks like random characters:

Fis
g
6
g
M a
t
3
0
- 
s
g
2
v
c
g
g
0 EG
M
m?
Fel
F
g
ho:
D
o
19
D.
_
of
O
bo
2 x l un g2@ 4
D
5
g
2
d
T
b
o
    

Original (garbage output):

enter image description here

Cropped (works):

enter image description here

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220

0 Answers0