java opencv 之车辆识别

上篇写了人脸识别,因为人脸识别的训练模型 haarcascade_frontalface_alt.xml 之类的官方已经训练好了可以直接用,但是我们要识别车辆或者其它物体就得训练模型,好在废了一点力 找到了一位大神训练好的模型

 

 核心代码 几乎和人脸识别的差不多

static CascadeClassifier carDetector;

    static {
        try {

            NativeLoader.loader();
            String path = System.getProperty("user.dir").concat("/classifier/car/cars.xml");
            carDetector = new CascadeClassifier(path);
            if (carDetector.empty()) {
                System.out.println("cars.xml 文件加载失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static void main(String[] args) {

        Mat image = Imgcodecs.imread("D:/rr/car5.jpg");
        Mat hvs = new Mat();
        Imgproc.cvtColor(image,hvs,Imgproc.COLOR_BGR2GRAY);

        MatOfRect faceDetections = new MatOfRect();
        carDetector.detectMultiScale(image,faceDetections);

        System.out.println("监测到"+faceDetections.toArray().length+"辆车");
        for (Rect rect : faceDetections.toArray()) {
            Imgproc.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
        }
        Imgcodecs.imwrite("D:/rr/1-55.jpg", image);
        HighGui.imshow("车辆识别", image);
        System.exit(0);

 可以看到大部分车辆能识别到,估计是训练样本选的不够多得到的模型不过已经很棒了

付一个连接 级联分类器训练 

级联分类器训练 — OpenCV 2.3.2 documentation

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值