iMicknl / cordova-plugin-openalpr

This Cordova plugin adds support for the OpenALPR (Automatic License Plate Recognition) library, which provides support for retrieving the license plate from a picture.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No rego recognized or error message - 0: No image found for given file path.

NickolaiA opened this issue · comments

Hi there,

I am trying to wring a test app to use this plugin it it seems it does not work on Android device (did not have a chance to check on iOS yet). Here is more details about my environment and code:
Test device: Samsung Galaxy S8+ with Android 8.1
Android platform was added as

cordova platform add android@6.3.0 (tried with 6.4.0, but result the same)

config.xml:

<?xml version='1.0' encoding='utf-8'?>
<widget id="au.com.test.test1234" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Test app 1</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="na@na.na.com" href="http://somewebsite.com">
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <allow-navigation href="*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
        <preference name="Orientation" value="all" />
        <config-file parent="UIStatusBarHidden" platform="ios" target="*-Info.plist">
            <true />
        </config-file>
        <config-file parent="UIViewControllerBasedStatusBarAppearance" platform="ios" target="*-Info.plist">
            <false />
        </config-file>
    </platform>
    <plugin name="cordova-plugin-camera" spec="^4.0.2" />
    <plugin name="cordova-plugin-openalpr" spec="^2.0.0" />
    <plugin name="phonegap-plugin-barcodescanner" spec="^7.1.0">
        <variable name="ANDROID_SUPPORT_V4_VERSION" value="27.+" />
    </plugin>
    <engine name="ios" spec="^4.5.4" />
    <engine name="android" spec="^6.3.0" />
</widget>

I added the following code to reeivedEvent method in index.js:

try{
  navigator.camera.getPicture(function(filepath) {
    alert("filepath=" + filepath)
    try{
      cordova.plugins.OpenALPR.scan(filepath, { country: 'au', amount: 3 },
      function (results) {
           alert(results);
           alert(results.length);
       }, function (error) {
           alert(error.code + ': ' + error.message);
       });
    } catch (msg) {
      alert(msg);
    }
  }, function() {

  }, {
    quality: 60,
    destinationType: navigator.camera.DestinationType.FILE_URI, //DATA_URL
    encodingType: navigator.camera.EncodingType.JPEG,
    mediaType: navigator.camera.MediaType.PICTURE,
    sourceType: navigator.camera.PictureSourceType.CAMERA

  });

}catch(msg) {
  alert(msg);
}

When the code is executed I receive a error message like "0: No image found for given file path". I found the following in OpenALPR.java:

if (imagePath == null || imagePath.length() > 0 || new File(imagePath).isFile()) {
  //Otherwise return an error.
 returnError("No image found for given file path", callbackContext);
}

It seems if statement has an issue. you must check imagePath.length() == 0 instead of > 0. Is ti correct? If so, can you please upload the fix?

I've applied a fix and if statement works correctly now, success call back is called with empty array (if you look at my code the second alert() displays 0).

Can you please help me what is wrong with it? Why rego cannot be recognised? Does you plugin send any request to external servers (for example, using Cloud API) to recognise rego or everything is recognised inside plugin? I tried online demo on openalpr.com web side and it recognises my rego correctly.

Thanks in advance for any help.

Thanks for reporting. The imagePath.lenght() > 0 is indeed a mistake, I will try to fix it this weekend and push a new update to NPM.

We have only tested the plugin with EU and US license plates, so I am not sure why AU isn't working. The empty array means that no license plates could be detected on the image. If you have a look at the source, we don't use the Cloud API and handle everything locally on the device using the ALPR framework.

Understood. Thanks for the prompt reply. I saw the plugin has some configuration for au - au.patterns, lau.traineddata, etc. Do you need an example of Australian rego to try to find what could be wrong? I really need you plugin working with Australian regos.

Hi @NickolaiA,

We've just released a hotfix to fix the if statement for using file_uri with Android.

Also I've tested the Australian plates mentioned in this OpenALPR issue topic openalpr/openalpr#200 And these work quite well for me, however it does emit the first V for both license plates (Not sure if this is intended). But as I'm not familiar with Australian plates I am not sure how many different ones there are and which parts of the plate are important. So I do not know if every plate works correctly.

The recognition options are provided by the official OpenALPR repo and are not something we've created ourselves, we simple provide a Cordova wrapper. So if not all Australian plates are supported by the given options you should create an issue on the official OpenALPR repository instead.

Hope this helped.

Kind regards,
Melvin

I just added some instructions that work for me on my S8 with Android 8, check them here #26 (comment)

Closed due to inactivity. Please comment if the issue still persists and we will reopen.