求opencv视频中行人检测和追踪的c++代码

求opencv视频中行人检测和追踪的c++代码,第1张

整个项目的结构图:

编写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())

//注意:源程序的路径会多打印一个‘/’,因此总是出现如下错误

/*

* Detected 0 faces Writing faceDetection.png libpng warning: Image

* width is zero in IHDR libpng warning: Image height is zero in IHDR

* libpng error: Invalid IHDR data

*/

//因此,我们将第一个字符去掉

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())

//注意:源程序的路径会多打印一个‘/’,因此总是出现如下错误

/*

* Detected 0 faces Writing faceDetection.png libpng warning: Image

* width is zero in IHDR libpng warning: Image height is zero in IHDR

* libpng error: Invalid IHDR data

*/

//因此,我们将第一个字符去掉

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

便衣警察跟踪人的方式一般是通过隐蔽、秘密的方式进行,以不被跟踪对象发现。具体 *** 作方法可能因地区和情况而异,但通常包括以下几个方面:

1. 预先调查:便衣警察会在开始跟踪前对目标进行预先调查,了解其行动规律、活动范围等信息。

2. 身份伪装:为了避免被发现,便衣警察通常会身着普通服装或者与当地环境相符合的服饰,并且不携带明显的执法工具。

3. 使用技术手段:如使用无线电设备监听目标交流内容、安装GPS定位器追踪目标位置等。

4. 保持距离:为了避免引起怀疑和暴露自己的身份,便衣警察通常会保持一定距离并尽量避免直接接触目标。

需要注意的是,在执行任务时必须严格按照相关法律法规和程序进行 *** 作,并确保不损害公民合法权益。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11749588.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存