编辑:没有找到长org.opencv.dnn.Dnn.readNetFromCaffe_0

时间:2019-09-06 04:34:38

标签: android opencv face-recognition

我正在使用Android Studio使用OpenCV库创建人脸识别应用程序,同时看到“ NDK分辨率结果:项目设置:Gradle模型版本= 5.6,NDK版本为未知”错误,当我在模拟器中运行该应用程序时检测图片中的人脸我收到以下错误:

  

“未找到长org.opencv.dnn.Dnn.readNetFromCaffe_0(java.lang.String,java.lang.String)的实现(尝试Java_org_opencv_dnn_Dnn_readNetFromCaffe_10和Java_org_opencv_dnn_Dnn_readNetFromCaffe_10__Ljava_lang_String_2>

一旦我进入readNetFromCaffe_0的实现,我意识到它是使用NDK本机运行的,我怀疑问题可能出在NDK的设置上(尽管我认为我已经对其进行了完整的配置)

这是代码停止的地方:

if (firsttimeFaces == false) {
    firsttimeFaces = true;
    String protoPath = Environment.getExternalStorageDirectory() + "/dnns/deploy.prototxt";
    String caffeWeights = Environment.getExternalStorageDirectory() + "/dnns/res10_300x300_ssd_iter_140000.caffemodel";
    ##detector = Dnn.readNetFromCaffe(protoPath, caffeWeights);##
}

分为readNetFromCaffe个节目;

public static Net readNetFromCaffe(String prototxt, String caffeModel) {
    return new Net(readNetFromCaffe_0(prototxt, caffeModel));
}

readNetFromCaffe_0的显示和实现;

private static native long readNetFromCaffe_0(String prototxt, String caffeModel);

在约旦的帮助下,我意识到我已经错过了

OpenCVLoader.initDebug();

因此,甚至没有启动该库。

现在,我正在尝试捕获人脸并在其周围绘制矩形,以便我知道它使用下面的代码序列检测到人脸,尽管代码运行没有错误,但我看不到矩形,代码如下; / p>

if (checkedId == R.id.timein) {
                    final AlertDialog.Builder builder = new AlertDialog.Builder(Recognition.this);
                    final EditText text = new EditText(Recognition.this);

                    builder.setTitle("Enter Your Staff ID: ").setMessage("").setView(text);
                    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface di, int i) {
                            final String id = text.getText().toString();

                            Cursor cursor = MainActivity.mSQLiteHelper.getData("SELECT * FROM RECORD WHERE staff_id=" + id);
                            if (cursor.moveToNext()) {
                                byte[] image = cursor.getBlob(3);
                                Bitmap bmp = BitmapFactory.decodeByteArray(image, 0, image.length);
                                imageView.setImageBitmap(bmp);
                                imageView.setVisibility(View.VISIBLE);



                                if (firsttimeFaces == false) {
                                    firsttimeFaces = true;
                                    String protoPath = Environment.getExternalStorageDirectory() + "/dnns/deploy.prototxt";
                                    String caffeWeights = Environment.getExternalStorageDirectory() + "/dnns/res10_300x300_ssd_iter_140000.caffemodel";

                                    detector = Dnn.readNetFromCaffe(protoPath, caffeWeights);

                                }

                                Mat loadedImage = new Mat();
                                Bitmap bmp32 = bmp.copy(Bitmap.Config.ARGB_8888, true);
                                Utils.bitmapToMat(bmp32, loadedImage);
                                Imgproc.cvtColor(loadedImage, loadedImage, Imgproc.COLOR_RGBA2RGB);


                                Mat imageblob = Dnn.blobFromImage(loadedImage, 1.0, new Size(300, 300), new Scalar(104.0, 177.0, 123.0), true, false, CvType.CV_32F);
                                detector.setInput(imageblob);
                                Mat detections = detector.forward();

                                int cols = loadedImage.cols();
                                int rows = loadedImage.cols();
                                double THRESHOLD = 0.55;

                                detections = detections.reshape(1, (int) detections.total() / 7);

                                Log.d("EXPERIMENT5:ROWS", detections.rows() + "");


                                for (int j = 0; j < detections.rows(); j++) {
                                    double confidence = detections.get(j, 2)[0];

                                    Log.d("EXPERIMENT6", j + " " + confidence + " " + THRESHOLD);
                                    if (confidence > THRESHOLD) {
                                        int left = (int) (detections.get(i, 3)[0] * cols);
                                        int top = (int) (detections.get(i, 4)[0] * rows);
                                        int right = (int) (detections.get(i, 5)[0] * cols);
                                        int bottom = (int) (detections.get(i, 6)[0] * rows);


                                        //rectangle draw

                                        if (left < 0) {
                                            left = 0;
                                        }
                                        if (top < 0) {
                                            top = 0;
                                        }
                                        if (right < 0) {
                                            right = 0;
                                        }
                                        if (bottom < 0) {
                                            bottom = 0;
                                        }

                                        int xLim = loadedImage.size(1);
                                        int yLim = loadedImage.size(0);

                                        if (left >= xLim) {
                                            left = xLim - 2;
                                        }
                                        if (right >= xLim) {
                                            right = xLim - 2;
                                        }
                                        if (top >= yLim) {
                                            top = yLim - 2;
                                        }
                                        if (bottom >= yLim) {
                                            bottom = yLim - 2;
                                        }

                                        Imgproc.rectangle(loadedImage, new Point(left, top), new Point(right, bottom), new Scalar(255, 255, 0), 2);
                                    }
                                }
                            }
                            else {
                                Toast.makeText(getApplicationContext(), "ID does not exist!", Toast.LENGTH_LONG).show();
                            }
                        }
                    });

此致

0 个答案:

没有答案