Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

321
Views
Crop CMSampleBuffer

I'm using Firebase ML Kit to recognise text that's visible within a small window. But I want to make it more efficient, helping it to not analyse unnecessary data. So I would like to crop the image being sent to the model.

Firebase ML is taking a VisionImage which takes a CMSampleBuffer. The only part of the image I would need is the same width, but is only about 100px high, like the blue part here:

Image showing the used part of the image captured

I haven't found a good way to do this yet, or is it better to take the image from the preview that is shown to the user and then convert it back?

I'm thinking that this should be done inside the captureOutput function from the AVCaptureVideoDataOutputSampleBufferDelegate. My function looks like this today:

func captureOutput(
    _ output: AVCaptureOutput,
    didOutput sampleBuffer: CMSampleBuffer,
    from connection: AVCaptureConnection
    ) {

    DispatchQueue.main.async {
        self.updatePreviewOverlayView()
    }

    guard let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return }
    self.lastFrame = sampleBuffer
    let visionImage = VisionImage(buffer: sampleBuffer)
    let metadata = VisionImageMetadata()
    let visionOrientation = VisionDetectorImageOrientation.rightTop
    metadata.orientation = visionOrientation
    visionImage.metadata = metadata
    let imageWidth = CGFloat(CVPixelBufferGetWidth(imageBuffer))
    let imageHeight = CGFloat(CVPixelBufferGetHeight(imageBuffer))
    self.recognizeTextOnDevice(in: visionImage, width: imageWidth, height: imageHeight)
}
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!