videocapture的下一帧是当前拍下的还是之前缓存的
1个回答
2017-05-31
展开全部
整个项目的结构图:编写DetectFaceDemo.java,代码如下:[java]viewplaincopyprint?packagecom.njupt.zhb.test;importorg.opencv.core.Core;importorg.opencv.core.Mat;importorg.opencv.core.MatOfRect;importorg.opencv.core.Point;importorg.opencv.core.Rect;importorg.opencv.core.Scalar;importorg.opencv.highgui.Highgui;importorg.opencv.objdetect.CascadeClassifier;////Detectsfacesinanimage,drawsboxesaroundthem,andwritestheresults//to"faceDetection.png".//publicclassDetectFaceDemo{publicvoidrun(){System.out.println("\nRunningDetectFaceDemo");System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath());//Createafacedetectorfromthecascadefileintheresources//directory.//CascadeClassifierfaceDetector=newCascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath());//Matimage=Highgui.imread(getClass().getResource("lena.png").getPath());//注意:源程序的路径会多打印一个‘/’,因此总是出现如下错误/**Detected0facesWritingfaceDetection.pnglibpngwarning:Image*widthiszeroinIHDRlibpngwarning:ImageheightiszeroinIHDR*libpngerror:InvalidIHDRdata*///因此,我们将第一个字符去掉StringxmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1);CascadeClassifierfaceDetector=newCascadeClassifier(xmlfilePath);Matimage=Highgui.imread(getClass().getResource("we.jpg").getPath().substring(1));//Detectfacesintheimage.//MatOfRectisaspecialcontainerclassforRect.MatOfRectfaceDetections=newMatOfRect();faceDetector.detectMultiScale(image,faceDetections);System.out.println(String.format("Detected%sfaces",faceDetections.toArray().length));//Drawaboundingboxaroundeachface.for(Rectrect:faceDetections.toArray()){Core.rectangle(image,newPoint(rect.x,rect.y),newPoint(rect.x+rect.width,rect.y+rect.height),newScalar(0,255,0));}//Savethevisualizeddetection.Stringfilename="faceDetection.png";System.out.println(String.format("Writing%s",filename));Highgui.imwrite(filename,image);}}packagecom.njupt.zhb.test;importorg.opencv.core.Core;importorg.opencv.core.Mat;importorg.opencv.core.MatOfRect;importorg.opencv.core.Point;importorg.opencv.core.Rect;importorg.opencv.core.Scalar;importorg.opencv.highgui.Highgui;importorg.opencv.objdetect.CascadeClassifier;////Detectsfacesinanimage,drawsboxesaroundthem,andwritestheresults//to"faceDetection.png".//publicclassDetectFaceDemo{publicvoidrun(){System.out.println("\nRunningDetectFaceDemo");System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath());//Createafacedetectorfromthecascadefileintheresources//directory.//CascadeClassifierfaceDetector=newCascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath());//Matimage=Highgui.imread(getClass().getResource("lena.png").getPath());//注意:源程序的路径会多打印一个‘/’,因此总是出现如下错误/**Detected0facesWritingfaceDetection.pnglibpngwarning:Image*widthiszeroinIHDRlibpngwarning:ImageheightiszeroinIHDR*libpngerror:InvalidIHDRdata*///因此,我们将第一个字符去掉StringxmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1);CascadeClassifierfaceDetector=newCascadeClassifier(xmlfilePath);Matimage=Highgui.imread(getClass().getResource("we.jpg").getPath().substring(1));//Detectfacesintheimage.//MatOfRectisaspecialcontainerclassforRect.MatOfRectfaceDetections=newMatOfRect();faceDetector.detectMultiScale(image,faceDetections);System.out.println(String.format("Detected%sfaces",faceDetections.toArray().length));//Drawaboundingboxaroundeachface.for(Rectrect:faceDetections.toArray()){Core.rectangle(image,newPoint(rect.x,rect.y),newPoint(rect.x+rect.width,rect.y+rect.height),newScalar(0,255,0));}//Savethevisualizeddetection.Stringfilename="faceDetection.png";System.out.println(String.format("Writing%s",filename));Highgui.imwrite(filename,image);}}3.编写测试类:[java]viewplaincopyprint?packagecom.njupt.zhb.test;publicclassTestMain{publicstaticvoidmain(String[]args){System.out.println("Hello,OpenCV");//Loadthenativelibrary.System.loadLibrary("opencv_java246");newDetectFaceDemo().run();}}//运行结果://Hello,OpenCV////RunningDetectFaceDemo///E:/eclipse_Jee/workspace/JavaOpenCV246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml//Detected8faces//WritingfaceDetection.pngpackagecom.njupt.zhb.test;publicclassTestMain{publicstaticvoidmain(String[]args){System.out.println("Hello,OpenCV");//Loadthenativelibrary.System.loadLibrary("opencv_java246");newDetectFaceDemo().run();}}//运行结果://Hello,OpenCV////RunningDetectFaceDemo///E:/eclipse_Jee/workspace/JavaOpenCV246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml//Detected8faces//WritingfaceDetection.png
瑞地测控
2024-08-12 广告
2024-08-12 广告
在苏州瑞地测控技术有限公司,我们专注于提供高集成度的视频监控系统解决方案。摄像头视频注入技术作为其中的重要一环,通过精密算法优化视频流,确保监控画面清晰无延迟地融入系统,提升整体监控效能与实时性。该技术不仅增强了监控画面的连贯性,还强化了系...
点击进入详情页
本回答由瑞地测控提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询