Imgproc.getRectSubPix()给出错误

时间:2015-05-25 16:50:21

标签: android opencv opencv4android

我正在撰写一篇论文,连续3天我的代码中出现了错误,因为对于上帝的爱,似乎无法修复它。

ideea很简单,我有一个有3个黑角的地图(就像QR码一样)。我得到3个黑角中心坐标和最后一个点的坐标(点D)我想将这个区域扩展到一个文件,使地图总是指向0,90,180,270,360的一个角度度。我在互联网上搜索过并找到了一个涉及RotatedRectangle的解决方案。这里有一些有用的代码:

public static RotatedRect getRotatedRect(List<Point> orderedPointList, Point D){// here i have as parameters Points(in this order) Top Right and Bottom + the final calculated point(Point D);
    if(orderedPointList==null)
        return null;
    RotatedRect rect = new RotatedRect();
    Point Top = orderedPointList.get(0);
    Point Right = orderedPointList.get(1);
    Point Bottom = orderedPointList.get(2);
    Point[] points= new Point[]{Top,Right,D,Bottom};
    rect.points(points);
    Point Center = new Point();
    Center.x=(Bottom.x+Right.x)/2;
    Center.y=(Bottom.y+Right.y)/2;
    rect.center = Center;
    double diference1=Top.x-Bottom.x;
    double difference2=Top.y-Bottom.y;
    double angle=Math.atan(diference1-difference2) * 180/Math.PI;// this formula is used to see how much the map is rotated untill now i haven't tested it for all degrees but as i see it returns -180 0 180.
    rect.angle=angle;
    double mapwidth=Math.sqrt((Right.x-Top.x)*(Right.x-Top.x)+(Right.y-Top.y)*(Right.y-Top.y));
    double mapheight=Math.sqrt((Bottom.x-Top.x)*(Bottom.x-Top.x)+(Bottom.y-Top.y)*(Bottom.y-Top.y));
    rect.size.width=mapwidth;
    rect.size.height=mapheight; // here i set the RotatedRectangle width and height.
    return rect;
}

以下代码无论我做什么都不起作用:

public static Mat getRotatedRectMat(Mat mImage,RotatedRect rect){
    if(rect==null)
        return null;
     Mat M  = new Mat();
     Mat rotated = new Mat();
     Mat clone=mImage.clone();
     //clone.convertTo(clone, CvType.CV_32F);
     //rotated.convertTo(rotated, CvType.CV_32F);
     // perform the affine transformation
     Rect boundingRect = rect.boundingRect();
     if(boundingRect.x >= 0 && boundingRect.y >=0
             && (boundingRect.x+boundingRect.width) < clone.cols() &&  
               (boundingRect.y+boundingRect.height) < clone.rows() ){
         Mat cropped=new Mat();
         M = Imgproc.getRotationMatrix2D(rect.center, rect.angle, 0.5);
         Imgproc.warpAffine(clone, rotated, M, clone.size(), Imgproc.INTER_AREA);
         Imgproc.getRectSubPix(rotated, rect.size, rect.center, cropped);//CRASHES exactly right here
reason:Noone knows
         return cropped;

     }

当我执行e.message()时得到的错误是这样的:     cv ::异常:/home/reports/ci/slave_desktop/50-SDK/opencv/modules/imgproc/src/samplers.cpp:556:错误:(-210)函数void cvGetRectSubPix(void const,void,CvPoint2D32f)

0 个答案:

没有答案