yasirmturk / openalpr-swift

iOS Framework for the openalpr library ready to use in Swift and Objective-C.
GNU General Public License v3.0
38 stars 24 forks source link

No idea why it's not working #3

Closed tuxedotu closed 6 years ago

tuxedotu commented 6 years ago

I currently try to include the OpenALPR in a Project, where I can take pictures of a plate and the app should recognise the plate. However for some reason it does not work...

This is the capturePhoto-function:

It is the following command: cameraOutput.capturePhoto(with: settings, delegate: self)

which calls the following function:

func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) { if let photoData = photo.fileDataRepresentation() { capturedImage = UIImage(data: photoData) showLicenseInfoView() } }

And the showLicenseInfoView-function looks like this:

`func showLicenseInfoView() {

    // scanning the image
    if let licenseText = scanLicensePlate(forImage: capturedImage!) {
        print(licenseText)
        licensePlateLabel.text = licenseText
    }

    // add the licenseInformationView as a subview to the main view
    self.view.addSubview(licenseInformationView)

    // configuring the licenseInformationView
    licenseInformationView.layer.cornerRadius = 10 // slightly rounding the corners of the liceseInformationView
    let height = self.view.frame.height * 0.8 // height of the license info
    let width = self.view.frame.width * 0.9 // width of the license info
    let posX = self.view.center.x - width / 2 // license info's x-position
    let posY = self.view.safeAreaInsets.top + 3 // license info's y-position
    licenseInformationView.frame = CGRect(x: posX, y: posY, width: width, height: height) // setting up the licenseInformationView with size and positions
    licenseInformationView.transform = CGAffineTransform.init(scaleX: 0.7, y: 0.7) // scale it down to get a popUp-effect when appearing
    licenseInformationView.alpha = 0 // making it invisible

    // animate the window's popUp
    UIView.animate(withDuration: 0.2) {
        self.blurEffectView.effect = self.blurEffect // adding the blur-effect
        self.licenseInformationView.alpha = 1 // making the licenseInformationView visible
        self.licenseInformationView.transform = CGAffineTransform.identity // resizing the licenseInformationView to its original size
    }
}`

However the licenseText is still nil and the licensePlateLabel doesn't get assigned... I really need help cause I have no goddamn idea why it doesn't work 😂

yasirmturk commented 6 years ago

how do u implement scanLicensePlate(forImage: capturedImage!) ??

tuxedotu commented 6 years ago

That's the scanLicensePlate-function:

`func scanLicensePlate(forImage image: UIImage) -> String? { let scanner = OAScanner(country: "eu", patternRegion: "at") var licenseText :String?

    scanner?.scanImage(image, onSuccess: { (plates) in plates?.forEach({ (plate) in licenseText = plate.number })
    }, onFailure: { (error) in
        print("error: \(String(describing: error?.localizedDescription))")
    })

    return licenseText
}`
tuxedotu commented 6 years ago

Sry that was messed up. Here's the code again:

func scanLicensePlate(forImage image: UIImage) -> String? {
        let scanner = OAScanner(country: "eu", patternRegion: "at")
        var licenseText :String?

        scanner?.scanImage(image, onSuccess: { (plates) in plates?.forEach({ (plate) in licenseText = plate.number })
        }, onFailure: { (error) in
            print("error: \(String(describing: error?.localizedDescription))")
        })

        return licenseText
    }
tuxedotu commented 6 years ago

The thing is, if i pass an image from my Assets-folder, it works but as soon as i pass the image which was currently taken (both are UIImages), it doesn't work at all

yasirmturk commented 6 years ago

plz check the guide here: https://github.com/cardash/react-native-openalpr#capturequality you need to pre-process the taken image