Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
anonym24 opened this issue Jan 31, 2018 · 3 comments

Comments

@anonym24
Copy link

anonym24 commented Jan 31, 2018

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

@anonym24
Copy link
Author

anonym24 commented Jan 31, 2018

even simple UIImage to OCVMat won't work!

        let image = UIImage(named: "myImage")
        let mat = OCVMat(image: image!)

opencv(1984,0x1b355cb80) malloc: *** error for object 0x16ed112d8: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
(lldb)

@anonym24 anonym24 changed the title Error when creating OCVMat from CVPixelBuffer Error when creating OCVMat from CVPixelBuffer (or from any other format) Jan 31, 2018
@anonym24 anonym24 changed the title Error when creating OCVMat from CVPixelBuffer (or from any other format) Error when creating OCVMat from CVPixelBuffer (or from any other supported format - UIImage,..) Jan 31, 2018
@anonym24
Copy link
Author

anonym24 commented Mar 3, 2018

I commented

- (void)dealloc {
    if (source) {
        free(source);
    }
    
    source = NULL;
}

but another issue with

- (cv::Mat *)source {
    return source;
}

it returns mat with incorrect size, for example initially it was 400x400px than it becomes 1x1498465

madhavajay added a commit to madhavajay/LegoCV that referenced this issue Apr 12, 2019
@yjjwxq
Copy link

yjjwxq commented Dec 27, 2019

I have the same problem, but I don't know how to solve it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants