mollysoda 2022-02-07 03:52 采纳率: 100%
浏览 79
已结题

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条回答 默认 最新

  • 爱晚乏客游 2022-02-07 10:04
    关注

    据我猜测,contribut包需要编译的吧,没有编译不能直接使用的,除非你把它当成另外的cpp文件而不是opencv的组件来使用(我也不确定当成另外的cpp文件能不能行的通,但是编译是没有问题的)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月1日
  • 已采纳回答 2月21日
  • 创建了问题 2月7日

悬赏问题

  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan