// init bounding
CGRect rect = CGRectMake(0, 0, 0.3, 0.3);
VNSequenceRequestHandler* reqImages = [[VNSequenceRequestHandler alloc] init];
VNRectangleObservation* ObserveRect = [VNRectangleObservation observationWithBoundingBox:rect];
VNTrackRectangleRequest* reqRect = [[VNTrackRectangleRequest alloc] initWithRectangleObservation:ObserveRect];
NSArray<VNRequest *>* requests = [NSArray arrayWithObjects:reqRect, nil];
BOOL bsucc = [reqImages performRequests:requests onCGImage:img.CGImage error:&error];
// get tracking bounding
VNDetectRectanglesRequest* reqRectTrack = [VNDetectRectanglesRequest new];
NSArray<VNRequest *>* requestsTrack = [NSArray arrayWithObjects:reqRectTrack, nil];
[reqImages performRequests:requestsTrack onCGImage:img.CGImage error:&error];
VNRectangleObservation* Observe = [reqRectTrack.results firstObject];
CGRect boundingBox = Observe.boundingBox;
为什么boundingBox值不正确?
如何找到ios11的vision.framework演示?
答案 0 :(得分:3)
Vision Framework跟踪一个对象,可以在此链接找到一个演示:
https://github.com/jeffreybergier/Blog-Getting-Started-with-Vision
Blogger详细介绍了如何让演示工作,并有一个显示工作版本的gif。
希望这就是你所追求的目标。
答案 1 :(得分:3)
以下是使用Vision框架的简单示例:https://github.com/artemnovichkov/iOS-11-by-Examples。我猜你有不同坐标系的问题。注意矩形转换:
cameraLayer.metadataOutputRectConverted(fromLayerRect: originalRect)
和
cameraLayer.layerRectConverted(fromMetadataOutputRect: transformedRect)