java画脸代码 java实现简单的人脸识别

用java编写一个颜色为红色,粗线型的笑脸和哭脸,需要继承JFrame类,用java中的绘制图形做

JFreeChart------------它是一种组件技术,专用于在java中实现图形报表

成都创新互联是一家专注于成都网站建设、做网站与策划设计,东方网站建设哪家好?成都创新互联做网站,专注于网站建设十余年,网设计领域的专业建站公司;建站业务涵盖:东方等地区。东方做网站价格咨询:13518219792

----------饼图,柱状图,折线图

JFreeChart它是一种独立图表技术,它与struts2本身并无关系,只不过,它可以与struts2配合使用

饼图的步骤:

1、创建一个web工程

2、导入struts2框架(core,struts2-jfreeChart)

3、向工程导入(jfreechart.jar,jcommon.jar)

4、创建BaseAction继承于ActionSupport,并且,在类中,声明一个属性 JFreeChart chart;并且生成set,get方法

5、编写ChartAction类,继承于BaseAction

6、在ChartAction类中,编写 showPie()用于显示饼图

7、在struts.xml配置当前action

8、在index.jsp配置,通过img src="chart!showPie.action"进入到指定方法

=================================================================================================================

9、编写ChartDao类,模拟从数据库查询数据

//得到饼图需要的数据集

public DefaultPieDataset getPieDataset(){

DefaultPieDataset dp = new DefaultPieDataset();

dp.setValue("联想",321);

dp.setValue("华硕",189);

dp.setValue("戴尔",98);

dp.setValue("IBM",213);

dp.setValue("Apple",287);

dp.setValue("惠普",120);

dp.setValue("SONY",87);

return dp;

}

==============================================================================================================

10、在ChartAction中的showPie方法,生成饼图

public String showPie(){

//得以要显示的数据集,根据数据,生成饼图

DefaultPieDataset dp = dao.getPieDataset();

//chart = ChartFactory.createPieChart("标题",要显示在饼图中的数据集,是否显示颜色说明,"是否显示工具提示","是否显示网络地址 ");

chart = ChartFactory.createPieChart("一季度各电脑品牌销售汇总",dp,true,false,false);

return "success";

}

=============================================================================================================

11、在struts.xml文件,进行相关配置

package name="struts2" extends="struts-default"

result-types

result-type name="chart" class="org.apache.struts2.dispatcher.ChartResult"/

/result-types

action name="chart" class="org.java.web.ChartAction"

result name="success" type="chart"

param name="width"800/param

param name="height"600/param

/result

/action

/package

=================================================================================================================

12、解决乱码

标题区的乱码

Font f1 = new Font("隶书",Font.BOLD,40);

TextTitle tt = new TextTitle("一季度各电脑品牌销售汇总",f1);

chart.setTitle(tt);//绑定标题

颜色提示区乱码

Font f2 = new Font("隶书",Font.BOLD,20);

LegendTitle lt = chart.getLegend();

lt.setItemFont(f2);//设置该区域的字体

解决饼图中的乱码

PiePlot pp = (PiePlot) chart.getPlot();//得到饼图区域

pp.setLabelFont(f2);//设置饼图区域中的字体

=============================================================================================================

13、设置饼图中要显示的数据格式

//该对象,用于指定饼图要显示的数据格式 //0:key //1:value 2:百分比

StandardPieSectionLabelGenerator sc = new StandardPieSectionLabelGenerator("{0},{1}台,{2}");

//把显示的格式,绑定饼图中

pp.setLabelGenerator(sc);

需要完整版请联系我

如何开发Java动态人脸识别

1.环境搭建

整个项目的结构图

2.编写DetectFaceDemo.java,代码如下:

[java] view plaincopy

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 plaincopy

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

用Java画人脸

完整代码如下:

import java.awt.Dimension;

import java.awt.Graphics;

import java.awt.Toolkit;

import javax.swing.JFrame;

public class Face extends JFrame  {

/**

*

*/

private static final long serialVersionUID = 1L;

public Face(){

setSize(500, 500);

setResizable(false);

setDefaultCloseOperation(EXIT_ON_CLOSE);

Dimension screenSize = Toolkit.getDefaultToolkit()

.getScreenSize();

Dimension frameSize = getSize();

setLocation((screenSize.width - frameSize.width) / 2,

(screenSize.height - frameSize.height) / 2);

setVisible(true);

}

//下面的是关键的绘图代码

public void paint(Graphics g){

//画头

g.drawOval(100, 50, 300, 400);

//画眼睛

g.drawOval(140, 150, 100, 50);

g.drawOval(260, 150, 100, 50);

//画鼻子

g.drawArc(140, 150, 100, 150, -90, 90);

g.drawArc(260, 150, 100, 150, 180, 90);

//画嘴巴

g.drawOval(170, 320, 150, 50);

}

public static void main(String args[]){

new Face();

}

}

主要是用了几个java的画图函数,如果有用的话,希望采纳


网页题目:java画脸代码 java实现简单的人脸识别
本文地址:http://scyanting.com/article/ddcpchi.html