weixin_44613287 2019-04-24 13:42 采纳率: 0%
浏览 434
已结题

安卓opencv人脸检测无法运行

使用了opencv自带的.xml模型,但是无法正常运行,一旦运行程序就会闪退,且无报错,求救!

这个是启动模型

public void initializeOpenCVDependencies() {
        try {
            // Copy the resource into a temp file so OpenCV can load it
                 InputStream is = getResources().openRawResource(R.raw.lbpcascade_frontalface_improved);
                 File cascadeDir = getDir("cascade", Context.MODE_PRIVATE);
                 File mCascadeFile = new File(cascadeDir.getAbsoluteFile(), "lbpcascade_frontalface_improved.xml");
                 FileOutputStream os = new FileOutputStream(mCascadeFile);
                 byte[] buffer = new byte[4096];
                 int bytesRead=0;
                 while ((bytesRead = is.read(buffer)) != -1) {
                     os.write(buffer, 0, bytesRead);
                 }
                 is.close();
                 os.close();
                 // Load the cascade classifier
             detectface = new CascadeClassifier(mCascadeFile.getAbsolutePath());
        } catch (Exception e) {
            Log.e("OpenCVActivity", "Error loading cascade", e);

这个是检测模块

 srcBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.a);
        grayBitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), Bitmap.Config.RGB_565);
        Utils.bitmapToMat(srcBitmap, rgbMat);//convert original bitmap to Mat, R G B.

        Imgproc.cvtColor(rgbMat, grayMat, Imgproc.COLOR_RGB2GRAY);//rgbMat to gray grayMat
        MatOfRect cars=new MatOfRect();
      detectface.detectMultiScale(grayMat,car,1.1,3,0,new Size(50,50),new Size());
  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog