Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在打开的cv android中检测到Physycal门或其他大矩形_Android_Opencv - Fatal编程技术网

无法在打开的cv android中检测到Physycal门或其他大矩形

无法在打开的cv android中检测到Physycal门或其他大矩形,android,opencv,Android,Opencv,我编写了代码来检测open cv中的矩形。我能探测到很少的物体,但我不能探测到实体门或大矩形。请检查我的代码,如果我在什么地方出错,请纠正我。另一个问题是,这段代码不能经常检测矩形,所以当我画矩形时,它来来往往,来来往往,看起来很糟糕。在每一帧中定期检测的任何方法 Mat output= getGray(inputFrame.rgba(),inputFrame.rgba()); Imgproc.medianBlur(output, output, 5); Im

我编写了代码来检测open 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
Mat output=getGray(inputFrame.rgba(),inputFrame.rgba());
Imgproc.medianBlur(输出,输出,5);
侵蚀(输出,输出,新材料());
Imgproc.deflate(输出,输出,新Mat());
垫边=新垫();
Imgproc.Canny(输出,输出,5,50);
//向量=新向量();
//Imgproc.findContours(输出、点、输出、Imgproc.RETR\u列表、Imgproc.CHAIN\u近似值\u简单值);
等高线=新的ArrayList();
Mat层次结构=新Mat();
轮廓。清晰();
Imgproc.findContours(输出、轮廓、层次、Imgproc.RETR\u外部、Imgproc.CHAIN\u近似\u简单);
MatOfPoint2f approxCurve=新的MatOfPoint2f();
rgbImage=inputFrame.rgba();
mDrawnContours.clear();
>大宗报价
对于(int i=0;i如果((Math.abs(Imgproc.contourArea(tempcourt))=4&&points.toArray().length=-0.1&&maxcos我想,大轮廓有4条以上的边。它们的轮廓由大量短线段组成(取决于直线中的近似函数参数

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

并且您具有检查边编号的条件:

points.toArray().length <= 6

points.toArray().长度到目前为止,你检测到了什么?嗨,我可以检测到小纸张、纸板、笔记本电脑屏幕、小封面,有时还可以检测到撞击物,但无法检测到更大的物体。嗨,谢谢你的回复。我删除了该条件,但没有多大区别。另一个问题是我没有在每一帧中都看到矩形。所以矩形来去频繁好吧,我可以给你另一个想法:你得到轮廓,计算轮廓的面积,然后用Minarealect方法,计算最小包围矩形的面积。如果你的轮廓形状接近矩形,面积将大致相等。希望你明白这个想法。嗨,Andrey,谢谢你的电子邮件,但我不是一个能够理解你所说的。如果可能的话,请你提供一些代码片段,以便我能更好地理解。Area1=Math.abs(Imgproc.contourArea(tempContour));RotatedRect RR=MinareRect(contourPoints);Area2=RR.size.width*RR.size.height;if(晶圆厂(Area1-Area2)您好,下面是我为您的建议编写的代码,但似乎不起作用。他们有什么问题吗?double Area 1=Math.abs(Imgproc.contourArea(tempContour));RotatedRect1=Imgproc.Minarealect(newMat);double Area 2=rect1.size.width*rect1.size.height;appendLog(“Math.abs(Area-Area 2);“+Math.abs(区域1-2));如果(数学abs(区域1-2)