mollysoda
2022-02-07 03:52
采纳率: 100%
浏览 46

opencv找不到文件(文件存在但找不到,如何解决?(语言-java)

问题遇到的现象和发生背景

processing(java模式)调用自己做的opencv库(照着书 Pro Processing for Images and Computer Vision with OpenCV 写的cvimage),用作者写的代码做测试(面部特征点识别 Face landmark detection in OpenCV Face module with Processing – Magic & Love Interactive ),结果提示 56: error: (-5:Bad argument) No file with given name found.Aborting.... in function 'cv::face::FacemarkKazemiImpl::loadModel' 程序无法运行,但是目录下文件是存在的(文件名也是对的)

img

问题相关代码,请勿粘贴截图
import cvimage.*;
import org.opencv.core.*;
import org.opencv.core.Core;
import org.opencv.face.Face;
import org.opencv.face.Facemark;
import org.opencv.face.EigenFaceRecognizer;

final int W = 300, H = 300;

PImage img1, img2;
String faceFile, modelFile;
//EigenFaceRecognizer fr;
Facemark fm;
PVector offset;

public void settings() {
  size(W*2, H);
}

public void setup() {
  System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
  println(Core.VERSION);
  img1 = loadImage("george.jpg");
  img2 = loadImage("daniel.jpg");
  faceFile = "haarcascade_frontalface_default.xml";
  modelFile = "face_landmark_model.dat";
  fm = Face.createFacemarkKazemi();
  fm.loadModel(dataPath(modelFile));
  offset = new PVector(img1.width, 0);
  noLoop();
}

public void draw() {
  background(0);
  image(img1, 0, 0);
  ArrayList<MatOfPoint2f> shapes = detectFacemarks(img1);
  PVector origin = new PVector(0, 0);
  for (MatOfPoint2f sh : shapes) {
    Point [] pts = sh.toArray();
    drawFacemarks(pts, origin);
  }
  image(img2, offset.x, offset.y);
  shapes.clear();
  shapes = detectFacemarks(img2);
  for (MatOfPoint2f sh : shapes) {
    Point [] pts = sh.toArray();
    drawFacemarks(pts, offset);
  }
}

private ArrayList<MatOfPoint2f> detectFacemarks(PImage i) {
  ArrayList<MatOfPoint2f> shapes = new ArrayList<MatOfPoint2f>();
  CVImage im = new CVImage(i.width, i.height);
  im.copyTo(i);
  MatOfRect faces = new MatOfRect();
  Face.getFacesHAAR(im.getBGR(), faces, dataPath(faceFile)); 
  if (!faces.empty()) {
    fm.fit(im.getBGR(), faces, shapes);
  }
  return shapes;
}

private void drawFacemarks(Point [] p, PVector o) {
  pushStyle();
  noStroke();
  fill(255);
  for (Point pt : p) {
    ellipse((float)pt.x+o.x, (float)pt.y+o.y, 3, 3);
  }
  popStyle();
}

运行结果及报错内容

4.1.2
CvException: cv::Exception: OpenCV(4.1.2) D:\Users\87552\Documents\opencv\opencv_contrib-4.1.2\modules\face\src\getlandmarks.cpp:56: error: (-5:Bad argument) No file with given name found.Aborting.... in function 'cv::face::FacemarkKazemiImpl::loadModel'

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题