java - 尽管我已经导入了所需的 jar 和 dll 文件,但我无法初始化 openCV 数据类型

标签 java opencv

我正在使用 opencv 2.4.4,我想用 java 检测和跟踪人脸。我在互联网上找到了如下示例。

示例

import hypermedia.video.*;
import java.awt.Rectangle;

float last = millis();
float interval = 100;
int startTime;
int noFaces = 0;
int noFacesPrev = 0;
int dx = 0;
int dy = 0;
int dwidth = 400;
int dheight = 400;

OpenCV opencv;

// contrast/brightness values
int contrast_value    = 0;
int brightness_value  = 0;



void setup() {

    size( 800,800 );

    opencv = new OpenCV( this );
    opencv.movie( "egypt.mov", 320, 240 );          // load movie file
    opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );  // load detection description, here-> front face detection : "haarcascade_frontalface_alt.xml"


    // print usage
    println( "Drag mouse on X-axis inside this sketch window to change contrast" );
    println( "Drag mouse on Y-axis inside this sketch window to change brightness" );

}

void stop() {
    opencv.stop();
    super.stop();
}

void draw() {

    // grab a new frame
    opencv.read();
    opencv.contrast( contrast_value );
    opencv.brightness( brightness_value );

    // proceed detection
    Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 ); // 40,40 is the smallest size its looking for

 // draw face area(s)
  noFaces = faces.length;

  if (faces.length >=1 && noFaces > noFacesPrev) {
    startTime = millis();
    println(startTime);
    println(noFaces);
    println(noFacesPrev);
    noFacesPrev = noFaces;
  }
  if (faces.length == 0) {  // if there is no face, start over
    println("no face");
    startTime = 0;
    noFacesPrev = 0;
  }

 if (startTime > 0) {
    println("started");
    if(millis() - startTime >interval && (faces.length >=1)) {
      for ( int i = 0; i= 800){
      dy = dy+400;
      dx = 0;
      }
      if (dy >= 800){
      dy = 0;
      dx = 0; 
      }
      }
      startTime=0;
      println ("clock reset");
      noFacesPrev=0;
    }
  }
}

// Changes contrast/brigthness values

void mouseDragged() {
    contrast_value   = (int) map( mouseX, 0, width, -128, 128 );
    brightness_value = (int) map( mouseY, 0, width, -128, 128 );
}

void keyPressed()
{

  if (key == 's') {
    opencv.stop(); 
    super.stop();
  }
}

当我想在我的项目中尝试此代码时,我无法初始化“OpenCV opencv;”!另外,我无法导入“hypermedia.video”!

最佳答案

OPENCV 不是一种数据类型。如果您想检测图像中的人脸,您可以在代码中导入 OpenCV 库。

并在调用任何 openCV 方法之前在主方法中调用 System.loadLibrary("opencv_java244") 。

您可以在 OpenCV 上找到代码和文档页。

关于java - 尽管我已经导入了所需的 jar 和 dll 文件,但我无法初始化 openCV 数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16177794/

相关文章:

java - 如何保存用户选择的 Intent ?

c++ - 使用透明层 opencv 读取和显示 PNG 时出现问题

java - 捕获应用程序停止异常时应该使用 System.exit(1) 吗?

Java 子类一般概念

c++ - Microsoft Visual Studio 中的 QWT 直方图和立即关闭的 Qt 插件

OpenCV:从平移和旋转中获取透视矩阵

python - 使用 Python OpenCV 将实时视频流中检测到的二维码保存为图像

python - 什么更快 : Python 3's ' len' or numpys shape?

Java- super 引用

java - PowerMockito 模拟间接静态方法