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
    2 days ago










  • 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
    2 days ago















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
    2 days ago










  • 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
    2 days ago













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 2 days ago

























asked 2 days ago









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
    2 days ago










  • 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
    2 days ago


















  • Your question is not clear, what are you asking, at the end what result do you want to get?
    – Bahramdun Adil
    2 days ago










  • 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
    2 days ago
















Your question is not clear, what are you asking, at the end what result do you want to get?
– Bahramdun Adil
2 days ago




Your question is not clear, what are you asking, at the end what result do you want to get?
– Bahramdun Adil
2 days ago












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
2 days ago




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
2 days ago












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
    2 days ago











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

Post as a guest
































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
    2 days ago















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
    2 days ago













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 2 days ago









Bahramdun Adil

3,23441744




3,23441744












  • I got it!!! YES its work @BahramdunAdil thank you very much:)
    – Winda Agusthia Netto
    2 days ago


















  • I got it!!! YES its work @BahramdunAdil thank you very much:)
    – Winda Agusthia Netto
    2 days ago
















I got it!!! YES its work @BahramdunAdil thank you very much:)
– Winda Agusthia Netto
2 days ago




I got it!!! YES its work @BahramdunAdil thank you very much:)
– Winda Agusthia Netto
2 days ago


















 

draft saved


draft discarded



















































 


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