【问题标题】:How to setting cropping size in CascadeCalssifier with Java如何使用 Java 在 CascadeClassifier 中设置裁剪大小
【发布时间】:2019-04-13 19:30:18
【问题描述】:
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;
}

我有那个代码..但我不知道设置裁剪输出图像的代码在哪里。 我想要像原始版本一样带有圆形模板的图片..不要被裁剪 可以给我建议吗:)

输入:

输出:

【问题讨论】:

  • 你的问题不清楚,你在问什么,最后你想得到什么结果?
  • 感谢您的关注@BahramdunAdil。我不想裁剪图片。我希望图片保持其大小(size_input = size_output)

标签: java image opencv face-detection cascade-classifier


【解决方案1】:

在您的代码中,您返回了原始图像的裁剪图像,因此如果您想要原始图像,请绘制圆圈并将其转换为 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);

    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-02
    • 1970-01-01
    • 2013-08-21
    • 1970-01-01
    • 2019-04-29
    • 1970-01-01
    相关资源
    最近更新 更多