2013-02-03 28 views
3

我想在Qt中使用OpenCV實現雙邊過濾器。到目前爲止,我已經做到了這一點:cv :: bilateralFilter

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(); 
} 

其中imagecv::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 
+0

您是否找到解決方案?與我發生同樣的問題。 –

回答

4

退房documentation

This filter does not work inplace.

您必須創建新的圖像作爲雙邊濾波器輸出。

+0

謝謝你的工作...... – Tysro

+0

嘿@Cfr,我注意到在文檔中,但是函數本身在源代碼中返回void。你能詳細解釋一下嗎? – TaylorTheDeveloper

+0

我得到了同樣的錯誤,我正在創建一個新的圖像 – tiagosilva