Comments (28)
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.
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.
from openalpr-swift.
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.
from openalpr-swift.
remove
func didScanResultsJSON(_ results: String!) { print("didScanResultsJSON \(results)") }
then it will fire
from openalpr-swift.
from openalpr-swift.
from openalpr-swift.
great thanks
from openalpr-swift.
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.
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.
here is the border view class
https://github.com/cardash/react-native-openalpr/blob/master/ios/RecognizedPlateBorderView.h
from openalpr-swift.
Awesome, thanks a ton for the help! Parsing through it now.
(And thanks equally for the framework itself!)
from openalpr-swift.
you are welcome :)
from openalpr-swift.
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.
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.
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.
so, you found what you looking for?
from openalpr-swift.
from openalpr-swift.
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.
that is the delegate method
didScanPlateResult
what are you getting in that method?
from openalpr-swift.
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.
i have update my comment above, now you can see the proper code
from openalpr-swift.
i am passing OAPlateResult
to updatePlateBorder(result: plateResult)
from openalpr-swift.
So my problem is I don't know how to get OAPlateResult to start with. Where are you getting it?
from openalpr-swift.
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.
Perfect. I think this is what I was missing. Trying it out.
Thanks again!
from openalpr-swift.
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)
- Plates not localized and read when they are rotated HOT 2
- Does not detect anything HOT 2
- Crashing in simulator HOT 2
- Update config file HOT 1
- Swift Package Manager integration
- Rec often fail. HOT 1
- No idea why it's not working HOT 5
- How do you compile the library for iOS HOT 2
- Failed to run pod install HOT 2
- Cannot build openalpr-swiftTests
- Can not recognize image HOT 4
- Can anyone provide indian number plate support file HOT 1
- License HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openalpr-swift.