我正在尝试在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:DownloadsSoftwareOpenCV-2.2.0-winOpenCV-2.2.0modulesimgprocsrcsmooth.cpp, line 1282
terminate called after throwing an instance of 'cv::Exception'
what(): C:DownloadsSoftwareOpenCV-2.2.0-winOpenCV-2.2.0modulesimgprocsrcsmooth.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
查看文档:
此筛选器无法就地工作。
您必须创建新图像作为双边过滤器的输出。