Skip to content

Error when creating OCVMat from CVPixelBuffer (or from any other supported format - UIImage,..) #8

@anonym24

Description

@anonym24

more: https://stackoverflow.com/questions/48540004/converting-cvpixelbuffer-to-mat-opencv

opencv(1934,0x16f087000) malloc: *** error for object 0x16f086108: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

my Swift code:

fileprivate func configureVideoOutput() {
    let videoOutput = AVCaptureVideoDataOutput()
    videoOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "sample buffer"))

    if self.session.canAddOutput(videoOutput) {
        print("canAddOutput yes")
        self.session.addOutput(videoOutput)
        print("canAddOutput yes added")
    } else {
        print("canAddOutput no")
    }
}

private func matFromSampleBuffer(sampleBuffer: CMSampleBuffer) -> OCVMat? {
    guard let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return nil }
    return OCVMat(pixelBuffer: imageBuffer)
}

public func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
    count = count + 1
    print("Got a frame # \(count)")
    guard let mat = matFromSampleBuffer(sampleBuffer: sampleBuffer) else { return }
}

screenshot at jan 31 12-10-05

https://github.com/Legoless/LegoCV/blob/master/LegoCV/LegoCV/Wrapper/Core/Mat/OCVMatDataAllocator.mm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions