2016-08-18 52 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);