java代码识别人物照 java识别图片

java课程设计(证件照应用,包括人脸识别,裁剪,压缩等的)求实验总结

public BufferedImage replaceWithWhiteColor(BufferedImage bi) {

创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站设计、成都网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的垣曲网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

int[] rgb = new int[3];

int width = bi.getWidth();

int height = bi.getHeight();

int minx = bi.getMinX();

int miny = bi.getMinY();

/**

* 遍历图片的像素,为处理图片上的杂色,所以要把指定像素上的颜色换成目标白色 用二层循环遍历长和宽上的每个像素

*/

int hitCount = 0;

for (int i = minx; i width-1; i++) {

for (int j = miny; j height; j++) {

/**

* 得到指定像素(i,j)上的RGB值,

*/

int pixel = bi.getRGB(i, j);

int pixelNext = bi.getRGB(i+1, j);

/**

* 分别进行位操作得到 r g b上的值

*/

rgb[0] = (pixel 0xff0000) 16;

rgb[1] = (pixel 0xff00) 8;

rgb[2] = (pixel 0xff);

/**

* 进行换色操作,我这里是要换成白底,那么就判断图片中rgb值是否在范围内的像素

*/

//经过不断尝试,RGB数值相互间相差15以内的都基本上是灰色,

//对以身份证来说特别是介于73到78之间,还有大于100的部分RGB值都是干扰色,将它们一次性转变成白色

if ((Math.abs(rgb[0] - rgb[1]) 15)

(Math.abs(rgb[0] - rgb[2]) 15)

(Math.abs(rgb[1] - rgb[2]) 15)

(((rgb[0] 73) (rgb[0] 78))||(rgb[0] 100))) {

//进行换色操作,0xffffff是白色

bi.setRGB(i, j, 0xffffff);

}

}

}

java代码 如何实现角色换衣服 如果有一张图片怎么实现帮人物图片换衣服

恩,简单的实现

思路:提供各个人穿各种样子的图片 比如3个人,4种衣服 12张图片预先设置好。然后获取 人和衣服的值给相应的图片就好

稍微复杂的实现

将人的图片设置被背景,衣服如果分上下衣(就分成DIV1/2),衣服做成PNG模式,放在DIV1/2里,主要衣服的位置准确性,这样用2个JS就可以实现 1个换背景 1个换衣服。

最最复杂的实现,用java画图。

这个,一般不做考虑,除非用来生成图表.

2是最好的,排好位置就行。但和java无关。

有很多东西,可以用简单的方式来完成,没有必要用JAVA,打个比方,你削铅笔时,会想到去用杀猪刀削还是铅笔刀?

如何开发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代码识别人物照 java识别图片
当前网址:http://scyanting.com/article/hgesch.html