I got null parameter in Java when I try to apply OpenCV?











up vote
0
down vote

favorite












 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;
}


----- in the EllipseParam class



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;
}


I try to setting parameter and getting that, but output I got is like this:



OpenCV: {196.5, 156.5}



wid:147.5



hei:147.5



Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException



value on EllipseParam: entity.EllipseParam@d34c4b



What is wrong with my code?



I read the answer, but its not solve my issue actually. Can you explain to me more?










share|improve this question
























  • Please show the complete stack trace. At the moment we can't tell enough about where the exception is being thrown.
    – Jon Skeet
    Nov 11 at 12:20










  • Why do you return null from the method?
    – Michael Dz
    Nov 11 at 12:21










  • @JonSkeet oke I try.
    – Winda Agusthia Netto
    Nov 11 at 12:27










  • @MichaelDz I tried to apply somecode for different result from my original code I made...but the reason I not really know
    – Winda Agusthia Netto
    Nov 11 at 12:27















up vote
0
down vote

favorite












 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;
}


----- in the EllipseParam class



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;
}


I try to setting parameter and getting that, but output I got is like this:



OpenCV: {196.5, 156.5}



wid:147.5



hei:147.5



Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException



value on EllipseParam: entity.EllipseParam@d34c4b



What is wrong with my code?



I read the answer, but its not solve my issue actually. Can you explain to me more?










share|improve this question
























  • Please show the complete stack trace. At the moment we can't tell enough about where the exception is being thrown.
    – Jon Skeet
    Nov 11 at 12:20










  • Why do you return null from the method?
    – Michael Dz
    Nov 11 at 12:21










  • @JonSkeet oke I try.
    – Winda Agusthia Netto
    Nov 11 at 12:27










  • @MichaelDz I tried to apply somecode for different result from my original code I made...but the reason I not really know
    – Winda Agusthia Netto
    Nov 11 at 12:27













up vote
0
down vote

favorite









up vote
0
down vote

favorite











 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;
}


----- in the EllipseParam class



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;
}


I try to setting parameter and getting that, but output I got is like this:



OpenCV: {196.5, 156.5}



wid:147.5



hei:147.5



Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException



value on EllipseParam: entity.EllipseParam@d34c4b



What is wrong with my code?



I read the answer, but its not solve my issue actually. Can you explain to me more?










share|improve this question















 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;
}


----- in the EllipseParam class



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;
}


I try to setting parameter and getting that, but output I got is like this:



OpenCV: {196.5, 156.5}



wid:147.5



hei:147.5



Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException



value on EllipseParam: entity.EllipseParam@d34c4b



What is wrong with my code?



I read the answer, but its not solve my issue actually. Can you explain to me more?







java opencv error-handling nullpointerexception netbeans-8






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 12:33

























asked Nov 11 at 12:18









Winda Agusthia Netto

155




155












  • Please show the complete stack trace. At the moment we can't tell enough about where the exception is being thrown.
    – Jon Skeet
    Nov 11 at 12:20










  • Why do you return null from the method?
    – Michael Dz
    Nov 11 at 12:21










  • @JonSkeet oke I try.
    – Winda Agusthia Netto
    Nov 11 at 12:27










  • @MichaelDz I tried to apply somecode for different result from my original code I made...but the reason I not really know
    – Winda Agusthia Netto
    Nov 11 at 12:27


















  • Please show the complete stack trace. At the moment we can't tell enough about where the exception is being thrown.
    – Jon Skeet
    Nov 11 at 12:20










  • Why do you return null from the method?
    – Michael Dz
    Nov 11 at 12:21










  • @JonSkeet oke I try.
    – Winda Agusthia Netto
    Nov 11 at 12:27










  • @MichaelDz I tried to apply somecode for different result from my original code I made...but the reason I not really know
    – Winda Agusthia Netto
    Nov 11 at 12:27
















Please show the complete stack trace. At the moment we can't tell enough about where the exception is being thrown.
– Jon Skeet
Nov 11 at 12:20




Please show the complete stack trace. At the moment we can't tell enough about where the exception is being thrown.
– Jon Skeet
Nov 11 at 12:20












Why do you return null from the method?
– Michael Dz
Nov 11 at 12:21




Why do you return null from the method?
– Michael Dz
Nov 11 at 12:21












@JonSkeet oke I try.
– Winda Agusthia Netto
Nov 11 at 12:27




@JonSkeet oke I try.
– Winda Agusthia Netto
Nov 11 at 12:27












@MichaelDz I tried to apply somecode for different result from my original code I made...but the reason I not really know
– Winda Agusthia Netto
Nov 11 at 12:27




@MichaelDz I tried to apply somecode for different result from my original code I made...but the reason I not really know
– Winda Agusthia Netto
Nov 11 at 12:27

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248684%2fi-got-null-parameter-in-java-when-i-try-to-apply-opencv%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248684%2fi-got-null-parameter-in-java-when-i-try-to-apply-opencv%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Full-time equivalent

Bicuculline

さくらももこ