首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么CIDetector不能检测到最大的矩形?

为什么CIDetector不能检测到最大的矩形?
EN

Stack Overflow用户
提问于 2017-05-06 06:37:42
回答 1查看 767关注 0票数 2

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

代码语言:javascript
复制
- (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;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-06 10:15:07

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

代码语言:javascript
复制
- (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;
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43817526

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档