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 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘