安卓利用opencv实现自定义图像识别

安卓利用opencv实现自定义图像识别

要在安卓上实现自定义图像识别,我们需要用到opencv-android-sdk先上效果图

安卓利用opencv实现自定义图像识别_第1张图片

下面来讲讲具体实现思路:

1、配置android studio中opencv的环境

2、训练自定义图像数据集

3、将训练好的数据集加载进行识别

  InputStream is = getResources().openRawResource(R.raw.cascade);
                        File cascadeDir = getDir("cascade", Context.MODE_PRIVATE);
                        mCascadeFile = new File(cascadeDir, "lbpcascade_frontalface.xml");
                        FileOutputStream os = new FileOutputStream(mCascadeFile);

                        byte[] buffer = new byte[4096];
                        int bytesRead;
                        while ((bytesRead = is.read(buffer)) != -1) {
                            os.write(buffer, 0, bytesRead);
                        }
                        is.close();
                        os.close();

                        mJavaDetector = new CascadeClassifier(mCascadeFile.getAbsolutePath());
                        if (mJavaDetector.empty()) {
                            Log.e(TAG, "Failed to load cascade classifier");
                            mJavaDetector = null;
                        } else
                            Log.i(TAG, "Loaded cascade classifier from " + mCascadeFile.getAbsolutePath());

                        mNativeDetector = new DetectionBasedTracker(mCascadeFile.getAbsolutePath(), 0);

                        cascadeDir.delete();

整个工程已上传有需要请复制下面链接:

https://download.csdn.net/download/sm16111/10703471

参考博客:

环境配置:https://blog.csdn.net/andrexpert/article/details/78993533

自定义目标训练:https://blog.csdn.net/wuxiaoyao12/article/details/39227189

你可能感兴趣的:(Android,图像学习笔记)