vision-camera-ocr icon indicating copy to clipboard operation
vision-camera-ocr copied to clipboard

Cannot recognise texts when the orientation is not portrait

Open hikmert opened this issue 2 years ago • 3 comments

I've installed the plugin correctly and it works pretty well if the orientation of the device is 'portrait'. However, when I either turn the text or device, it doesn't recognise the texts. Although I played a bit with the orientation property of the camera, no improvements achieved so far. When I looked into the pod of VisionCameraOCR, I came across with a todo as: ` @objc public static func callback(_ frame: Frame!, withArgs _: [Any]!) -> Any! {

    guard (CMSampleBufferGetImageBuffer(frame.buffer) != nil) else {
      print("Failed to get image buffer from sample buffer.")
      return nil
    }

    let visionImage = VisionImage(buffer: frame.buffer)
    
    // TODO: Get camera orientation state
    visionImage.orientation = .up`

I'd highly appreciate any advices or hints. Thanks in advance!

hikmert avatar May 11 '22 08:05 hikmert

I find out that by modifying this line for Android :

 val image = InputImage.fromMediaImage(mediaImage, frame.imageInfo.rotationDegrees) // frame.imageInfo.rotationDegrees = 90 

To :

 val image = InputImage.fromMediaImage(mediaImage, 0)  // or 180

The OCR can recognize text vertically. I haven’t been able to test but I think it's the same for iOS, if you change .up to .left or .right it should work. As mentioned in the documentation : https://developers.google.com/ml-kit/vision/text-recognition/ios

I am also looking forward to changing the orientation by passing a param. I don't know if that's something that could be added to this package.

romancxx avatar May 17 '22 05:05 romancxx

Hey @Nazort, thanks for your reply.

I'm working on iOS at the moment, so as a workaround I removed the lines ` // TODO: Get camera orientation state visionImage.orientation = .up`` and I passed the orientation of the device through listening to the device acceloremeter.

hikmert avatar May 23 '22 08:05 hikmert

Hey @Nazort, thanks for your reply.

I'm working on iOS at the moment, so as a workaround I removed the lines ` // TODO: Get camera orientation state visionImage.orientation = .up`` and I passed the orientation of the device through listening to the device acceloremeter.

Hi, can you share the code? I'm having the issue, almost 2 years later

tomerh2001 avatar Feb 14 '24 13:02 tomerh2001