How to setting cropping size in CascadeCalssifier with Java











up vote
1
down vote

favorite












public BufferedImage detectAndDisplay(BufferedImage img, CascadeClassifier faceCascade) {
Mat frameGray = new Mat();
BufferedImage imgout = null;

Mat image = ImagePreProcessing.bufferedImageToMat(img);

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

List<Rect> listOfFaces = faces.toList();
for (Rect face : listOfFaces) {
Point center = new Point(face.x + face.width / 2, face.y + face.height / 2);
Imgproc.ellipse(image, center, new Size(face.width / 2, face.height / 2), 0, 0, 360,
new Scalar(255, 0, 255), 3);

Mat faceROI = image.submat(face);
imgout = ImagePreProcessing.Mat2BufferedImage(faceROI);
System.out.println("OpenCV: " +center);

}
return imgout;
}


that code I have..but I don't know where the code for setting crop output image.
I want to have the picture like original version with circle template..NOT to be crop
Can give me suggestion, please:)



input: input



output: output










share|improve this question
























  • Your question is not clear, what are you asking, at the end what result do you want to get?
    – Bahramdun Adil
    Nov 10 at 13:50










  • Thank you for your attention @BahramdunAdil .I want NOT the picture to be crop. I want the picture still in its size (size_input = size_output)
    – Winda Agusthia Netto
    Nov 10 at 13:53















up vote
1
down vote

favorite












public BufferedImage detectAndDisplay(BufferedImage img, CascadeClassifier faceCascade) {
Mat frameGray = new Mat();
BufferedImage imgout = null;

Mat image = ImagePreProcessing.bufferedImageToMat(img);

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

List<Rect> listOfFaces = faces.toList();
for (Rect face : listOfFaces) {
Point center = new Point(face.x + face.width / 2, face.y + face.height / 2);
Imgproc.ellipse(image, center, new Size(face.width / 2, face.height / 2), 0, 0, 360,
new Scalar(255, 0, 255), 3);

Mat faceROI = image.submat(face);
imgout = ImagePreProcessing.Mat2BufferedImage(faceROI);
System.out.println("OpenCV: " +center);

}
return imgout;
}


that code I have..but I don't know where the code for setting crop output image.
I want to have the picture like original version with circle template..NOT to be crop
Can give me suggestion, please:)



input: input



output: output










share|improve this question
























  • Your question is not clear, what are you asking, at the end what result do you want to get?
    – Bahramdun Adil
    Nov 10 at 13:50










  • Thank you for your attention @BahramdunAdil .I want NOT the picture to be crop. I want the picture still in its size (size_input = size_output)
    – Winda Agusthia Netto
    Nov 10 at 13:53













up vote
1
down vote

favorite









up vote
1
down vote

favorite











public BufferedImage detectAndDisplay(BufferedImage img, CascadeClassifier faceCascade) {
Mat frameGray = new Mat();
BufferedImage imgout = null;

Mat image = ImagePreProcessing.bufferedImageToMat(img);

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

List<Rect> listOfFaces = faces.toList();
for (Rect face : listOfFaces) {
Point center = new Point(face.x + face.width / 2, face.y + face.height / 2);
Imgproc.ellipse(image, center, new Size(face.width / 2, face.height / 2), 0, 0, 360,
new Scalar(255, 0, 255), 3);

Mat faceROI = image.submat(face);
imgout = ImagePreProcessing.Mat2BufferedImage(faceROI);
System.out.println("OpenCV: " +center);

}
return imgout;
}


that code I have..but I don't know where the code for setting crop output image.
I want to have the picture like original version with circle template..NOT to be crop
Can give me suggestion, please:)



input: input



output: output










share|improve this question















public BufferedImage detectAndDisplay(BufferedImage img, CascadeClassifier faceCascade) {
Mat frameGray = new Mat();
BufferedImage imgout = null;

Mat image = ImagePreProcessing.bufferedImageToMat(img);

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

List<Rect> listOfFaces = faces.toList();
for (Rect face : listOfFaces) {
Point center = new Point(face.x + face.width / 2, face.y + face.height / 2);
Imgproc.ellipse(image, center, new Size(face.width / 2, face.height / 2), 0, 0, 360,
new Scalar(255, 0, 255), 3);

Mat faceROI = image.submat(face);
imgout = ImagePreProcessing.Mat2BufferedImage(faceROI);
System.out.println("OpenCV: " +center);

}
return imgout;
}


that code I have..but I don't know where the code for setting crop output image.
I want to have the picture like original version with circle template..NOT to be crop
Can give me suggestion, please:)



input: input



output: output







java image opencv face-detection cascade-classifier






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 14:04

























asked Nov 10 at 12:47









Winda Agusthia Netto

155




155












  • Your question is not clear, what are you asking, at the end what result do you want to get?
    – Bahramdun Adil
    Nov 10 at 13:50










  • Thank you for your attention @BahramdunAdil .I want NOT the picture to be crop. I want the picture still in its size (size_input = size_output)
    – Winda Agusthia Netto
    Nov 10 at 13:53


















  • Your question is not clear, what are you asking, at the end what result do you want to get?
    – Bahramdun Adil
    Nov 10 at 13:50










  • Thank you for your attention @BahramdunAdil .I want NOT the picture to be crop. I want the picture still in its size (size_input = size_output)
    – Winda Agusthia Netto
    Nov 10 at 13:53
















Your question is not clear, what are you asking, at the end what result do you want to get?
– Bahramdun Adil
Nov 10 at 13:50




Your question is not clear, what are you asking, at the end what result do you want to get?
– Bahramdun Adil
Nov 10 at 13:50












Thank you for your attention @BahramdunAdil .I want NOT the picture to be crop. I want the picture still in its size (size_input = size_output)
– Winda Agusthia Netto
Nov 10 at 13:53




Thank you for your attention @BahramdunAdil .I want NOT the picture to be crop. I want the picture still in its size (size_input = size_output)
– Winda Agusthia Netto
Nov 10 at 13:53












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










In your code, you returned a cropped image of the original image, so if you want the original image, draw the circle and convert it to the BufferedImage and return.



for (Rect face : listOfFaces) {
Point center = new Point(face.x + face.width / 2, face.y + face.height / 2);
Imgproc.ellipse(image, center, new Size(face.width / 2, face.height / 2), 0, 0, 360,
new Scalar(255, 0, 255), 3);

// dot not crop!!!
/*Mat faceROI = image.submat(face);
imgout = ImagePreProcessing.Mat2BufferedImage(faceROI);*/

System.out.println("OpenCV: " +center);
imgout = ImagePreProcessing.Mat2BufferedImage(image);

}





share|improve this answer





















  • I got it!!! YES its work @BahramdunAdil thank you very much:)
    – Winda Agusthia Netto
    Nov 10 at 15:34











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',
autoActivateHeartbeat: false,
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%2f53239100%2fhow-to-setting-cropping-size-in-cascadecalssifier-with-java%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










In your code, you returned a cropped image of the original image, so if you want the original image, draw the circle and convert it to the BufferedImage and return.



for (Rect face : listOfFaces) {
Point center = new Point(face.x + face.width / 2, face.y + face.height / 2);
Imgproc.ellipse(image, center, new Size(face.width / 2, face.height / 2), 0, 0, 360,
new Scalar(255, 0, 255), 3);

// dot not crop!!!
/*Mat faceROI = image.submat(face);
imgout = ImagePreProcessing.Mat2BufferedImage(faceROI);*/

System.out.println("OpenCV: " +center);
imgout = ImagePreProcessing.Mat2BufferedImage(image);

}





share|improve this answer





















  • I got it!!! YES its work @BahramdunAdil thank you very much:)
    – Winda Agusthia Netto
    Nov 10 at 15:34















up vote
0
down vote



accepted










In your code, you returned a cropped image of the original image, so if you want the original image, draw the circle and convert it to the BufferedImage and return.



for (Rect face : listOfFaces) {
Point center = new Point(face.x + face.width / 2, face.y + face.height / 2);
Imgproc.ellipse(image, center, new Size(face.width / 2, face.height / 2), 0, 0, 360,
new Scalar(255, 0, 255), 3);

// dot not crop!!!
/*Mat faceROI = image.submat(face);
imgout = ImagePreProcessing.Mat2BufferedImage(faceROI);*/

System.out.println("OpenCV: " +center);
imgout = ImagePreProcessing.Mat2BufferedImage(image);

}





share|improve this answer





















  • I got it!!! YES its work @BahramdunAdil thank you very much:)
    – Winda Agusthia Netto
    Nov 10 at 15:34













up vote
0
down vote



accepted







up vote
0
down vote



accepted






In your code, you returned a cropped image of the original image, so if you want the original image, draw the circle and convert it to the BufferedImage and return.



for (Rect face : listOfFaces) {
Point center = new Point(face.x + face.width / 2, face.y + face.height / 2);
Imgproc.ellipse(image, center, new Size(face.width / 2, face.height / 2), 0, 0, 360,
new Scalar(255, 0, 255), 3);

// dot not crop!!!
/*Mat faceROI = image.submat(face);
imgout = ImagePreProcessing.Mat2BufferedImage(faceROI);*/

System.out.println("OpenCV: " +center);
imgout = ImagePreProcessing.Mat2BufferedImage(image);

}





share|improve this answer












In your code, you returned a cropped image of the original image, so if you want the original image, draw the circle and convert it to the BufferedImage and return.



for (Rect face : listOfFaces) {
Point center = new Point(face.x + face.width / 2, face.y + face.height / 2);
Imgproc.ellipse(image, center, new Size(face.width / 2, face.height / 2), 0, 0, 360,
new Scalar(255, 0, 255), 3);

// dot not crop!!!
/*Mat faceROI = image.submat(face);
imgout = ImagePreProcessing.Mat2BufferedImage(faceROI);*/

System.out.println("OpenCV: " +center);
imgout = ImagePreProcessing.Mat2BufferedImage(image);

}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 10 at 14:40









Bahramdun Adil

3,26241745




3,26241745












  • I got it!!! YES its work @BahramdunAdil thank you very much:)
    – Winda Agusthia Netto
    Nov 10 at 15:34


















  • I got it!!! YES its work @BahramdunAdil thank you very much:)
    – Winda Agusthia Netto
    Nov 10 at 15:34
















I got it!!! YES its work @BahramdunAdil thank you very much:)
– Winda Agusthia Netto
Nov 10 at 15:34




I got it!!! YES its work @BahramdunAdil thank you very much:)
– Winda Agusthia Netto
Nov 10 at 15:34


















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%2f53239100%2fhow-to-setting-cropping-size-in-cascadecalssifier-with-java%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







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()