0

開いている cv で四角形を検出するコードを書きました。また、オブジェクトはほとんど検出できませんが、物理的なドアや大きな長方形は検出できません。コードを確認して、どこか間違っている場合は修正してください。別の問題は、このコードが常に四角形を検出できないことです。そのため、四角形を描画すると、行ったり来たりして、見栄えが悪くなります。すべてのフレームで定期的に検出する方法。

 Mat  output= getGray(inputFrame.rgba(),inputFrame.rgba());
        Imgproc.medianBlur(output, output, 5);
        Imgproc.erode(output, output, new Mat());
        Imgproc.dilate(output, output, new Mat());
         Mat edges = new Mat();
        Imgproc.Canny(output, output, 5, 50);
//      Vector<MatOfPoint> vector=new Vector<MatOfPoint>();
//      Imgproc.findContours(output, points, output, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
         contours = new ArrayList<MatOfPoint>();
        Mat hierarchy = new Mat();
        contours.clear();
        Imgproc.findContours(output, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

 MatOfPoint2f approxCurve = new MatOfPoint2f();
        rgbImage=inputFrame.rgba();
        mDrawnContours.clear();

> Blockquote

 for(int i=0;i< contours.size();i++){
            MatOfPoint tempContour=contours.get(i);
            MatOfPoint2f newMat = new MatOfPoint2f( tempContour.toArray() );
            int contourSize = (int)tempContour.total();
            Imgproc.approxPolyDP(newMat, approxCurve, contourSize*0.15, true);
            MatOfPoint points=new MatOfPoint(approxCurve.toArray());

            if((Math.abs(Imgproc.contourArea(tempContour))<100) || !Imgproc.isContourConvex(points)){
                Log.i(TAG, "::onCameraFrame:" + " too small");
                appendLog("Too small");
                continue;
            }
            else if(points.toArray().length >= 4 && points.toArray().length <= 6){
                int vtc = points.toArray().length;
                Vector<Double> cosList=new Vector<Double>();
                for (int j = 2; j < vtc+1; j++){

                    cosList.add(angle(points.toArray()[j%vtc], points.toArray()[j-2], points.toArray()[j-1]));

                }   
                   double mincos = getMin(cosList);
                   double maxcos = getMax(cosList);
                   Log.i(TAG, "::onCameraFrame:" + "mincos:"+mincos+"maxcos:"+maxcos);
                   if (vtc == 4 && mincos >= -0.1 && maxcos <= 0.3)
                   {
                       mTotalSquare++;

                        Imgproc.drawContours(rgbImage, contours, i, new Scalar(0,0,255));
                        DrawnContours contours2=new DrawnContours();
                        contours2.setIndex(i);
                        mDrawnContours.add(contours2);
                        Log.i(TAG, "::onCameraFrame:" + "found");
                        appendLog("found");

                   }
                   else{
                       Log.i(TAG, "::onCameraFrame:" +" not found " +"mincos:"+mincos+"maxcos:"+maxcos);
                       appendLog("not found 1");
                   }

            }

return rgbImage

ご不明な点がございましたら、お知らせください。

4

1 に答える 1

0

大きな輪郭には4つ以上のエッジがあると思います。それらの輪郭は、多数の短い線分で構成されています (線の近似関数パラメーターに依存します)。

 Imgproc.approxPolyDP(newMat, approxCurve, contourSize*0.15, true);

)。

そして、エッジ番号をチェックする条件があります:

points.toArray().length <= 6
于 2013-11-12T19:19:14.553 に答える