我正在尝试在 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
最佳答案
查看 documentation :
您必须创建新图像作为双边滤波器的输出。
关于qt - cv::双边过滤器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14671443/