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

    报告相同问题?

    悬赏问题

    • ¥20 SQL server表计算问题
    • ¥15 C# P/Invoke的效率问题
    • ¥20 thinkphp适配人大金仓问题
    • ¥20 Oracle替换.dbf文件后无法连接,如何解决?(相关搜索:数据库|死循环)
    • ¥15 数据库数据成问号了,前台查询正常,数据库查询是?号
    • ¥15 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)
    • ¥15 彩灯控制电路,会的加我QQ1482956179
    • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
    • ¥15 (关键词-电路设计)
    • ¥15 如何解决MIPS计算是否溢出