Tia*_*HUo 6 iphone opencv image-processing image-recognition ipad
我需要从iPhone拍摄的照片中识别,旋转和裁剪矩形(名片).我相信这可以通过使用OpenCV来完成,但我之前没有使用它.有人可以给出一些提示吗?
Ded*_*d77 14
从iOS 8的,你现在可以使用新的检测CIDetectorTypeRectangle返回CIRectangleFeature.您可以添加选项:
宽高比:如果您只想查找正方形,则为1.0
CIImage *image = // your image
NSDictionary *options = @{CIDetectorAccuracy: CIDetectorAccuracyHigh, CIDetectorAspectRatio: @(1.0)};
CIDetector *rectangleDetector = [CIDetector detectorOfType:CIDetectorTypeRectangle context:nil options:options];
NSArray *rectangleFeatures = [rectangleDetector featuresInImage:image];
for (CIRectangleFeature *rectangleFeature in rectangleFeatures) {
CGPoint topLeft = rectangleFeature.topLeft;
CGPoint topRight = rectangleFeature.topRight;
CGPoint bottomLeft = rectangleFeature.bottomLeft;
CGPoint bottomRight = rectangleFeature.bottomRight;
}
Run Code Online (Sandbox Code Playgroud)更多信息参见WWDC 2014 核心图像进展,第514届会议.
请参阅opencv示例代码OpenCV2.2\samples\cpp\squares.cpp.他们执行以下操作:
使用Canny检测边缘
通过检索轮廓 findContours
对于每个轮廓
approxPolyDP用于减少顶点数的近似轮廓
如果轮廓有4个顶点,每个角度为~90度,则产生一个矩形