CIDetector not detecting proper Rectangle in iOS?

2019-01-29 03:08发布

问题:

I am trying to detect a Rectangle using CIDetector.

I am using code from this: https://www.cocoacontrols.com/controls/vnimagescanner

My problem is when I am trying to detect any Rectangle object, sometimes it's detecting or sometimes it's detecting Odd Rectangle (please see below images). I tried to search this Google but didn't find any solution of this.

Normal case:

Some bad case:

Here is my code to set the CIDetector Accuracy :

func highAccuracyRectangleDetector() -> CIDetector? {
   var detector: CIDetector? = nil
   detector = CIDetector(ofType: CIDetectorTypeRectangle, context: nil, options: [CIDetectorAccuracy: CIDetectorAccuracyHigh, CIDetectorAspectRatio: 1.43, CIDetectorMaxFeatureCount: 5])

   return detector
}

If you will look into third image, it's highlighting without Rectangle object.

Is it possible to detect or to display the highlighted green overlay when there will be a proper Rectangle? Please suggest me.