Photo.colorChange()opencv函数给出奇怪的错误

时间:2018-09-26 07:22:36

标签: android opencv image-processing

我是opencv概念的新手,所以如果我的问题很愚蠢,请原谅。基本上,我试图使用Photo.colorChange()的{​​{1}}函数。但是问题是它给出了一个奇怪的错误,我不明白为什么。我试图在Google中找到参考,但是我在任何地方都找不到。

有人可以帮我解决此问题吗?

代码:

opencv

错误:

Mat tmp = new Mat (bitmap.getWidth(), bitmap.getHeight(), CvType.CV_8UC4);

            Utils.bitmapToMat(bitmap, tmp);

            Mat tir=new Mat(bitmap.getWidth()/2,bitmap.getHeight()/2,CvType.CV_8UC4);
             Photo.colorChange(tmp,tmp,tir,0.5f,0.4f,0.2f);


            Utils.matToBitmap(tmp,bitmap);

关注this answer之后,出现以下新错误。

新错误:

CvException [org.opencv.core.CvException: cv::Exception: /home/maksim/workspace/android-pack/opencv/modules/core/src/arithm.cpp:1987: error: (-209) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function void cv::arithm_op(cv::InputArray, cv::InputArray, cv::OutputArray, cv::InputArray, int, void (**)(const uchar*, size_t, const uchar*, size_t, uchar*, size_t, cv::Size, void*), bool, void*, int)
]
    at org.opencv.photo.Photo.colorChange_0(Native Method)
    at org.opencv.photo.Photo.colorChange(Photo.java:480)
    at opengl.community.myopencvexample.MainActivity$3.onClick(MainActivity.java:87)
    at android.view.View.performClick(View.java:4478)
    at android.view.View$PerformClick.run(View.java:18698)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:149)
    at android.app.ActivityThread.main(ActivityThread.java:5257)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
    at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

出现此错误的原因似乎是因为tmptir矩阵的行数不同:

Photo.colorChange(tmp,tmp,tir,0.5f,0.4f,0.2f);

使用

创建tir
Mat tir=new Mat(bitmap.getWidth()/2,bitmap.getHeight()/2,CvType.CV_8UC4);

因此它的尺寸是tmp尺寸的一半。您可以将tir创建为:

Mat tir=new Mat(bitmap.getWidth(),bitmap.getHeight(),CvType.CV_8UC4);
Photo.colorChange(tmp,tmp,tir,0.5f,0.4f,0.2f);

完成这些步骤后,您可以使用tir来调整Imgproc.resize()的大小。