2015-05-09 27 views
1

我使用OpenCV在python和java中修改圖像。該代碼是很簡單的,但我沒有得到相同的結果,爲什麼?:在python和java中使用OpenCV的不同圖像

的Python

img = cv2.imread('sudoku.jpg') 
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) 

thresh = cv2.adaptiveThreshold(gray,255,1,1,5,2) 
printImg(thresh) 

enter image description here

的Java

BitmapFactory.Options op = new BitmapFactory.Options(); 
     op.inPreferredConfig = Bitmap.Config.ARGB_8888; 
Bitmap bm = BitmapFactory.decodeResource(mContext.getResources(), 
       R.drawable.sudoku1, op); 
Utils.bitmapToMat(bm, img); 
Imgproc.cvtColor(img, gray, Imgproc.COLOR_BGR2GRAY); 
Imgproc.adaptiveThreshold(gray, thresh, 255, 1, 1, 5, 2); 

enter image description here

+0

嘗試使用png或更好的bmp文件(有損jpg壓縮) – berak

回答

1

所以,我測試了一些配置並嘗試了一些解決方法。這個問題似乎與如何加載圖像有關。 @berak說,將圖像從bitmap轉換爲mat似乎會影響圖像的質量。我最終使用Highgui.imread來獲取圖像。

如果有人知道如何以更友好的方式進行操作,我希望聽到它。

乾杯。

相關問題