[英]Different image using OpenCV in python and java
I'm using OpenCV to modify an image in python and in java. 我正在使用OpenCV修改python和java中的图像。 The code is very simple but I'm not getting the same result, why?: 代码很简单,但是我没有得到相同的结果,为什么?:
Python : Python :
img = cv2.imread('sudoku.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
thresh = cv2.adaptiveThreshold(gray,255,1,1,5,2)
printImg(thresh)
Java : 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);
So, I'd tested some configurations and tried some workarounds. 因此,我测试了一些配置并尝试了一些解决方法。 The issue seems related to how to load the image. 该问题似乎与如何加载图像有关。 Convert the image from bitmap
to mat
seems to affect the quality of the image as @berak said. 如@berak所说,将图像从bitmap
转换为mat
似乎会影响图像的质量。 I ended up using Highgui.imread
to get the image. 我最终使用Highgui.imread
来获取图像。
If someone knows how to do it in a more android-friendly way I'd like to hear it. 如果有人知道如何以对Android更友好的方式进行操作,我想听听。
Cheers. 干杯。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.