Giter VIP home page Giter VIP logo

Comments (28)

yasirmturk avatar yasirmturk commented on August 18, 2024

According to my experience with the provided trained data set, It works best when you

  • Capture the picture of plate along with some area around it
  • Downsize your UIImage resolution to somewhere between [1280 - 480] i.e. 1280x720 or 640x480
  • Fix the orientation of UIImage before passing it to the scanner
  • Capture or Crop the image in landscape
  • Make sure you have selected correct country and region

Still if you are having troubles, please send me the picture that you are trying to scan

from openalpr-swift.

yasirmturk avatar yasirmturk commented on August 18, 2024

detected region you can get by implementing the delegate method
- (void)didScanResults:(OAResults *)results;
read the platePoints of the first plate in results

from openalpr-swift.

sensei71 avatar sensei71 commented on August 18, 2024

from openalpr-swift.

yasirmturk avatar yasirmturk commented on August 18, 2024

when you write UIImage to file it stores meta date like orientation along with it... but in case of passing it directly you need to fix the orientation yourself

and
func didScanResults(_ results: OAResults!) { for plate in results.plates { for point in plate.platePoints { let pt = point.cgPointValue let newPt = CGPoint(x: pt.x, y: pt.y) } } }

from openalpr-swift.

sensei71 avatar sensei71 commented on August 18, 2024

from openalpr-swift.

yasirmturk avatar yasirmturk commented on August 18, 2024

remove
func didScanResultsJSON(_ results: String!) { print("didScanResultsJSON \(results)") }

then it will fire

from openalpr-swift.

sensei71 avatar sensei71 commented on August 18, 2024

from openalpr-swift.

sensei71 avatar sensei71 commented on August 18, 2024

from openalpr-swift.

yasirmturk avatar yasirmturk commented on August 18, 2024

great thanks

from openalpr-swift.

Luxonis-Brandon avatar Luxonis-Brandon commented on August 18, 2024

Hey guys,

Sorry for a late follow-up question here. So I too am trying to get the plate coordinates, and can't quite seem to get them (despite trying to piece together the above... not sure what I'm missing).

I have, however, gotten the coordinates of the characters in the plates (cheat-y code below):

let alprScanner = OAScanner(country: "us", patternRegion: "co")
        alprScanner?.scanImage(photo.image, onSuccess: { (plates) in
            plates?.forEach({ (plate) in
                print("result (oh ya!): \(String(describing: plate.number)), probability: \(String(describing: plate.confidence))")
                self.licensePlateText.text = String(describing: plate.number!)
                print(plate.characters[0].corners)
                print(plate.characters[0].character)
                
            })
            }, onFailure: { (error) in
                print("error, oh no!: \(String(describing:error?.localizedDescription))")
        })

And this prints, as it should:

result (oh ya!): Optional("WBFYDND"), probability: 81.44639
Optional([NSPoint: {1215, 1927}, NSPoint: {1278, 1925}, NSPoint: {1287, 2146}, NSPoint: {1224, 2148}])
Optional("W")

Now, I'm stuck when it comes to the required delegate bits to get the bounding box of the license plate.

Where should I define the functions? I did find the following in "OAScanner.h"

@optional
- (void)didScanResults:(OAResults *)results;

- (void)didScanResultsJSON:(NSString *)results;

- (void)didScanBestPlates:(NSArray<OAPlate *> *)bestPlates;

- (void)didScanPlateResult:(OAPlateResult *)plateResult;

- (void)didFailToLoadwithError:(NSError *)error;

@end

And the didScanPlateResult is definitely what I want to use, like sensei71 mentioned.

Where should I put the delegate functions, and how should I call them?
Do I call them after having called the scanImage function?

Thanks in advance!

from openalpr-swift.

yasirmturk avatar yasirmturk commented on August 18, 2024

You can use

func didScanPlateResult(_ plateResult: OAPlateResult!) {
        DispatchQueue.main.async {
            self.updatePlateBorder(result: plateResult)
            if plateResult.bestPlate.confidence > 90 {
                self.textField.text = plateResult.bestPlate.number
            }
        }
    }

and

fileprivate func updatePlateBorder(result: OAPlateResult?) {
        guard let result = result else {
            UIView.animate(withDuration: 0.2, animations: {
                self.borderView.alpha = 0
            })
            return
        }
        let widthScale = CGFloat(result.cols) / borderView.bounds.width
        let heightScale = CGFloat(result.rows) / borderView.bounds.height
        if let points = result.platePoints {
            var newPoints = [NSValue]()
            for i in 0..<points.count {
                let pt = points[i].cgPointValue
                let newPt = CGPoint(x: pt.x / widthScale, y: pt.y / heightScale)
                newPoints.append(NSValue(cgPoint: newPt))
            }
            UIView.animate(withDuration: 0.1) {
                self.borderView.alpha = 1
                self.borderView.updateCorners(newPoints)
            }
        }
    }

from openalpr-swift.

yasirmturk avatar yasirmturk commented on August 18, 2024

here is the border view class
https://github.com/cardash/react-native-openalpr/blob/master/ios/RecognizedPlateBorderView.h

from openalpr-swift.

Luxonis-Brandon avatar Luxonis-Brandon commented on August 18, 2024

Awesome, thanks a ton for the help! Parsing through it now.

(And thanks equally for the framework itself!)

from openalpr-swift.

yasirmturk avatar yasirmturk commented on August 18, 2024

you are welcome :)

from openalpr-swift.

Luxonis-Brandon avatar Luxonis-Brandon commented on August 18, 2024

So I was able to pull in the RecognizedPlateBorderView.h by adding the .h and .mm to the Podfile project, and then making sure the .h is in both the OpenALPRSwift-umbrella.h file and also added to Build Phases > Headers.

However, I don't think that's what I'm looking for actually.

From your example above, you're actually calling on results of the PlateScanner.mm from the ReactNative project, here:
https://github.com/cardash/react-native-openalpr/blob/master/ios/PlateScanner.mm

Now, this is fine, I guess I could use that project instead... but, is there a way to do this with your framework? Or should I just move to the React Native framework instead? I tried using PlateScanner.mm (and PlateScanner.h) in your framework/podfile, but it doesn't work because the ReactNative framework has different dependencies.

Thoughts?

Thanks again!

from openalpr-swift.

Luxonis-Brandon avatar Luxonis-Brandon commented on August 18, 2024

In other words I'm just looking to get OAPlateResult filled, but I don't see a function to do that in the current framework. The React Native Framework has the equivalent, but I don't see it in this Swift framework.

And to clarify, OAScanner seems to return only type OAPLate, not OAPlateResult, as far as I can tell.

Am I missing something?

Thanks again!

from openalpr-swift.

Luxonis-Brandon avatar Luxonis-Brandon commented on August 18, 2024

Yep, according to the definition, it does return, or rather is typedef'ed to, OAPlate type:
typedef void(^onPlateScanSuccess)(NSArray<OAPlate *> *);

(in here: https://github.com/yasirmturk/openalpr-swift/blob/master/openalpr-swift/OAScanner.h)

from openalpr-swift.

yasirmturk avatar yasirmturk commented on August 18, 2024

so, you found what you looking for?

from openalpr-swift.

sensei71 avatar sensei71 commented on August 18, 2024

from openalpr-swift.

Luxonis-Brandon avatar Luxonis-Brandon commented on August 18, 2024

So I have not yet.

I can't figure out how to get OAPlateResult populated. What do I call to populate it?

Right now I'm calling OAScanner, but it returns type OAPlate, which doesn't include the plate coordinates.

Thanks again!

from openalpr-swift.

yasirmturk avatar yasirmturk commented on August 18, 2024

that is the delegate method
didScanPlateResult
what are you getting in that method?

from openalpr-swift.

Luxonis-Brandon avatar Luxonis-Brandon commented on August 18, 2024

Thanks!

So when I try to call it, it says it needs type OAPlateResult, which was what I'm trying to get from it.

So I think it's as simple as me not knowing how to use that delegate. I'm new to Swift (this is my ~3rd day programming in it), so it could be me doing something really dumb.

How are you getting results from didScanPlateResult?

Thanks again!

from openalpr-swift.

yasirmturk avatar yasirmturk commented on August 18, 2024

i have update my comment above, now you can see the proper code

from openalpr-swift.

yasirmturk avatar yasirmturk commented on August 18, 2024

i am passing OAPlateResult to updatePlateBorder(result: plateResult)

from openalpr-swift.

Luxonis-Brandon avatar Luxonis-Brandon commented on August 18, 2024

So my problem is I don't know how to get OAPlateResult to start with. Where are you getting it?

from openalpr-swift.

yasirmturk avatar yasirmturk commented on August 18, 2024

to use the delegate

if let scanner = OAScanner(country: "eu", patternRegion: "dk") {
            scanner.delegate = self // Here we set the delegate 
            scanner.setTopN(1)
    // scanner.scanImage... // use this method as usual
}

and then

extension CameraViewController: OAScannerDelegate {
    // Here you will get the complete results
    func didScanPlateResult(_ plateResult: OAPlateResult!) {
        DispatchQueue.main.async {
            //self.updatePlateBorder(result: plateResult)
        }
    }

from openalpr-swift.

Luxonis-Brandon avatar Luxonis-Brandon commented on August 18, 2024

Perfect. I think this is what I was missing. Trying it out.

Thanks again!

from openalpr-swift.

Luxonis-Brandon avatar Luxonis-Brandon commented on August 18, 2024

Yes, that was exactly it. I'm now getting OAPlateResult, as desired, including the plate points:

plateResult: <OAPlateResult: 0x28110ca80>
plateResult.bestPlate.number!: 026UAT
plateResult.platePoints!: [NSPoint: {805, 1506}, NSPoint: {2296, 1506}, NSPoint: {2268, 2596}, NSPoint: {805, 2596}]

Thanks again for all the help! Everything is working now. :-)

from openalpr-swift.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.