Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

320
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda