aarongrider / vision-camera-ocr

VisionCamera Frame Processor Plugin to detect text in real time using MLKit Text Detector (OCR)
MIT License
235 stars 86 forks source link

Cannot recognise texts when the orientation is not portrait #5

Open hikmert opened 2 years ago

hikmert commented 2 years ago

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!

romancxx commented 2 years ago

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.

hikmert commented 2 years ago

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.

tomerh2001 commented 4 months ago

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