【问题标题】:OpenCV StereoSGBM mat output array bad access in XcodeXcode中的OpenCV StereoSGBM mat输出数组访问错误
【发布时间】:2023-03-12 12:21:01
【问题描述】:

尝试在 xcode 中创建视差图,但在运行 stereosgbm.compute 时不断获得 exc 错误访问,并且无法找出原因。该函数的输出数组是一个垫子,但我不知道如何初始化它以使其工作。

代码如下:

#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

【问题讨论】:

    标签: objective-c xcode opencv


    【解决方案1】:

    知道了!我初始化 StereoBM 错误。正确的做法是:

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

    【讨论】:

      猜你喜欢
      • 2012-11-12
      • 1970-01-01
      • 1970-01-01
      • 2013-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-04
      相关资源
      最近更新 更多