- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 Eclipse Indigo 上通过以下链接运行唇读代码:https://github.com/sagioto/LipReading/blob/master/lipreading-core/src/main/java/edu/lipreading/vision/NoMoreStickersFeatureExtractor.java
代码是:
package edu.lipreading.vision;
import static com.googlecode.javacv.cpp.opencv_core.IPL_DEPTH_8U;
import static com.googlecode.javacv.cpp.opencv_core.cvCircle;
import static com.googlecode.javacv.cpp.opencv_core.cvClearMemStorage;
import static com.googlecode.javacv.cpp.opencv_core.cvCreateImage;
import static com.googlecode.javacv.cpp.opencv_core.cvGetSeqElem;
import static com.googlecode.javacv.cpp.opencv_core.cvLoad;
import static com.googlecode.javacv.cpp.opencv_core.cvResetImageROI;
import static com.googlecode.javacv.cpp.opencv_core.cvSetImageROI;
import static com.googlecode.javacv.cpp.opencv_core.cvSize;
import static com.googlecode.javacv.cpp.opencv_imgproc.CV_COUNTER_CLOCKWISE;
import static com.googlecode.javacv.cpp.opencv_imgproc.CV_RGB2GRAY;
import static com.googlecode.javacv.cpp.opencv_imgproc.cvCvtColor;
import static com.googlecode.javacv.cpp.opencv_objdetect.CV_HAAR_FIND_BIGGEST_OBJECT;
import static com.googlecode.javacv.cpp.opencv_objdetect.cvHaarDetectObjects;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
import org.apache.commons.math3.linear.RealMatrix;
import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.cpp.opencv_core.CvMat;
import com.googlecode.javacv.cpp.opencv_core.CvMemStorage;
import com.googlecode.javacv.cpp.opencv_core.CvPoint;
import com.googlecode.javacv.cpp.opencv_core.CvRect;
import com.googlecode.javacv.cpp.opencv_core.CvScalar;
import com.googlecode.javacv.cpp.opencv_core.CvSeq;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import com.googlecode.javacv.cpp.opencv_objdetect;
import com.googlecode.javacv.cpp.opencv_objdetect.CvHaarClassifierCascade;
import edu.lipreading.Constants;
import edu.lipreading.Utils;
/**
* This FeatureExtractor extracts lip coordinates automatically by identifying user lips.
*/
public class NoMoreStickersFeatureExtractor extends AbstractFeatureExtractor{
private static final int RECT_VERTICAL_JUMP = 10;
private static final int RECT_FRAME_THRESHOLD = 5;
private final ExecutorService executor = Executors.newCachedThreadPool();
private IplImage manipulated;
private CvRect prev = new CvRect();
private CvHaarClassifierCascade classifier;
private CvMemStorage storage;
private int sideConfidence;
private int lowerConfidence;
private int upperConfidence;
private int rectFrameCount = 0;
public List<Integer> getPoints(IplImage grabbed) throws Exception {
int roiFix = grabbed.height() / -32;
sideConfidence = grabbed.width() / 128;
lowerConfidence = grabbed.height() / 128;
upperConfidence = grabbed.width() / 32;
if(manipulated == null)
manipulated = cvCreateImage(cvSize(grabbed.width(), grabbed.height()), IPL_DEPTH_8U, 1);
if(storage == null || classifier == null)
init();
cvClearMemStorage(storage);
cvCvtColor(grabbed, manipulated, CV_RGB2GRAY);
CvSeq mouths = cvHaarDetectObjects(manipulated, classifier, storage, 1.8, 13, CV_HAAR_FIND_BIGGEST_OBJECT);
CvRect r = new CvRect(cvGetSeqElem(mouths, 0));
if(r.isNull()){
return null;
} else if (prev.y() != 0 && rectFrameCount < RECT_FRAME_THRESHOLD){
if (Math.abs(r.y() - prev.y()) > RECT_VERTICAL_JUMP){
CvRect.memcpy(r, prev, prev.sizeof());
rectFrameCount++;
}
} else if (rectFrameCount >= RECT_FRAME_THRESHOLD){
rectFrameCount = 0;
}
CvRect.memcpy(prev, r, r.sizeof());
r.y(r.y() + roiFix);
final int x = r.x(), y = r.y();
cvSetImageROI(grabbed, r);
final CvMat mat = grabbed.asCvMat();
List<Future<int[]>> points = new Vector<Future<int[]>>();
final Future<double[][]> getH = executor.submit(new Callable<double[][]>() {
@Override
public double[][] call() throws Exception {
return getH(mat);
}
});
final Future<double[][]> getL = executor.submit(new Callable<double[][]>() {
@Override
public double[][] call() throws Exception {
return getL(mat);
}
});
final Future<double[][]> getLmini = executor.submit(new Callable<double[][]>() {
@Override
public double[][] call() throws Exception {
return Lmini(getL.get());
}
});
final Future<int[]> getRight = executor.submit(new Callable<int[]>() {
@Override
public int[] call() throws Exception {
return getRight(getL.get(), getLmini.get());
}
});
points.add(getRight);
final Future<int[]> getLeft = executor.submit(new Callable<int[]>() {
@Override
public int[] call() throws Exception {
return getLeft(getL.get(), getLmini.get());
}
});
points.add(getLeft);
final Future<int[]> getUpper = executor.submit(new Callable<int[]>() {
@Override
public int[] call() throws Exception {
return getUpper(getL.get(), getH.get(), getRight.get()[0], getLeft.get()[0]);
}
});
points.add(getUpper);
final Future<int[]> getLower = executor.submit(new Callable<int[]>() {
@Override
public int[] call() throws Exception {
return getLower(getL.get(), getUpper.get()[0]);
}
});
points.add(getLower);
List<Integer> frameCoordinates = new Vector<Integer>();
for (Future<int[]> point : points) {
int coordinateX = point.get()[0] + x, coordinateY = point.get()[1] + y;
frameCoordinates.add(coordinateX);
frameCoordinates.add(coordinateY);
}
cvResetImageROI(grabbed);
//cvRectangle(grabbed, cvPoint(x, y), cvPoint(x+r.width(), y+r.height()), CvScalar.GREEN, 1, CV_AA, 0);
return frameCoordinates;
}
/* public List<Integer> getPointsSingleThreaded(IplImage grabbed) throws Exception {
int roiFix = grabbed.height() / -32;
sideConfidence = grabbed.width() / 128;
lowerConfidence = grabbed.height() / 128;
upperConfidence = grabbed.width() / 32;
if(manipulated == null)
manipulated = cvCreateImage(cvSize(grabbed.width(), grabbed.height()), IPL_DEPTH_8U, 1);
if(storage == null || classifier == null)
init();
cvClearMemStorage(storage);
cvCvtColor(grabbed, manipulated, CV_RGB2GRAY);
CvSeq mouths = cvHaarDetectObjects(manipulated, classifier, storage, 1.8, 13, CV_HAAR_FIND_BIGGEST_OBJECT);
CvRect r = new CvRect(cvGetSeqElem(mouths, 0));
if(r.isNull()){
return null;
} else if (prev.y() != 0 && rectFrameCount < RECT_FRAME_THRESHOLD){
if (Math.abs(r.y() - prev.y()) > RECT_VERTICAL_JUMP){
CvRect.memcpy(r, prev, prev.sizeof());
rectFrameCount++;
}
} else if (rectFrameCount >= RECT_FRAME_THRESHOLD){
rectFrameCount = 0;
}
CvRect.memcpy(prev, r, r.sizeof());
r.y(r.y() + roiFix);
final int x = r.x(), y = r.y();
cvSetImageROI(grabbed, r);
final CvMat mat = grabbed.asCvMat();
List<Integer> frameCoordinates = new Vector<Integer>();
frameCoordinates.add(r.x());
frameCoordinates.add(r.x() + r.width());
frameCoordinates.add(r.y());
frameCoordinates.add(r.y() + r.height());
return frameCoordinates;
double[][] h = getH(mat);
double[][] l = getL(mat);
double[][] lmini = Lmini(l);
int[] right = getRight(l, lmini);
frameCoordinates.add(right[0] + x);
frameCoordinates.add(right[1] + y);
int[] left = getLeft(l, lmini);
frameCoordinates.add(left[0] + x);
frameCoordinates.add(left[1] + y);
int[] upper = getUpper(l, h, right[0], left[0]);
frameCoordinates.add(upper[0] + x);
frameCoordinates.add(upper[1] + y);
int[] lower = getLower(l, upper[0]);
frameCoordinates.add(lower[0] + x);
frameCoordinates.add(lower[1] + y);
cvResetImageROI(grabbed);
//cvRectangle(grabbed, cvPoint(x, y), cvPoint(x+r.width(), y+r.height()), CvScalar.GREEN, 1, CV_AA, 0);
return frameCoordinates;
}*/
private void init() throws Exception {
Loader.load(opencv_objdetect.class);
String fileNameFromUrl = Utils.getFileNameFromUrl(Constants.HAAR_CASCADE_MOUTH_FILE);
if(!new File(fileNameFromUrl).exists())
Utils.get(Constants.HAAR_CASCADE_MOUTH_FILE);
classifier = new CvHaarClassifierCascade(cvLoad(Utils.getFileNameFromUrl(fileNameFromUrl)));
storage = CvMemStorage.create();
}
@Override
public void paintCoordinates(IplImage grabbed,
List<Integer> frameCoordinates) {
if(frameCoordinates != null){
for (int i = 0; i < frameCoordinates.size(); i += 2) {
cvCircle(grabbed,
new CvPoint(frameCoordinates.get(i),
frameCoordinates.get(i + 1)),
1, CvScalar.GREEN, 3, 0, 0);
}
}
}
protected int[] getLower(double[][] L, int centerLine) {
RealMatrix matrixL = new Array2DRowRealMatrix(L);
double[] column = matrixL.getColumn(centerLine);
for (int i = column.length - 1; i >= 0; i--) {
boolean found = true;
for (int j = i; j > Math.max(i - lowerConfidence, 0) && found; j--) {
found &= column[j] < column[j - 1];
}
if(found)
return new int[] {centerLine, i};
}
return new int []{centerLine,column.length * 3 / 4};
}
protected int[] getUpper(double[][] L, double[][] h, int right, int left) {
RealMatrix matrixL = new Array2DRowRealMatrix(L);
RealMatrix matrixH = new Array2DRowRealMatrix(h);
RealMatrix hMinusL = matrixH.subtract(matrixL);
int centerLine = (int)Math.round((double)(right + left) / 2);
double[] column = hMinusL.getColumn(centerLine);
// find first getting up
boolean found = false;
int y = 0;
for(int i = 0; i < column.length - 1 && !found; i++){
if(column[i] <= column[i + 1]){
y = i;
found = true;
for (int j = i + 2; j < Math.min(column.length, i + upperConfidence) && found; j++){
found &= column[i] < column[j];
}
}
}
return new int[]{centerLine, y};
}
/**
* @param roi a matrix of the roi pixels arranged as BGR
* @return the Hue matrix
*/
private double[][] getH(CvMat roi){
double[][] h = new double[roi.rows()][roi.cols()];
double max = Double.MIN_VALUE;
for (int i = 0; i < roi.rows(); i++) {
for (int j = 0; j < roi.cols(); j++) {
double R = roi.get(i, j , 2), G = roi.get(i, j , 1);
//h = R / (G + R)
h[i][j] = R / (G + R);
max = Math.max(max, h[i][j]);
}
}
//scale values to be between 0 - 1
for (int i = 0; i < roi.rows(); i++) {
for (int j = 0; j < roi.cols(); j++) {
h[i][j] /= max;
}
}
return h;
}
/**
* @param roi a matrix of the roi pixels arranged as BGR
* @return the luminance matrix
*/
private double[][] getL(CvMat roi){
double[][] L = new double[roi.rows()][roi.cols()];
double max = Double.MIN_VALUE;
for (int i = 0; i < roi.rows(); i++) {
for (int j = 0; j < roi.cols(); j++) {
//L = (R + R + B + G + G + G) / 6
double R = roi.get(i, j , 2), G = roi.get(i, j , 1), B = roi.get(i, j , 0);
L[i][j] = (R + R + B + G + G + G) / 6;
max = Math.max(max, L[i][j]);
}
}
//scale values to be between 0 - 1
for (int i = 0; i < roi.rows(); i++) {
for (int j = 0; j < roi.cols(); j++) {
L[i][j] /= max;
}
}
return L;
}
/**
* @param L the luminance matrix
* @return both the Lmini line in 0 index and in [1][0] the mean luminance of Lmini
*/
private double[][] Lmini(double [][] L){
RealMatrix l = new Array2DRowRealMatrix(L);
double[][] Lmini = new double[2][L[0].length];
for (int i = 0; i < L[0].length; i++) {
double[] column = l.getColumn(i);
int minIndex = Utils.getMinIndex(column, false);
Lmini[0][i] = minIndex;
Lmini[1][0] += column[minIndex];
}
Lmini[1][0] /= L[0].length;
return Lmini;
}
private int[] getRight(double[][] L, double[][] Lmini){
final int[] ans = new int[2];
final double meanL = Lmini[1][0];
for (int i = Lmini[0].length - 1; i >= 0; i--) {
if(L[(int)Lmini[0][i]][i] < meanL){
boolean found = true;
for (int j = i; j > Math.max(i - sideConfidence, 0) && found; j--) {
found &= L[(int)Lmini[0][j]][j] < meanL;
}
if(found)
return new int[] {i, (int)Lmini[0][i]};
}
}
return ans;
}
private int[] getLeft(double[][] L, double[][] Lmini){
final int[] ans = new int[2];
final double meanL = Lmini[1][0];
for (int i = 0; i < Lmini[0].length; i++) {
if(L[(int)Lmini[0][i]][i] < meanL){
boolean found = true;
for (int j = i; j < Math.min(i + sideConfidence, Lmini[0].length) && found; j++) {
found &= L[(int)Lmini[0][j]][j] < meanL;
}
if(found)
return new int[] {i, (int)Lmini[0][i]};
}
}
return ans;
}
public void setClassifier(CvHaarClassifierCascade classifier) {
this.classifier = classifier;
}
public void setStorage(CvMemStorage storage) {
this.storage = storage;
}
public void shutdown(){
executor.shutdownNow();
if(storage != null)
storage.release();
}
public static void main(String ... args) throws Exception{
NoMoreStickersFeatureExtractor fe = new NoMoreStickersFeatureExtractor();
//fe.setOutput(true);
fe.extract( null );
fe.shutdown();
}
}
运行时出现以下错误:
Exception in thread "main" java.lang.ExceptionInInitializerError
at main.java.edu.lipreading.vision.NoMoreStickersFeatureExtractor.init(NoMoreStickersFeatureExtractor.java:216)
at main.java.edu.lipreading.vision.NoMoreStickersFeatureExtractor.getPoints(NoMoreStickersFeatureExtractor.java:70)
at main.java.edu.lipreading.vision.AbstractFeatureExtractor.getPoints(AbstractFeatureExtractor.java:82)
at main.java.edu.lipreading.vision.AbstractFeatureExtractor.extract(AbstractFeatureExtractor.java:37)
at main.java.edu.lipreading.vision.NoMoreStickersFeatureExtractor.main(NoMoreStickersFeatureExtractor.java:389)
Caused by: java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at main.java.edu.lipreading.Constants.<clinit>(Constants.java:16)
... 5 more
***** VIDEOINPUT LIBRARY - 0.1995 - TFW07 *****
SETUP: Setting up device 0
SETUP: 1.3M HD WebCam
SETUP: Couldn't find preview pin using SmartTee
SETUP: Capture callback set
SETUP: Device is setup and ready to capture.
最佳答案
错误是来自 Constants class 的 NullPointerException在第 16 行。
您可以在该行看到,程序正在尝试加载 lr.properties
文件。
问题可能在于该文件不在您的类路径中。将该文件添加到类路径中以防止出现此错误
关于java - 由 NullPointerException 引起的初始化程序中的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21361688/
我正在编写一个具有以下签名的 Java 方法。 void Logger(Method method, Object[] args); 如果一个方法(例如 ABC() )调用此方法 Logger,它应该
我是 Java 新手。 我的问题是我的 Java 程序找不到我试图用作的图像文件一个 JButton。 (目前这段代码什么也没做,因为我只是得到了想要的外观第一的)。这是我的主课 代码: packag
好的,今天我在接受采访,我已经编写 Java 代码多年了。采访中说“Java 垃圾收集是一个棘手的问题,我有几个 friend 一直在努力弄清楚。你在这方面做得怎么样?”。她是想骗我吗?还是我的一生都
我的 friend 给了我一个谜语让我解开。它是这样的: There are 100 people. Each one of them, in his turn, does the following
如果我将使用 Java 5 代码的应用程序编译成字节码,生成的 .class 文件是否能够在 Java 1.4 下运行? 如果后者可以工作并且我正在尝试在我的 Java 1.4 应用程序中使用 Jav
有关于why Java doesn't support unsigned types的问题以及一些关于处理无符号类型的问题。我做了一些搜索,似乎 Scala 也不支持无符号数据类型。限制是Java和S
我只是想知道在一个 java 版本中生成的字节码是否可以在其他 java 版本上运行 最佳答案 通常,字节码无需修改即可在 较新 版本的 Java 上运行。它不会在旧版本上运行,除非您使用特殊参数 (
我有一个关于在命令提示符下执行 java 程序的基本问题。 在某些机器上我们需要指定 -cp 。 (类路径)同时执行java程序 (test为java文件名与.class文件存在于同一目录下) jav
我已经阅读 StackOverflow 有一段时间了,现在我才鼓起勇气提出问题。我今年 20 岁,目前在我的家乡(罗马尼亚克卢日-纳波卡)就读 IT 大学。足以介绍:D。 基本上,我有一家提供簿记应用
我有 public JSONObject parseXML(String xml) { JSONObject jsonObject = XML.toJSONObject(xml); r
我已经在 Java 中实现了带有动态类型的简单解释语言。不幸的是我遇到了以下问题。测试时如下代码: def main() { def ks = Map[[1, 2]].keySet()
一直提示输入 1 到 10 的数字 - 结果应将 st、rd、th 和 nd 添加到数字中。编写一个程序,提示用户输入 1 到 10 之间的任意整数,然后以序数形式显示该整数并附加后缀。 public
我有这个 DownloadFile.java 并按预期下载该文件: import java.io.*; import java.net.URL; public class DownloadFile {
我想在 GUI 上添加延迟。我放置了 2 个 for 循环,然后重新绘制了一个标签,但这 2 个 for 循环一个接一个地执行,并且标签被重新绘制到最后一个。 我能做什么? for(int i=0;
我正在对对象 Student 的列表项进行一些测试,但是我更喜欢在 java 类对象中创建硬编码列表,然后从那里提取数据,而不是连接到数据库并在结果集中选择记录。然而,自从我这样做以来已经很长时间了,
我知道对象创建分为三个部分: 声明 实例化 初始化 classA{} classB extends classA{} classA obj = new classB(1,1); 实例化 它必须使用
我有兴趣使用 GPRS 构建车辆跟踪系统。但是,我有一些问题要问以前做过此操作的人: GPRS 是最好的技术吗?人们意识到任何问题吗? 我计划使用 Java/Java EE - 有更好的技术吗? 如果
我可以通过递归方法反转数组,例如:数组={1,2,3,4,5} 数组结果={5,4,3,2,1}但我的结果是相同的数组,我不知道为什么,请帮助我。 public class Recursion { p
有这样的标准方式吗? 包括 Java源代码-测试代码- Ant 或 Maven联合单元持续集成(可能是巡航控制)ClearCase 版本控制工具部署到应用服务器 最后我希望有一个自动构建和集成环境。
我什至不知道这是否可能,我非常怀疑它是否可能,但如果可以,您能告诉我怎么做吗?我只是想知道如何从打印机打印一些文本。 有什么想法吗? 最佳答案 这里有更简单的事情。 import javax.swin
我是一名优秀的程序员,十分优秀!