尝试应用OpenCV时,Java中出现空参数?

时间:2018-11-11 12:18:43

标签: java opencv error-handling nullpointerexception netbeans-8

 public EllipseParam detectAndDisplay(BufferedImage img, CascadeClassifier faceCascade) {
   // EllipseParam openCV;
    Point center = null;
    double width = 0;
    double height = 0;

    Mat image = ImagePreProcessing.bufferedImageToMat(img);

    // -- Detect faces
    MatOfRect faces = new MatOfRect(); 
    faceCascade.detectMultiScale(image, faces);

    List<Rect> listOfFaces = faces.toList();
    for (Rect face : listOfFaces) {
        center = new Point(face.x + face.width * 0.5, face.y + face.height * 0.5);
        width = face.width*0.5;
        height = face.height*0.5;

        System.out.println("OpenCV: " +center);
        System.out.println("wid:" +width);
        System.out.println("hei:" +height);
        EllipseParam openCV = new EllipseParam(center, width, height);
        System.out.println("value on EllipseParam: " +String.valueOf(openCV));
        return openCV;
    }
    return null;
}

-----在EllipseParam类中

public class EllipseParam {
public double x;
public double y;
public double a;
public double b;
public double theta;
public Point center;
public double width;
public double height;

public EllipseParam(double x,double y,double a,double b,double theta){
    this.x = x;
    this.y = y;
    this.a = a;
    this.b = b;
    this.theta = theta;
}

public EllipseParam(Point center, double width, double height){
    //this.image = image;
    this.center = center;
    this.width = width;
    this.height = height;
}

我尝试设置参数并得到它,但是我得到的输出是这样的:

OpenCV:{196.5,156.5}

wid:147.5

hei:147.5

线程“ AWT-EventQueue-0”中的异常java.lang.NullPointerException

EllipseParam上的

值:entity.EllipseParam@d34c4b

我的代码有什么问题?

我阅读了答案,但实际上并不能解决我的问题。你能再跟我解释一下吗?

0 个答案:

没有答案