i'm trying detect qrcode uiimage using cidetector in order extract messagestring it.
i have function receives uiimage input , returns decoded messagestring.
the uiimage pass function extracted user gallery using phasset, phassetcollection, phimagerequestoptions etc. request made synchronously , images quality (i've tried present image in uiimageview make sure image readable).
here can see snippet of code request images:
let _: phimagerequestid = phimagemanager.defaultmanager().requestimageforasset(asset as! phasset, targetsize: size, contentmode: phimagecontentmode.aspectfit, options: options, resulthandler: { (image: uiimage?, info:[nsobject : anyobject]?) -> void in images.append(image!) })
after getting images want detect qrcodes , i'm using following code:
func scanimage(image: ciimage) -> string { let detector = cidetector(oftype: cidetectortypeqrcode, context: nil, options: [cidetectoraccuracy:cidetectoraccuracyhigh]) var image = ciimage(image: uiimage) var decode = "" let features = detector.featuresinimage(image!) feature in features as! [ciqrcodefeature] { decode = feature.messagestring } return decode }
i found (core image detector(cidetector) not detecting qrcodes) , other similar questions none of them seems work.
this tutorial followed https://www.shinobicontrols.com/blog/ios8-day-by-day-day-13-coreimage-detectors
am doing wrong?
thanks in advance
the problem passing ciimage in function
func scanimage(image: ciimage)
and add image variable undefined image in
var image = ciimage(image: uiimage)
remove line , should ok writing qrcode myself , if interested can check out.
// open photo library func loadgallery() { let imagepicker = uiimagepickercontroller() imagepicker.delegate = self imagepicker.sourcetype = .photolibrary self.presentviewcontroller(imagepicker, animated: true, completion: nil) } // read qrcode selecting image func imagepickercontroller(picker: uiimagepickercontroller, didfinishpickingmediawithinfo info: [string : anyobject]) { let qrimg:uiimage = info[uiimagepickercontrolleroriginalimage] as! uiimage if #available(ios 8.0, *) { let detector:cidetector = cidetector(oftype: cidetectortypeqrcode, context:nil, options:[cidetectoraccuracy: cidetectoraccuracyhigh]) let ciimg: ciimage = ciimage(image: qrimg)! let features = detector.featuresinimage(ciimg) feature in features as! [ciqrcodefeature] { print(feature.messagestring) } } else { // fallback on earlier versions } dismissviewcontrolleranimated(true, completion: nil) }
update swift 3 xcode 8.1
// read qrcode selecting image func imagepickercontroller(_ picker: uiimagepickercontroller, didfinishpickingmediawithinfo info: [string : any]) { let qrimg:uiimage = info[uiimagepickercontrolleroriginalimage] as! uiimage if #available(ios 8.0, *) { let detector:cidetector = cidetector(oftype: cidetectortypeqrcode, context:nil, options:[cidetectoraccuracy: cidetectoraccuracyhigh])! let ciimg: ciimage = ciimage(image: qrimg)! let features = detector.features(in: ciimg) feature in features as! [ciqrcodefeature] { print(feature.messagestring!) } } else { // fallback on earlier versions } dismiss(animated: true, completion: nil) }
hope helpfull
Comments
Post a Comment