A
A
AwvuweWd2020-01-03 02:59:41
Java
AwvuweWd, 2020-01-03 02:59:41

How to cut object in opencv by 4 points?

I read the picture, find the object:
Mat src = Imgcodecs.imread(filepathString);
MatOfRect faceDetection = new MatOfRect();
csc.detectMultiScale(src, faceDetection);
I work with each found object (I add a frame, but I need to cut out the object):
for (Rect rect : faceDetection.toArray()) {
try {
Imgproc.rectangle(src, new Point(rect.x, rect.y), new Point (rect.x + rect.width, rect.y + rect.height),new Scalar(0, 0, 255), 3);
if (!dirDetected.exists()) {
dirDetected.mkdirs();
}
Imgcodecs.imwrite(((dirDetected.toString() + File.separatorChar + (FilenameUtils.getBaseName(filepathString))+ '.' + FilenameUtils.getExtension(filepathString))),src);
} catch (Exception e) {
e.printStackTrace();
}
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question