gpt4 book ai didi

ios - 为什么 CIDetector 无法检测到最大的矩形?

转载 作者:行者123 更新时间:2023-11-29 11:46:02 26 4
gpt4 key购买 nike

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

Original Image-Detected Image

- (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;
}

最佳答案

最后我通过添加 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;
}

关于ios - 为什么 CIDetector 无法检测到最大的矩形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43817526/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com