Skip to content
This repository was archived by the owner on Sep 25, 2023. It is now read-only.
This repository was archived by the owner on Sep 25, 2023. It is now read-only.

Vision framework compatibility #16

@flaushi

Description

@flaushi

I am using the Vision framework but the program crashes as soon as I access the pixelBuffer property of the result observation. This is my code:

    VNCoreMLModel * model = [VNCoreMLModel modelForMLModel:fns.model  error:&error];
    VNCoreMLRequest * request = [[VNCoreMLRequest alloc] initWithModel:model completionHandler:^(VNRequest * _Nonnull request, NSError * _Nullable error) {
            if(error) {
                NSLog(@"completionHandler Error %@", error);
                return;
            }
            for (VNObservation * observation in request.results){
                if(observation.class == [VNPixelBufferObservation class]){
                    VNPixelBufferObservation * pxbufobs = (VNPixelBufferObservation*)observation;
                    
                      
                    CIImage *ciImage = [CIImage imageWithCVPixelBuffer:pxbufobs.pixelBuffer]; // <<---EXC_BAD_ACCESS here!!!
                    
                    CIContext *temporaryContext = [CIContext contextWithOptions:nil];
                    CGImageRef videoImage = [temporaryContext
                                             createCGImage:ciImage
                                             fromRect:CGRectMake(0, 0,
                                                                 CVPixelBufferGetWidth(pxbufobs.pixelBuffer),
                                                                 CVPixelBufferGetHeight(pxbufobs.pixelBuffer))];
                    
                    // resulting UIImage
                    UIImage * image = [UIImage imageWithCGImage:videoImage];
                    CGImageRelease(videoImage);
                }
                    
            }
        }];

The fns is a .mlmodel converted with this project and dragged into my xcode project.

Interestingly, the models offered here do not work in xcode 9.1. It complains about the missing header file (although it is there). So, I was not able to test with mlmodels from alternative sources.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions