Skip to content

Issue With reading the Plate letter/numbers #68

Description

@seanmack56

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();
            }
        });
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions