cuda :: reprojectImageTo3D和OpenCV 3.0的奇怪错误

时间:2015-07-23 22:49:58

标签: c++ qt opencv

您好我正在尝试从我已经使用cuda :: StereoBM对象生成的视差图中获取带有XYZ的Matden,这是我创建的视差图的屏幕截图"disparity map" 但是当我添加函数cuda :: reprojectImageTo3D(d_disp,d_xyz,d_Q,3,Stream)时;我得到一个我无法理解的错误,如果我对这行代码进行修改没有显示错误,但是当我尝试使用此函数时,我得到下一个error window

,错误代码为:

OpenCV Error: The function/feature is not implemented (You should explicitly call download method for cuda::GpuMat object) in cv::_InputArray::getMat_, file C:\opencv\sources\modules\core\src\matrix.cpp, line 1211

bellow是我的代码,请注意我的大部分Mats都被声明为全局,因此它们的声明不在此插槽函数中

void MainWindow::on_botonMostrarDispSGBMCUDA_clicked()
{

    if(map_l1.empty()&&map_l2.empty()&&map_r1.empty() &&map_r2.empty()){
        FileStorage fs(xmlname,FileStorage::READ);
        fs["map_l1"]>>map_l1;
        fs["map_l2"]>>map_l2;
        fs["map_r1"]>>map_r1;
        fs["map_r2"]>>map_r2;
        fs["Q"] >> Q;
        fs.release();
    }
    Mat img1, img2;
    img1 = imread("C:\\Users\\Diego\\Pictures\\calibstereo\\camleft\\photoleft_1.jpg");
    img2 = imread("C:\\Users\\Diego\\Pictures\\calibstereo\\camright\\photoright_1.jpg");


    cvtColor(img1, frameLGray, CV_BGR2GRAY);
    cvtColor(img2, frameRGray, CV_BGR2GRAY);
    remap(frameLGray,framel_rect,map_l1,map_l2,INTER_LINEAR);
    remap(frameRGray,framer_rect,map_r1,map_r2,INTER_LINEAR);

    bool ok1, ok2, ok3, ok4, ok5, ok6 , ok7,ok8,ok9,ok10 ;
    int preFilterSize = ui->editPrefilterSizeBM->text().toInt(&ok1);
    int prefilterCap = ui->editFilterCapBM->text().toInt(&ok2);
    int blockSize = ui->editBlockSBM->text().toInt(&ok3);
    int minDisp = ui->editMinDispBM->text().toInt(&ok4);
    int numDisp = ui->editNumDispBM->text().toInt(&ok5);
    int texturethresh = ui->editTextureBM->text().toInt(&ok6);
    int uniqueness = ui->editUniquenesBM->text().toInt(&ok7);
    int speckleWindow = ui->editSpeckleWindowBM->text().toInt(&ok8);
    int speckleRange = ui->editSpeckleRangeBM->text().toInt(&ok9);
    int maxDiff = ui->editMaxDiffBM->text().toInt(&ok10);

    if (!ok1 || !ok2 || !ok3 || !ok4 || !ok5 || !ok6 || !ok7 || !ok8 || !ok9 || !ok10){
        QMessageBox messageBox;
        messageBox.setIconPixmap(QPixmap(":/icon.svg"));
        messageBox.setText("One of your entries is not a valid number.");
        messageBox.setWindowTitle("Error");
        messageBox.exec();
     }


    d_left.upload(framel_rect);
    d_right.upload(framer_rect);
    Ptr<cuda::StereoBM> CUSBM;
    CUSBM = cuda::createStereoBM(64, 5);
    CUSBM->setPreFilterSize(preFilterSize);             
    CUSBM->setPreFilterCap(prefilterCap);               
    CUSBM->setBlockSize(blockSize);                     
    CUSBM->setMinDisparity(minDisp);                    
    CUSBM->setNumDisparities(numDisp);                  
    CUSBM->setTextureThreshold(texturethresh);          
    CUSBM->setUniquenessRatio(uniqueness);              
    CUSBM->setSpeckleWindowSize(speckleWindow);         
    CUSBM->setSpeckleRange(speckleRange);               
    CUSBM->setDisp12MaxDiff(maxDiff);                   
    cuda::Stream myStream = cuda::Stream::Stream();
    CUSBM->compute(d_left, d_right, d_disp, myStream);
    if(!d_disp.empty()){
        cuda::GpuMat d_xyz(d_disp.size(), CV_32FC4);
        cuda::GpuMat d_Q(4,4,CV_32F);
        d_Q.upload(Q);
        cuda::Stream mySecondStream = cuda::Stream::Stream();
        cuda::reprojectImageTo3D(d_disp,d_xyz,d_Q,3,mySecondStream);
        d_xyz.download(xyz);
    }

    cuda::drawColorDisp(d_disp, d_disp,numDisp);        //64

    d_disp.download(disp);

    namedWindow("left");
    namedWindow("right");
    namedWindow("disp");

    imshow("left", framel_rect);
    imshow("right", framer_rect);
    imshow("disp", disp);
    //imshow("xyz", xyz);
    waitKey(0);
    cv::destroyAllWindows();
}

我使用Windows 8.1,QtCreator作为我的IDE,OpenCV 3.0.0使用cuda 7.0

3 个答案:

答案 0 :(得分:0)

您确定d_dispcuda::reprojectImageTo3D(d_disp,d_xyz,d_Q,3,mySecondStream);GpuMat

吗?

您的问题可能来自cv::Mat类,它没有重载的赋值运算符或带有cv::gpu::GpuMat类型参数的复制构造函数,因此您无法在代码中混合它们。

答案 1 :(得分:0)

我从 cudastereo / src / util.cpp 检查了该函数的参数列表。

该函数似乎将d_dispd_xyz作为cuda::GpuMat,但Q矩阵需要为cv::Mat

cuda::reprojectImageTo3D(d_disp,d_xyz,Q,3,mySecondStream);似乎工作正常。

对不起,迟到了。

答案 2 :(得分:0)

问题在于cuda::drawColorDisp(d_disp, d_disp,numDisp); //64。您提供的是相同的源和目标GpuMat文件,不应该是。您可能希望查看drawColorDisp的详细构造函数参数{。{3}}。