SandroMachado / openalpr-android

Android Automatic License Plate Recognition library (http://www.openalpr.com) ported for android.
Apache License 2.0
770 stars 272 forks source link

Issue With reading the Plate letter/numbers #68

Open seanmack56 opened 6 years ago

seanmack56 commented 6 years ago

Hey, I tried to implement this into a project and i have had in issue with actually getting it to give me a value of what the license plates characters are. I get this when i debug for the value of result. result={"error":true,"msg":"Error initializing Open Alpr"}. I am not sure of what the issue is. I tried using your sample project and it reached the same issue. Attached is a screenshot of the code where this issue occurs. I know that i am not missing a file where I have already tried your version and received the same problem. image

The code in the photo for this method is as follows:

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_IMAGE && resultCode == Activity.RESULT_OK) { final ProgressDialog progress = ProgressDialog.show(this, "Loading", "Parsing result...", true); final String openAlprConfFile = ANDROID_DATA_DIR + File.separatorChar + "runtime_data" + File.separatorChar + "openalpr.conf"; BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 10;

        // Picasso requires permission.WRITE_EXTERNAL_STORAGE
        Picasso.with(MainActivity.this).load(destination).fit().centerCrop().into(imageView);
        resultTextView.setText("Processing");

        AsyncTask.execute(new Runnable() {
            @Override
            public void run() {
                String result = OpenALPR.Factory.create(MainActivity.this, ANDROID_DATA_DIR).recognizeWithCountryRegionNConfig("eu", "", destination.getAbsolutePath(), openAlprConfFile, 10);

                Log.d("OPEN ALPR", result);

                try {
                    final Results results = new Gson().fromJson(result, Results.class);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if (results == null || results.getResults() == null || results.getResults().size() == 0) {
                                Toast.makeText(MainActivity.this, "It was not possible to detect the licence plate.", Toast.LENGTH_LONG).show();
                                resultTextView.setText("It was not possible to detect the licence plate.");
                            } else {
                                resultTextView.setText("Plate: " + results.getResults().get(0).getPlate()
                                        // Trim confidence to two decimal places
                                        + " Confidence: " + String.format("%.2f", results.getResults().get(0).getConfidence()) + "%"
                                        // Convert processing time to seconds and trim to two decimal places
                                        + " Processing time: " + String.format("%.2f", ((results.getProcessingTimeMs() / 1000.0) % 60)) + " seconds");
                            }
                        }
                    });

                } catch (JsonSyntaxException exception) {
                    final ResultsError resultsError = new Gson().fromJson(result, ResultsError.class);

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            resultTextView.setText(resultsError.getMsg());
                        }
                    });
                }

                progress.dismiss();
            }
        });
    }
}
naishadh-logistic commented 4 years ago

I am getting same issue. can you please provide solution if you have? thanks.

find-name-brent commented 4 years ago

I am also getting the same issue even with the example project with no changes. The app crashes whenever I take a picture of a license plate, but just gives me an error message if it's just a picture of a blank wall or something.