2016-08-18 180 views
0

试图在xcode中创建视差图,但在运行stereosgbm.compute时不断获得不良访问权限,但无法找出原因。该函数的输出数组是一个垫子,但我不知道如何初始化它以使其工作。OpenCV StereoSGBM mat输出阵列在Xcode中的访问不良

这里是代码:

#import <Foundation/Foundation.h> 
#import "DisparityGenerator.h" 
#import "AppDelegate.h" 




@implementation DisparityGenerator 

AppDelegate *appDelDG; 
cv::Mat matImageR; 
cv::Mat matImageL; 


+ (UIImage*) dispGen:(int)image{ 

    appDelDG = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 

    UIImage* result = nil; 
    // convert the photo the camera took to MAT 

    if(image == 0){ 

     UIImage *R = [UIImage imageNamed:@"im6"]; 
     UIImageToMat(R, matImageR); 

     UIImage *L = [UIImage imageNamed:@"im2"]; 
     UIImageToMat(L, matImageL); 

    }else{ 

     UIImage *R = [UIImage imageNamed:@"im6a"]; 
     UIImageToMat(R, matImageR); 

     UIImage *L = [UIImage imageNamed:@"im2a"]; 
     UIImageToMat(L, matImageL); 

    } 

    cv::Mat dispArray;; 

// dispArray.create(<#int _rows#>, <#int _cols#>, int _type) 

    cv::cvtColor(matImageL, matImageL, cv::COLOR_BGR2GRAY); 
    cv::cvtColor(matImageR, matImageR, cv::COLOR_BGR2GRAY); 

    cv::StereoSGBM *imbm = cv::StereoSGBM::create(6, 6, 6); 
     //cv::StereoBM::create(16, 2); 

    imbm->compute(matImageL,matImageR,dispArray); 

    result = MatToUIImage(dispArray); 

    return result; 


} 



@end 

回答

0

明白了!我初始化了StereoBM错误。正确的方法是:

cv::Ptr <cv::StereoBM> imbm = cv::StereoBM::create(0);