java - 在 python 和 java 中使用 OpenCV 的不同图像

标签 java python opencv

我正在使用 OpenCV 在 python 和 java 中修改图像。代码非常简单,但我没有得到相同的结果,为什么?:

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

最佳答案

因此,我测试了一些配置并尝试了一些解决方法。该问题似乎与如何加载图像有关。将图像从 bitmap 转换为 mat 似乎会影响图像的质量,正如@berak 所说。我最终使用 Highgui.imread 来获取图像。

如果有人知道如何以对 Android 更友好的方式做到这一点,我很想听听。

干杯。

关于java - 在 python 和 java 中使用 OpenCV 的不同图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30140317/

相关文章:

python - 用于图像去模糊的维纳滤波器

java - 合并来自多个 Jenkins 作业的测试覆盖率和测试结果

使用 os.system 的 python 超时

java - 我应该使用什么二维数据结构来支持Java中的固定大小?

python - 如何读取其中包含数组的文件.txt?

c# - C++ 中 cv::Rectangle 的问题

java - OpenCV 错误 : Assertion failed (ksize. 宽度 > ...... 对于 GaussianBlur

python - 字符识别的最佳算法

java - 使用嵌套 addValueEventListener 时 Android firebase 错误

java - 如何通过 GPars 中的主 Actor 终止所有从属 Actor?