2015-05-12 63 views
2

我在java中使用opencv。我正面臨這個奇怪的問題,在我做了dilate函數後,我的圖片改變了它的大小。在documentation明確說:在java opencv中使用擴展名時更改大小

dst - 輸出圖像的大小和類型與src相同。

我的代碼是:

Log.d(TAG, "dilate size1 " + dilate.size().height + " " + dilate.size().width); 
Imgproc.GaussianBlur(warpg, smooth, new Size(3, 3), 3); 
Log.d(TAG, "smooth size1 " + smooth.size().height + " " + smooth.size().width); 
Imgproc.adaptiveThreshold(smooth, thresh, 255, 0, 1, 5, 2); 
Log.d(TAG, "thresh size1 " + thresh.size().height + " " + thresh.size().width); 
kernel = Imgproc.getStructuringElement(Imgproc.MORPH_CROSS, new Size(3, 3)); 
Imgproc.erode(thresh, erode, kernel, new Point(-1, -1), 1); 
Log.d(TAG, "erode size1 " + erode.size().height + " " + erode.size().width); 
Imgproc.dilate(erode, dilate, kernel, new Point(-1, -1), 1); 
Imgproc.findContours(thresh, contours, hierarchy, 
     Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE); 
Log.d(TAG, "dilate size2 " + dilate.size().height + " " + dilate.size().width); 

輸出是:

dilate size1 450.0 450.0 
smooth size1 450.0 450.0 
thresh size1 450.0 450.0 
erode size1 450.0 450.0 
dilate size2 1.0 313.0 

任何想法?

回答

2

我解決了這樣做的:

dilate = new Mat(erode.rows(), erode.cols(), erode.type()); 
erode.copyTo(dilate); 
Imgproc.dilate(dilate, dilate, kernel, new Point(-1, -1), 1); 

乾杯。