Skip to content

Commit

Permalink
Merge pull request #18 from pepperav/fix_memory_leak
Browse files Browse the repository at this point in the history
Removed UIImage usage creating a VisionImage instance by frame buffer
  • Loading branch information
ismaelsousa authored Jul 31, 2024
2 parents 4fc7ae6 + f1f60b9 commit 270d553
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions ios/VisionCameraOcr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,33 +122,19 @@ public class OCRFrameProcessorPlugin: FrameProcessorPlugin {

public override func callback(_ frame: Frame, withArguments arguments: [AnyHashable: Any]?) -> Any? {

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

let ciImage = CIImage(cvPixelBuffer: imageBuffer)

guard let cgImage = CIContext().createCGImage(ciImage, from: ciImage.extent) else {
print("Failed to create bitmap from image.")
return nil
}

let image = UIImage(cgImage: cgImage)

let visionImage = VisionImage(image: image)
let visionImage = VisionImage(buffer: frame.buffer)

// Set the orientation of visionImage to the opposite of the frame's orientation
// Opposite compare to the `up` orientation
switch frame.orientation {
case .left:
visionImage.orientation = .right
case .right:
visionImage.orientation = .left
case .up, .down:
fallthrough

default: visionImage.orientation = frame.orientation
case .left:
visionImage.orientation = .right
case .right:
visionImage.orientation = .left
case .up, .down:
fallthrough
default: visionImage.orientation = frame.orientation
}

var result: Text
Expand Down

0 comments on commit 270d553

Please sign in to comment.