模板匹配java中的多个对象

问题描述

我正在使用 openCV 进行模板匹配,以下代码仅响应图像上检测到的对象的一个​​位置。但我想看看图像中是否有另一个模板,最后根据它们在照片中的位置生成检测到的对象列表。

        Mat source=null;
        Mat template=null;
        String filePath="C:\\Users\\Mohamad Jahangiri\\IdeaProjects\\WiringProject\\src\\sample\\Image\\" ;
        String templateFilePath="C:\\Users\\Mohamad Jahangiri\\IdeaProjects\\WiringProject\\src\\sample\\templates\\" ;
        //Load image file
        source=Imgcodecs.imread(filePath+"1.jpg");
        template=Imgcodecs.imread(templateFilePath+"key1.jpg");

        Mat outputimage=new Mat();
        int machMethod=Imgproc.TM_CCOEFF;
        //Template matching method
       Imgproc.matchTemplate(source,template,outputimage,machMethod);


        Core.MinMaxLocResult mmr = Core.minMaxLoc(outputimage);
        Point matchLoc=mmr.maxLoc;
        //Draw rectangle on result image
        System.out.println(" template.rows() "+ template.rows() + "");
        Imgproc.rectangle(source,matchLoc,new Point(matchLoc.x + template.cols(),matchLoc.y + template.rows()),new Scalar(255,255,255));

        System.out.println("( " +matchLoc.x + "," +matchLoc.y );

        Imgcodecs.imwrite(filePath+"sonuc.jpg",source);
        System.out.println("Complated.");



我想知道是否有更好的检测对象的库,例如简单的正方形和矩形

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)