cverror Android的断言失败(SCN == 3)的Andr​​oid [英] cverror android assertion failed (scn == 3) Android

查看:464
本文介绍了cverror Android的断言失败(SCN == 3)的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的图像(位图)我有机器人这就需要改变成一个垫子,然后将其转换为灰度上使用自适应阈值。

下面是我的code开始创建位图。它们被命名为作物,因为我只是在这之前裁剪照片的权利。

 位图bmCrop = BitmapFactory.de codeStream(istream的);
            位图bmThreshed = NULL;
            / *
             *初始化垫
             * /
            垫脱粒=新垫(bmCrop.getHeight(),bmCrop.getWidth(),CvType.CV_8UC1,新标(4)); //,新的标量(4)
            //垫作物=新垫();
            垫作物=新垫(bmCrop.getHeight(),bmCrop.getWidth(),CvType.CV_8UC1,新标(4)); //,新的标量(4)
            / *
             *转换的垫为灰度
             * /
            如果(!threshed.empty())
                Imgproc.cvtColor(脱粒,脱粒,Imgproc.COLOR_RGB2GRAY,1); //当前BREAKING HERE
            如果(!crop.empty())
                Imgproc.cvtColor(作物,作物,Imgproc.COLOR_BGR2GRAY,1);
            Utils.bitmapToMat(bmCrop,作物);            //垫SRC,DST垫,双maxValue(最大值),INT adaptiveMethod,诠释thresholdType,INT块大小,双C
            Imgproc.adaptiveThreshold(作物,脱粒,255,Imgproc.ADAPTIVE_THRESH_MEAN_C,Imgproc.THRESH_BINARY_INV,15,第8);            Utils.matToBitmap(脱粒,bmThreshed);
            bmThreshed = bmCrop;

这是目前突破上线Imgproc.cvtColor(脱粒,脱粒,Imgproc.COLOR_RGB2GRAY,1)在那里我试图cvtColor在垫子上。

下面是LogCat中的输出:

 十一月5日至28日:25:21.172:E / CV ::错误()(32505):OpenCV的错误:断言失败(SCN == || 3 SCN == 4)在无效简历:: cvtColor(CV :: InputArray,CV :: OutputArray,INT,INT),文件/home/reports/ci/slave/50-SDK/opencv/modules/imgproc/src/color.cpp,线路3414
11月5日至28日:25:25.697:D / AndroidRuntime(32505):关闭VM
11月5日至28日:25:25.707:W / dalvikvm(32505):主题ID = 1:螺纹未捕获的异常退出(组= 0x414b1930)
11月5日至28日:25:25.747:E / AndroidRuntime(32505):致命异常:主要
11月5日至28日:25:25.747:E / AndroidRuntime(32505):CvException [org.opencv.core.CvException:/home/reports/ci/slave/50-SDK/opencv/modules/imgproc/src/color.cpp :3414:错误:(-215)SCN == || 3 SCN == 4在功能上无效简历:: cvtColor(CV :: InputArray,CV :: OutputArray,INT,INT)
11月5日至28日:25:25.747:E / AndroidRuntime(32505):]
11月5日至28日:25:25.747:E / AndroidRuntime(32505):在org.opencv.imgproc.Imgproc.cvtColor_0(本机方法)
11月5日至28日:25:25.747:E / AndroidRuntime(32505):在org.opencv.imgproc.Imgproc.cvtColor(Imgproc.java:4017)
11月5日至28日:25:25.747:E / AndroidRuntime(32505):在com.activity.IMGP_Camera $ 1.onManagerConnected(IMGP_Camera.java:263)
11月5日至28日:25:25.747:E / AndroidRuntime(32505):在org.opencv.android.AsyncServiceHelper $ 1.onServiceConnected(AsyncServiceHelper.java:318)
11月5日至28日:25:25.747:E / AndroidRuntime(32505):在android.app.LoadedApk $ ServiceDispatcher.doConnected(LoadedApk.java:1101)
11月5日至28日:25:25.747:E / AndroidRuntime(32505):在android.app.LoadedApk $ ServiceDispatcher $ RunConnection.run(LoadedApk.java:1118)
11月5日至28日:25:25.747:E / AndroidRuntime(32505):在android.os.Handler.handleCallback(Handler.java:725)
11月5日至28日:25:25.747:E / AndroidRuntime(32505):在android.os.Handler.dispatchMessage(Handler.java:92)
11月5日至28日:25:25.747:E / AndroidRuntime(32505):在android.os.Looper.loop(Looper.java:137)
11月5日至28日:25:25.747:E / AndroidRuntime(32505):在android.app.ActivityThread.main(ActivityThread.java:5226)
11月5日至28日:25:25.747:E / AndroidRuntime(32505):在java.lang.reflect.Method.invokeNative(本机方法)
11月5日至28日:25:25.747:E / AndroidRuntime(32505):在java.lang.reflect.Method.invoke(Method.java:511)
11月5日至28日:25:25.747:E / AndroidRuntime(32505):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:795)
11月5日至28日:25:25.747:E / AndroidRuntime(32505):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
11月5日至28日:25:25.747:E / AndroidRuntime(32505):在dalvik.system.NativeStart.main(本机方法)


解决方案

这是我现在的工作code。我有问题是我没有做初始化垫后做cvtColor()前右Utils.bitmapToMat()。

  / *
             *初始化位图
             * /
            位图bmCrop = BitmapFactory.de codeStream(istream的);
            位图bmThreshed = bmCrop;
            / *
             *初始化垫
             * /
            垫脱粒=新垫(bmCrop.getWidth(),bmCrop.getHeight(),CvType.CV_8UC1);
            Utils.bitmapToMat(bmCrop,脱粒);            垫作物=新垫(bmCrop.getWidth(),bmCrop.getHeight(),CvType.CV_8UC1);
            Utils.bitmapToMat(bmCrop,作物);
            / *
             *转换的垫为灰度
             * /
            如果(!threshed.empty())
                Imgproc.cvtColor(脱粒,脱粒,Imgproc.COLOR_RGB2GRAY);
            如果(!crop.empty())
                Imgproc.cvtColor(作物,农作物,Imgproc.COLOR_BGR2GRAY);            / *
             *使用自适应阈值的grayscaled垫
             *作物 - >脱粒
             *垫SRC,DST垫,双maxValue(最大值),INT adaptiveMethod,诠释thresholdType,INT块大小,双C
             * /
            Imgproc.adaptiveThreshold(作物,脱粒,255,Imgproc.ADAPTIVE_THRESH_MEAN_C,Imgproc.THRESH_BINARY,15,第8); // 15,8个是测试。凯西75,10            Utils.matToBitmap(脱粒,bmThreshed);
            bmThreshed = bmCrop;

I'm trying to use adaptive thresholding on an image (Bitmap) I have in android which requires changing it into a Mat and then converting it to grayscale.

Below is my code starting with creating the bitmaps. They are named crop because I just cropped the photo right before this.

            Bitmap bmCrop = BitmapFactory.decodeStream(iStream);
            Bitmap bmThreshed = null;
            /*
             * Initialize the Mats
             */
            Mat threshed = new Mat(bmCrop.getHeight(),bmCrop.getWidth(), CvType.CV_8UC1, new Scalar(4));//, new Scalar(4)
            //Mat crop = new Mat();
            Mat crop = new Mat(bmCrop.getHeight(),bmCrop.getWidth(), CvType.CV_8UC1,new Scalar(4));//, new Scalar(4)
            /*
             * Convert the Mats to Grayscale
             */
            if(!threshed.empty())
                Imgproc.cvtColor(threshed, threshed, Imgproc.COLOR_RGB2GRAY,1);// CURRENTLY BREAKING HERE
            if(!crop.empty())
                Imgproc.cvtColor(crop, crop, Imgproc.COLOR_BGR2GRAY,1);         


            Utils.bitmapToMat(bmCrop, crop);

            // Mat src, Mat dst, double maxValue, int adaptiveMethod, int thresholdType, int blockSize, double C
            Imgproc.adaptiveThreshold(crop, threshed, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY_INV, 15, 8);

            Utils.matToBitmap(threshed, bmThreshed);
            bmThreshed = bmCrop;

It is currently breaking on the line "Imgproc.cvtColor(threshed, threshed, Imgproc.COLOR_RGB2GRAY,1)" where I attempt to cvtColor on the Mat.

Below is the output of LogCat:

05-28 11:25:21.172: E/cv::error()(32505): OpenCV Error: Assertion failed (scn == 3 || scn == 4) in void cv::cvtColor(cv::InputArray, cv::OutputArray, int, int), file /home/reports/ci/slave/50-SDK/opencv/modules/imgproc/src/color.cpp, line 3414
05-28 11:25:25.697: D/AndroidRuntime(32505): Shutting down VM
05-28 11:25:25.707: W/dalvikvm(32505): threadid=1: thread exiting with uncaught exception (group=0x414b1930)
05-28 11:25:25.747: E/AndroidRuntime(32505): FATAL EXCEPTION: main
05-28 11:25:25.747: E/AndroidRuntime(32505): CvException [org.opencv.core.CvException: /home/reports/ci/slave/50-SDK/opencv/modules/imgproc/src/color.cpp:3414: error: (-215) scn == 3 || scn == 4 in function void cv::cvtColor(cv::InputArray, cv::OutputArray, int, int)
05-28 11:25:25.747: E/AndroidRuntime(32505): ]
05-28 11:25:25.747: E/AndroidRuntime(32505):    at org.opencv.imgproc.Imgproc.cvtColor_0(Native Method)
05-28 11:25:25.747: E/AndroidRuntime(32505):    at org.opencv.imgproc.Imgproc.cvtColor(Imgproc.java:4017)
05-28 11:25:25.747: E/AndroidRuntime(32505):    at com.activity.IMGP_Camera$1.onManagerConnected(IMGP_Camera.java:263)
05-28 11:25:25.747: E/AndroidRuntime(32505):    at org.opencv.android.AsyncServiceHelper$1.onServiceConnected(AsyncServiceHelper.java:318)
05-28 11:25:25.747: E/AndroidRuntime(32505):    at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1101)
05-28 11:25:25.747: E/AndroidRuntime(32505):    at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1118)
05-28 11:25:25.747: E/AndroidRuntime(32505):    at android.os.Handler.handleCallback(Handler.java:725)
05-28 11:25:25.747: E/AndroidRuntime(32505):    at android.os.Handler.dispatchMessage(Handler.java:92)
05-28 11:25:25.747: E/AndroidRuntime(32505):    at android.os.Looper.loop(Looper.java:137)
05-28 11:25:25.747: E/AndroidRuntime(32505):    at android.app.ActivityThread.main(ActivityThread.java:5226)
05-28 11:25:25.747: E/AndroidRuntime(32505):    at java.lang.reflect.Method.invokeNative(Native Method)
05-28 11:25:25.747: E/AndroidRuntime(32505):    at java.lang.reflect.Method.invoke(Method.java:511)
05-28 11:25:25.747: E/AndroidRuntime(32505):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
05-28 11:25:25.747: E/AndroidRuntime(32505):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
05-28 11:25:25.747: E/AndroidRuntime(32505):    at dalvik.system.NativeStart.main(Native Method)

解决方案

Here is my now working code. The problem that I had was that I wasn't doing Utils.bitmapToMat() right after Initializing the Mats and before doing the cvtColor().

            /*
             * Initialize the bitmaps
             */
            Bitmap bmCrop = BitmapFactory.decodeStream(iStream);
            Bitmap bmThreshed = bmCrop;
            /*
             * Initialize the Mats
             */
            Mat threshed = new Mat(bmCrop.getWidth(),bmCrop.getHeight(), CvType.CV_8UC1);
            Utils.bitmapToMat(bmCrop, threshed);

            Mat crop = new Mat(bmCrop.getWidth(),bmCrop.getHeight(), CvType.CV_8UC1);
            Utils.bitmapToMat(bmCrop, crop);
            /*
             * Convert the Mats to Grayscale
             */
            if(!threshed.empty())
                Imgproc.cvtColor(threshed, threshed, Imgproc.COLOR_RGB2GRAY);
            if(!crop.empty())
                Imgproc.cvtColor(crop, crop, Imgproc.COLOR_BGR2GRAY);           

            /*
             * Use Adaptive Thresholding on the grayscaled Mats
             * crop -> threshed
             * Mat src, Mat dst, double maxValue, int adaptiveMethod, int thresholdType, int blockSize, double C
             */
            Imgproc.adaptiveThreshold(crop, threshed, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 15, 8);//15, 8 were original tests. Casey was 75,10

            Utils.matToBitmap(threshed, bmThreshed);
            bmThreshed = bmCrop;

这篇关于cverror Android的断言失败(SCN == 3)的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆