mixChannels()在OpenCV的机器人给人异常 [英] mixChannels() giving exception in opencv android

查看:1059
本文介绍了mixChannels()在OpenCV的机器人给人异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写函数查找矩形的垫。但我正在逐渐mixChannels异常()函数。我的code是如下。有人检查,能告诉我可能是错在它,我也想知道我可以实施灰色= gray0> =(1 + 1)* 255 / N; 在Java和Android?

I am writing function to find rectangles in Mat. But i am getting exception at mixChannels()function. My code is as follow. Can some one check and tell me what could be wrong in it ?I would also like to know how i can implement gray = gray0 >= (l+1)*255/N; in java or android ?

private void findSqaures(Mat sourceImage){
        Vector<Point> sqares;
        Mat pyr,timing ,gry =new Mat();
        pyr=new Mat(sourceImage.size(),CvType.CV_8U);
        timing=new Mat(sourceImage.size(),CvType.CV_8U);
        int thresh = 50, N = 11;
        List<Mat> grayO=new ArrayList<Mat>();
        List<Mat> timing1=new ArrayList<Mat>();
        Imgproc.pyrDown(sourceImage, pyr,new Size(sourceImage.cols()/2.0, sourceImage.rows()/2));
        Imgproc.pyrUp(pyr, timing,sourceImage.size());
//      Vector<Point> contours=new Vector<Point>();
        timing1.add(0,pyr);
        grayO.add(0,timing);
//      grayO.add(0,timing);
        for(int c=0;c<3;c++){
            int ch[]={1,0};

            MatOfInt fromto = new MatOfInt(ch);
            Core.mixChannels(timing1, grayO, fromto); // Getting Exception here
//          Core.mixChannels(src, dst, fromTo)
            for(int i=0;i<N;i++){
                Mat output=grayO.get(0);
                if(i==0){

                    Imgproc.Canny(output, gry, 5, thresh);
                    Imgproc.dilate(gry, gry, new Mat(), new Point(-1,-1), 1);
                }
                 else { 
//                   output = output >= (i+1)*255/N;
                   }
//              sourceImage=gry;
                contours=new ArrayList<MatOfPoint>();
                Imgproc.findContours(gry, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
                 MatOfPoint2f approxCurve = new MatOfPoint2f();
                 mDrawnContours.clear();
                 Log.i(TAG, "::findSqaures:" + "contours.size():"+contours.size());
                for(int j=0;i<contours.size();j++){
                    MatOfPoint tempContour=contours.get(i);
                    MatOfPoint2f newMat = new MatOfPoint2f( tempContour.toArray() );
                    int contourSize = (int)tempContour.total();

                    Imgproc.approxPolyDP(newMat, approxCurve, contourSize*0.02, true);
                    MatOfPoint points=new MatOfPoint(approxCurve.toArray());
//                    if( approx.size() == 4 && fabs(contourArea(cv::Mat(approx))) > 1000 && cv::isContourConvex(cv::Mat(approx))) {
                    if(points.toArray().length==4 && (Math.abs(approxCurve.total())>1000) && Imgproc.isContourConvex(points)){
                        double maxCosine=0;
                        int k;
                        for( k=2;k<5;k++){
                            double cosine=Math.abs(angle(points.toArray()[k%4], points.toArray()[k-2], points.toArray()[k-1]));
                            if(maxCosine>cosine){
                                maxCosine=cosine;
                            }
                        }
                        Log.i(TAG, "::findSqaures:" + "maxCosine:"+maxCosine);
                        if(maxCosine<0.3){
                            DrawnContours drawnContours=new DrawnContours();
                            drawnContours.setIndex(k);
                            mDrawnContours.add(drawnContours);

                        }

                    }

                }
                Log.i(TAG, "::findSqaures:" + "mDrawnContours.size():"+mDrawnContours.size());
            }
        }


//      Core.mixChannels(src, dst, fromTo)

    }

唯一的例外是的 * CvException [org.opencv.core.CvException:/home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/matrix.cpp:3210:错误:( -215)A.size ==阵列[I0] - >大小函数void CV :: NAryMatIterator ::初始化(常量CV ::垫,CV ::垫*,* UCHAR的,INT) 的**

The exception is *CvException [org.opencv.core.CvException: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/matrix.cpp:3210: error: (-215) A.size == arrays[i0]->size in function void cv::NAryMatIterator::init(const cv::Mat, cv::Mat*, uchar*, int)**

推荐答案

Core.mixChannels(timing1, grayO, fromto); 

gray0 阵列和时序1 数组的元素应该有相同的大小。
有一半大小时间让你有一个错误。

element of gray0 array and timing1 array should have the same size. but pyr has half the size of timing so you've got an error.

在样品再看看 squares.cpp


  1. mixChannels功能的来源应该是pyrUp函数的结果垫

  2. mixChannels功能的目的地应该是一个新的空垫具有相同的尺寸。

所以,用更正:

timing1.add(0,timing); // or timing1.add(timing)
grayO.add(0, new Mat(timing.size(), timing.type()) );

问候,
路易

Regards, Louis

这篇关于mixChannels()在OpenCV的机器人给人异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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