Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

322
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda