4

我正在尝试在 Qt 中使用 OpenCV 实现双边过滤器。到目前为止,我已经这样做了:

void MainWindow::on_actionOpen_triggered() {
    QString fileName =
      QFileDialog::getOpenFileName(this, tr("Open Image"), ".",
                                   tr("Image Files (*.png *.jpg *.jpeg *.bmp)"));
    image = cv::imread(fileName.toAscii().data());
    emit qtimage();
}

哪里image是类型cv::Mat。我的过滤功能是:

cv::bilateralFilter(image, image, 0, 21, 3, 0);
QImage img = QImage((const unsigned char*)(image.data), 
                   image.cols,image.rows, QImage::Format_RGB888);
QPalette palette;
palette.setBrush(this->backgroundRole(), QBrush(img));
                 this->setPalette(palette);

但它给出了一个运行时错误:

OpenCV Error: Assertion failed ((src.type() == CV_8UC1 || src.type() == CV_8UC3) && src.type() == dst.type() && src.size() == dst.size() && src.data != dst.data)
    in bilateralFilter_8u, file C:\Downloads\Software\OpenCV-2.2.0-win\OpenCV-2.2.0\modules\imgproc\src\smooth.cpp, line 1282
terminate called after throwing an instance of 'cv::Exception'
what():  C:\Downloads\Software\OpenCV-2.2.0-win\OpenCV-2.2.0\modules\imgproc\src\smooth.cpp:1282:
    error:    (-215) (src.type() == CV_8UC1 || src.type() == CV_8UC3) && src.type() == dst.type() && src.size() == dst.size() && src.data != dst.data in function bilateralFilter_8u
4

1 回答 1

6

查看文档

此过滤器不能就地工作。

您必须创建新图像作为双边过滤器的输出。

于 2013-02-03T10:42:43.317 回答