2017-08-28 3 views
0

ここでは、グレアを除去しようとしています。inpaint()は予期した結果を生成しません。どうして?

これは私のオリジナル画像です。
enter image description here

これは私のマスク画像です。
enter image description here

私はinpaint()を使用するために、次のコード行を使用:

inpaint(image, vthresh, out, 5.0, CV_INPAINT_NS); //CV_INPAINT_TELEA , CV_INPAINT_NS 

しかし、私はinpaint()を使用しても効果の結果を得ることができない理由を私は理解していません。 誰もその理由を指摘できますか?ありがとう!ここで

+0

ように添加ヘッダと主な機能を試してみてください: 'CV :: bitwise_not(VTHRESH、VTHRESH);'前'inpaint'を呼び出します。 –

+0

cv :: bitwise_not(vthresh、vthresh); これはちょうど逆のイメージです。 – Abc

+0

はい、それはあなたのマスクを反転させる、私はちょうどあなたのマスクが間違っていると思っていた。 –

答えて

3

あなたが行く:

#include "opencv2/highgui.hpp" 
#include "opencv2/photo.hpp" 

#include <iostream> 

using namespace cv; 
using namespace std; 

int main(int args, char** argv) 
{ 
    //Read the image 
    Mat img = imread("/Desktop/apple.png", -1); 
    //create inpaint mask the size of original image 
    Mat inpaintMask = img.clone(); 
    //convert mask from rgb to gray 
    cv::cvtColor(inpaintMask, inpaintMask, cv::COLOR_RGB2GRAY); 
    // convert mask from gray to binary by thresholding, you can play with 170 and 255 args to achieve desired mask 
    cv::threshold(inpaintMask, inpaintMask, 170, 255, cv::THRESH_BINARY); 
    Mat inpainted; 
    //finally call inpaint function and pass the args 
    inpaint(img, inpaintMask, inpainted, 3, INPAINT_TELEA); 

    imshow("image", img); 
    imshow("mask", inpaintMask); 
    imshow("inpainted image", inpainted); 
    cv::waitKey(0); 
} 

編集:それは、スタンドアロンのファイル

+0

私はそれを試しました。私はまだバイナリイメージを取得しています。期待される結果ではない。 – Abc

+0

まだバイナリイメージを与えている理由が見つかりません。 – Abc

+0

@Abc新しいコードをコピーして別のファイルに貼り付け、g ++でコンパイルします。 – zindarod

関連する問題