gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 04:43:28 31 4
gpt4 key购买 nike

我正在使用 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/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com