2017-01-01 2 views
2

In OpenCV Android, ist es möglich, bilaterale Filterung anzuwenden? Ich weiß, dass ich Gaussian Unschärfe wie Imgproc.GaussianBlur(gray, gray, new Size(15,15), 0); tun kann, aber ich kann nicht scheinen, den Code für die bilaterale Filterung zu finden.OpenCV 2.4 Bilaterale Filterung

Antwort

3

scheint es möglich, wie:

Imgproc.bilateralFilter(mat, dstMat, 10, 50, 0); 

von here und here.

aktualisieren

Dieses:

E/AndroidRuntime: FATAL EXCEPTION: Thread-1376 Process: PID: 30368 CvException [org.opencv.core.CvException: cv::Exception: /Volumes/build-storage/build/2_4_pack-android/opencv/modules‌​/imgproc/src/smooth.‌​cpp:1925: error: (-215) (src.type() == CV_8UC1 || src.type() == CV_8UC3) && src.type() == dst.type() && src.size() == dst.size() && src.data != dst.data in function void cv::bilateralFilter_8u(const cv::Mat&, cv::Mat&, int, double, double, int) 

ist, weil falsche Farbe Format der Verarbeitung Mat. Sie sollten 4 Kanäle RGBA Format in 3 Kanäle konvertieren RGB für bilateralFilter() gelten (wie in bilateralFilterTutorial() Methode here). Also, Code Sie sollten so sein:

// load Mat from somewhere (e.g. from assets) 
mSourceImageMat = Utils.loadResource(this, R.drawable.<your_image>); 
// convert 4 channel Mat to 3 channel Mat 
Imgproc.cvtColor(mSourceImageMat, mSourceImageMat, Imgproc.COLOR_BGRA2BGR); 

// create dest Mat 
Mat dstMat = mSourceImageMat.clone(); 

// apply bilateral filter 
Imgproc.bilateralFilter(mSourceImageMat, dstMat, 10, 250, 50); 

// convert to 4 channels Mat back 
Imgproc.cvtColor(dstMat, dstMat, Imgproc.COLOR_RGB2RGBA); 

// create result bitmap and convert Mat to it 
Bitmap bm = Bitmap.createBitmap(mSourceImageMat.cols(), mSourceImageMat.rows(), Bitmap.Config.ARGB_8888); 
Utils.matToBitmap(dstMat, bm); 

// show bitmap on ImageView 
mImageView.setImageBitmap(bm); 
+0

E/Android Runtime: Schwerwiegende Ausnahme: Thread-1376-Prozess: PID: 30368 CvException [org.opencv.core.CvException: cv :: Ausnahme:/Volumes/Build- storage/build/2_4_pack-android/opencv/Module/imgproc/src/smooth.cpp: 1925: Fehler: (-215) (src.type() == CV_8UC1 || src.type() == CV_8UC3) && src .type() == dst.type() && src.size() == dst.size() && src.data! = dst.data in der Funktion void cv :: bilateralFilter_8u (const cv :: Mat &, cv :: Mat &, int, double, double, int) – user7360712

+0

Ich habe diesen Fehler bei der Ausführung dieses Codes erhalten – user7360712

+0

Bitte siehe aktualisierte Antwort. –