// 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
MATLAB的DCT变换 利用MATLAB对一副8×8的图像进行DTC变换,并保留20个DCT变换系数用matlab对一张图片进行DFT变换,DCT变换,比较保留20个DCT变换系数重构的图象与原始图像的差别.-Using matlab on a picture to DFT transform, DCT transform, compared to 20 DCT transform coefficients to retain ...
matlab 图像dct变换[A,map]=imread('******');
%显示原图
imshow(A,map),
title('原图');
image=double(A);
N=8;
for x=1,
a(x)=sqrt(1/N);
end,
for x=2:8,
a(x)=sqrt(2/N);
end,
%dct
rimage=zeros(8,8);
for x=1:32,
for y=1:32,
for u=1:N,
for v=1:N,
for i=1:N,
for j=1:N,
rimage(i,j)=image(i+(x-1)*8,j+(y-1)*8);
b(i,j)=rimage(i,j).*cos((2*(i-1)+1)*(u-1)*pi/(2*N)).*cos((2*(j-1)+1)*(v-1)*pi/(2*N));
end,
end,
推荐阅读
- 直播卖货技巧,直播卖货技巧和注意事项
- 微信上视频号怎么操作,微信上视频号怎么操作的
- 简单网站制作手工,手工网页
- excel怎么判断值为空,excl判断表格是否为空
- linux创建快捷键命令 linux 创建快捷命令
- pgadmin执行sql文件,pgadmin4如何执行sql
- chatgpt是啥板块,plate板块
- mysql怎么修改配置 在mysql中怎么修改数据
- jquery表单二级联动,html二级联动