编写森段并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
本文通过对OpenCV中图像类型和函数处理方法的介绍,通过设计实例描述在vivadoHLS中调用OpenCV库函数实现图像处理的几个基本皮谨巧步骤,完成从OpenCV设计到RTL转换综合的开发流程。开源计算机视觉 (OpenCV) 被广泛用于开发计算机视觉应用,它包含2500多个优化的燃键视频函数的函数库并且专门针对台式机处理器和GPU进行优化。OpenCV的用户成千上万,OpenCV的设计无需修改即可在 Zynq器件的ARM处理器上运行。但是利用OpenCV实现的高清处理经常受外部存储器的限制,尤其是存储带宽会成为性能瓶颈,存储访问也会限制功耗效率。使用VivadoHLS高级语言综合工具,可以轻松实现OpenCV C++视频处理设计到RTL代码的转晌宴换,输出硬件加速或者直接在FPGA上实现实时视频处理功能。同时,Zynq All-programmable SOC是实现嵌入式计算机视觉应用的极好方法,很好解决了在单一处理器上实现视频处理性能低功耗高的限制,Zynq高性能可编程逻辑和嵌入式ARM内核,是一款功耗优化的集成式解决方案。
1 OpenCV中图像IplImage, CvMat, Mat 类型的关系和VivadoHLS中图像hls::Mat类型介绍
OpenCv中常见的与图像 *** 作有关的数据容器有Mat,cvMat和IplImage,这三种类型都可以代表和显示图像,但是,Mat类型侧重于计算,数学性较高,openCV对Mat类型的计算也进行了优化。而CvMat和IplImage类型更侧重于“图像”,opencv对其中的图像 *** 作(缩放、单通道提取、图像阈值 *** 作等)进行了优化。在opencv2.0之前,opencv是完全用C实现的,但是,IplImage类型与CvMat类型的关系类似于面向对象中的继承关系。实际上,CvMat之上还有一个更抽象的基类----CvArr,这在源代码中会常见。
1.1 OpenCV中Mat类型:矩阵类型(Matrix)。
回归正题,首先放出漏带念我参考的几个文件:ug871、ug902、xapp1167(它的参考设计文件对我帮助最大)还有这篇文章 http://www.eepw.com.cn/article/234670.htm
在hls中使行冲用opencv大体的结构是这样的,在需要综合的文件中包含 hls_video.h文件,这里面有的就是能使用的图像处理相关的函数,在testbench中可以包含opencv或opencv2的头文件,在testbench中使用opencv读取本地图片或视频流,转换成axi的的流文件,使用测试函数处理,返回的也是axi流,将其转换成mat或iplimage等形式用opencv显示出来,这样就能看出被综合文件的功能性。返困在实际设计时testbench对应的就是摄像头
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)