0

Matで長方形を見つける関数を書いています。しかし、私は mixChannels() 関数で例外を取得しています。私のコードは次のとおりです。誰かがチェックして、何が間違っているのか教えてもらえますか gray = gray0 >= (l+1)*255/N;?Javaまたは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: error: (-215) A.size == arrays[i0]->関数内のサイズ void cv::NAryMatIterator::init(const cv::Mat , cv::Mat*, uchar* , int) **

4

2 に答える 2

1

次の timing1.add(0,pyr); の代わりに grayO.add(0,タイミング);

これを試して

timing1.add(pyr);
grayO.add(timing);

下の行の代わりに

gry = output >= (i+1)*255/N;

あなたが使用することができます

Imgproc.threshold(output, gry, (l+1) * 255 / N, 255, Imgproc.THRESH_BINARY);

また、ソースとして pyr を使用する代わりに、medianBlur 関数を使用して画像をぼかすと、より良い四角形の識別が得られます。

于 2014-01-17T06:07:02.113 に答える