繁体   English   中英

如何使用Java在CascadeCalssifier中设置裁剪大小

[英]How to setting cropping size in CascadeCalssifier with Java

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

该代码我有..但是我不知道设置裁剪输出图像的代码在哪里。 我想拥有带有圆圈模板的原始版本的图片。不要被剪裁,请给我建议:)

输入: 输入

输出: 输出

在您的代码中,您返回了原始图像的裁剪图像,因此,如果您想要原始图像,请绘制圆并将其转换为BufferedImage并返回。

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

    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM