【问题标题】:Why CIDetector Could not Detect Biggest Rectangle?为什么 CIDetector 无法检测到最大的矩形?
【发布时间】:2017-05-06 18:15:07
【问题描述】:

CIDetector 无法检测到最大的矩形。左图是原始图像,右图是矩形检测图像。它没有检测到整个矩形。我该如何解决?

- (CIDetector *)highAccuracyRectangleDetector
{
    static CIDetector *detector = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^
    {
        detector = [CIDetector detectorOfType:CIDetectorTypeRectangle 
 context:nil options:@{CIDetectorAccuracy : CIDetectorAccuracyHigh}];
    });
    return detector;
}

- (CIRectangleFeature *)_biggestRectangleInRectangles:(NSArray 
*)rectangles
{
    if (![rectangles count]) return nil;

    float halfPerimiterValue = 0;

    CIRectangleFeature *biggestRectangle = [rectangles firstObject];

    for (CIRectangleFeature *rect in rectangles)
    {
        CGPoint p1 = rect.topLeft;
        CGPoint p2 = rect.topRight;
        CGFloat width = hypotf(p2.x - p1.x, p2.y - p1.y);

        CGPoint p3 = rect.topLeft;
        CGPoint p4 = rect.bottomLeft;
        CGFloat height = hypotf(p4.x - p3.x, p4.y - p3.y);
        CGFloat currentHalfPerimiterValue = (height)+(width);
        _RectHeight = height;
        _RectWidth = width;
        if (halfPerimiterValue < currentHalfPerimiterValue)
        {

            halfPerimiterValue = currentHalfPerimiterValue;
            biggestRectangle = rect;
            NSLog(@"height    %@", @(height));
            NSLog(@"width    %@", @(width));
        }
    }

    return biggestRectangle;
}

【问题讨论】:

    标签: ios objective-c core-image


    【解决方案1】:

    最后我通过添加 CIDetectorAspectRatio: @1.667, CIDetectorMaxFeatureCount: @5 解决了这个问题

    - (CIDetector *)highAccuracyRectangleDetector
    {
        static CIDetector *detector = nil;
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^
        {
                detector = [CIDetector detectorOfType:CIDetectorTypeRectangle context:nil options:@{CIDetectorAccuracy : CIDetectorAccuracyHigh, CIDetectorAspectRatio: @1.667, CIDetectorMaxFeatureCount: @5}];
        });
        return detector;
    }
    

    【讨论】:

    • 嗨@Mir Ashraf,你有什么例子可以在ios中检测到正确的矩形吗?
    • 在我的情况下,它有时也会出现错误的对象,它不是矩形形状。请给我建议。谢谢
    猜你喜欢
    • 2019-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-18
    • 2022-01-14
    • 2018-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多