永发信息网

2.4.8的opencv有imageclipper或objectmarker吗

答案:2  悬赏:0  手机版
解决时间 2021-02-18 10:40
  • 提问者网友:我一贱你就笑
  • 2021-02-18 02:45
2.4.8的opencv有imageclipper或objectmarker吗
最佳答案
  • 五星知识达人网友:动情书生
  • 2021-02-18 04:05
整个项目的结构图: 编写DetectFaceDemo.java,代码如下: [java] view plaincopyprint? package com.njupt.zhb.test; import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfRect; import org.opencv.core.Poi...
全部回答
  • 1楼网友:舊物识亽
  • 2021-02-18 04:26
整个项目的结构图: 编写detectfacedemo.java,代码如下: [java] view plaincopyprint? package com.njupt.zhb.test; import org.opencv.core.core; import org.opencv.core.mat; import org.opencv.core.matofrect; import org.opencv.core.point; import org.opencv.core.rect; import org.opencv.core.scalar; import org.opencv.highgui.highgui; import org.opencv.objdetect.cascadeclassifier; // // detects faces in an image, draws boxes around them, and writes the results // to "facedetection.png". // public class detectfacedemo { public void run() { system.out.println("\nrunning detectfacedemo"); system.out.println(getclass().getresource("lbpcascade_frontalface.xml").getpath()); // create a face detector from the cascade file in the resources // directory. //cascadeclassifier facedetector = new cascadeclassifier(getclass().getresource("lbpcascade_frontalface.xml").getpath()); //mat image = highgui.imread(getclass().getresource("lena.png").getpath()); //注意:源程序的路径会多打印一个‘/’,因此总是出现如下错误 //因此,我们将第一个字符去掉 string xmlfilepath=getclass().getresource("lbpcascade_frontalface.xml").getpath().substring(1); cascadeclassifier facedetector = new cascadeclassifier(xmlfilepath); mat image = highgui.imread(getclass().getresource("we.jpg").getpath().substring(1)); // detect faces in the image. // matofrect is a special container class for rect. matofrect facedetections = new matofrect(); facedetector.detectmultiscale(image, facedetections); system.out.println(string.format("detected %s faces", facedetections.toarray().length)); // draw a bounding box around each face. for (rect rect : facedetections.toarray()) { core.rectangle(image, new point(rect.x, rect.y), new point(rect.x + rect.width, rect.y + rect.height), new scalar(0, 255, 0)); } // save the visualized detection. string filename = "facedetection.png"; system.out.println(string.format("writing %s", filename)); highgui.imwrite(filename, image); } } package com.njupt.zhb.test; import org.opencv.core.core; import org.opencv.core.mat; import org.opencv.core.matofrect; import org.opencv.core.point; import org.opencv.core.rect; import org.opencv.core.scalar; import org.opencv.highgui.highgui; import org.opencv.objdetect.cascadeclassifier; // // detects faces in an image, draws boxes around them, and writes the results // to "facedetection.png". // public class detectfacedemo { public void run() { system.out.println("\nrunning detectfacedemo"); system.out.println(getclass().getresource("lbpcascade_frontalface.xml").getpath()); // create a face detector from the cascade file in the resources // directory. //cascadeclassifier facedetector = new cascadeclassifier(getclass().getresource("lbpcascade_frontalface.xml").getpath()); //mat image = highgui.imread(getclass().getresource("lena.png").getpath()); //注意:源程序的路径会多打印一个‘/’,因此总是出现如下错误 //因此,我们将第一个字符去掉 string xmlfilepath=getclass().getresource("lbpcascade_frontalface.xml").getpath().substring(1); cascadeclassifier facedetector = new cascadeclassifier(xmlfilepath); mat image = highgui.imread(getclass().getresource("we.jpg").getpath().substring(1)); // detect faces in the image. // matofrect is a special container class for rect. matofrect facedetections = new matofrect(); facedetector.detectmultiscale(image, facedetections); system.out.println(string.format("detected %s faces", facedetections.toarray().length)); // draw a bounding box around each face. for (rect rect : facedetections.toarray()) { core.rectangle(image, new point(rect.x, rect.y), new point(rect.x + rect.width, rect.y + rect.height), new scalar(0, 255, 0)); } // save the visualized detection. string filename = "facedetection.png"; system.out.println(string.format("writing %s", filename)); highgui.imwrite(filename, image); } } 3.编写测试类: [java] view plaincopyprint? package com.njupt.zhb.test; public class testmain { public static void main(string[] args) { system.out.println("hello, opencv"); // load the native library. system.loadlibrary("opencv_java246"); new detectfacedemo().run(); } } //运行结果: //hello, opencv // //running detectfacedemo ///e:/eclipse_jee/workspace/javaopencv246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml //detected 8 faces //writing facedetection.png package com.njupt.zhb.test; public class testmain { public static void main(string[] args) { system.out.println("hello, opencv"); // load the native library. system.loadlibrary("opencv_java246"); new detectfacedemo().run(); } } //运行结果: //hello, opencv // //running detectfacedemo ///e:/eclipse_jee/workspace/javaopencv246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml //detected 8 faces //writing facedetection.png
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯