{"id":663,"date":"2023-05-30T14:39:14","date_gmt":"2023-05-30T06:39:14","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/?p=663"},"modified":"2023-05-30T14:39:14","modified_gmt":"2023-05-30T06:39:14","slug":"%e5%9c%a8%e7%ba%bf%e7%ad%be%e5%90%8dios%e5%ae%9e%e7%8e%b0%e5%8e%9f%e7%90%86%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2023\/663\/","title":{"rendered":"\u5728\u7ebf\u7b7e\u540dios\u5b9e\u73b0\u539f\u7406\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"

\u5728\u79fb\u52a8\u4e92\u8054\u7f51\u65f6\u4ee3\uff0c\u8d8a\u6765\u8d8a\u591a\u7684\u4e1a\u52a1\u9700\u8981\u5728\u7ebf\u7b7e\u540d\u529f\u80fd\uff0c\u5176\u4e2d\u5305\u62ec\u5408\u540c\u7b7e\u7f72\u3001\u6388\u6743\u8ba4\u8bc1\u7b49\u3002\u800c\u5728iOS\u7cfb\u7edf\u4e2d\uff0c\u4e5f\u63d0\u4f9b\u4e86\u4e00\u79cd\u5feb\u901f\u5b9e\u73b0\u5728\u7ebf\u7b7e\u540d\u7684\u65b9\u6cd5\uff0c\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5176\u539f\u7406\u548c\u4f7f\u7528\u65b9\u5f0f\u3002<\/p>\n

\u4e00\u3001\u539f\u7406<\/p>\n

iOS\u7cfb\u7edf\u4e2d\u7684\u5728\u7ebf\u7b7e\u540d\u529f\u80fd\u4e3b\u8981\u57fa\u4e8eCore Graphics\u6846\u67b6\u7684\u624b\u5199\u7b14\u753b\u8bc6\u522b\u6280\u672f\uff0c\u5176\u539f\u7406\u53ef\u4ee5\u7b80\u8ff0\u4e3a\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a<\/p>\n

1.\u83b7\u53d6\u624b\u5199\u7b14\u753b\uff1a\u901a\u8fc7UIResponder\u7c7b\u4e2d\u7684touch\u4e8b\u4ef6\u83b7\u53d6\u7528\u6237\u624b\u5199\u7b14\u753b\u7684\u5750\u6807\u70b9\uff0c\u5e76\u5c06\u5176\u4fdd\u5b58\u5728\u4e00\u4e2a\u6570\u7ec4\u4e2d\uff1b<\/p>\n

2.\u7ed8\u5236\u624b\u5199\u7b14\u753b\uff1a\u5728UIView\u4e2d\u91cd\u5199drawRect\u65b9\u6cd5\uff0c\u5c06\u4fdd\u5b58\u7684\u624b\u5199\u7b14\u753b\u5750\u6807\u70b9\u8fde\u6210\u7ebf\u6761\uff0c\u5f62\u6210\u624b\u5199\u7b14\u753b\u7684\u56fe\u5f62\uff1b<\/p>\n

3.\u8bc6\u522b\u624b\u5199\u7b14\u753b\uff1a\u901a\u8fc7Core Graphics\u6846\u67b6\u4e2d\u7684UIGraphicsGetImageFromCurrentImageContext\u65b9\u6cd5\u5c06\u624b\u5199\u7b14\u753b\u8f6c\u6362\u6210\u4e00\u5f20\u56fe\u7247\uff0c\u5e76\u5c06\u5176\u4f20\u9012\u7ed9Core ML\u6846\u67b6\u4e2d\u7684\u624b\u5199\u7b14\u753b\u8bc6\u522b\u6a21\u578b\u8fdb\u884c\u8bc6\u522b\uff1b<\/p>\n

4.\u8fd4\u56de\u8bc6\u522b\u7ed3\u679c\uff1a\u5c06\u8bc6\u522b\u7ed3\u679c\u8fd4\u56de\u7ed9\u5e94\u7528\u7a0b\u5e8f\uff0c\u5b9e\u73b0\u5728\u7ebf\u7b7e\u540d\u529f\u80fd\u3002<\/p>\n

\u4e8c\u3001\u4f7f\u7528\u65b9\u5f0f<\/p>\n

\u5728iOS\u7cfb\u7edf\u4e2d\u5b9e\u73b0\u5728\u7ebf\u7b7e\u540d\u529f\u80fd\u7684\u65b9\u5f0f\u6709\u591a\u79cd\uff0c\u4e0b\u9762\u4ecb\u7ecd\u5176\u4e2d\u4e00\u79cd\u6bd4\u8f83\u7b80\u5355\u7684\u5b9e\u73b0\u65b9\u5f0f\u3002<\/p>\n

1.\u521b\u5efa\u4e00\u4e2aUIView\u5b50\u7c7b\uff0c\u7528\u4e8e\u7ed8\u5236\u624b\u5199\u7b14\u753b\uff1b<\/p>\n

2.\u5728UIView\u5b50\u7c7b\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff0c\u5b9e\u73b0\u624b\u5199\u7b14\u753b\u7684\u7ed8\u5236\uff1a<\/p>\n

“`<\/p>\n

– (void)drawRect<\/p>\n

<\/figure>\n<\/p>\n

:(CGRect)rect {<\/p>\n

CGContextRef context = UIGraphicsGetCurrentContext();<\/p>\n

CGContextSetLineWidth(context, 2.0);<\/p>\n

CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);<\/p>\n

CGContextSetLineCap(context, kCGLineCapRound);<\/p>\n

for (int i=0; i<\/p>\n

CGPoint startPoint = [[self.points objectAtIndex:i] CGPointValue];<\/p>\n

CGPoint endPoint = [[self.points objectAtIndex:i+1] CGPointValue];<\/p>\n

CGContextBeginPath(context);<\/p>\n

CGContextMoveToPoint(context, startPoint.x, startPoint.y)\u82f9\u679c\u8bc1\u4e66\u4fe1\u4efb\u8bbe\u7f6e\u91cc\u9762\u7684<\/a>;<\/p>\n

CGContextAddLineToPoint(context, endPoint.x, endPoint.y);<\/p>\n

CGContextStrokePath(context);<\/p>\n

}<\/p>\n

}<\/p>\n

“`<\/p>\n

3.\u5728UIViewController\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff0c\u5b9e\u73b0\u624b\u5199\u7b14\u753b\u7684\u8bc6\u522b\uff1a<\/p>\n

“`<\/p>\n

– (IBAction)recognizeSignature:(id)sender {<\/p>\n

UIGraphicsBeginImageContext(self.signatureView.bounds.size);<\/p>\n

[self.signatureView.layer renderInContext:UIGraphicsGetCurrentContext()];<\/p>\n

UIImage *signatureImage = UIGraphicsGetImageFromCurrentImageContext();<\/p>\n

UIGraphicsEndImageContext();<\/p>\n

UIImage *scaledImage = [self scaleImage:signatureImage toSize:CGSizeMake(28, 28)];<\/p>\n

NSError *error;<\/p>\n

MNIST *model = [[MNIST alloc] init];<\/p>\n

MNISTOutput *output = [model predictionFromImage:scaledImage error:&error];<\/p>\n

if (error) {<\/p>\n

NSLog(@”Error: %@”, error.localizedDescription);<\/p>\n

} else {<\/p>\n

ios\u5f00\u53d1\u8005\u7b7e\u540dudd<\/a> NSLog(@”Output: %@”, output.classLabel);<\/p>\n

}<\/p>\n

}<\/p>\n

– (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)size {<\/p>\n

UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);<\/p>\n

[image drawInRect:CGRectMake(0, 0, size.width, size.height)];<\/p>\n

UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();<\/p>\n

UIGraphicsEndImageContext();<\/p>\n

return scaledImage;<\/p>\n

}<\/p>\n

“`<\/p>\n

\u5176\u4e2d\uff0cMNIST\u662f\u4e00\u4e2a\u7528\u4e8e\u624b\u5199\u6570\u5b57\u8bc6\u522b\u7684Core ML\u6a21\u578b\uff0c\u53ef\u4ee5\u901a\u8fc7Core ML\u6846\u67b6\u5bfc\u5165\u4f7f\u7528\u3002<\/p>\n

\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u5373\u53ef\u5b9e\u73b0iOS\u7cfb\u7edf\u4e2d\u7684\u5728\u7ebf\u7b7e\u540d\u529f\u80fd\u3002<\/p>\n

\u4e09\u3001\u603b\u7ed3<\/p>\n

iOS\u7cfb\u7edf\u4e2d\u7684\u5728\u7ebf\u7b7e\u540d\u529f\u80fd\u4e3b\u8981\u57fa\u4e8eCore Graphics\u6846\u67b6\u7684\u624b\u5199\u7b14\u753b\u8bc6\u522b\u6280\u672f\uff0c\u5176\u539f\u7406\u6bd4\u8f83\u7b80\u5355\uff0c\u4f7f\u7528\u4e5f\u6bd4\u8f83\u65b9\u4fbf\u3002\u901a\u8fc7\u4ee5\u4e0a\u4ecb\u7ecd\uff0c\u76f8\u4fe1\u8bfb\u8005\u80fd\u591f\u4e86\u89e3iOS\u7cfb\u7edf\u4e2d\u5728\u7ebf\u7b7e\u540d\u7684\u539f\u7406\u548c\u4f7f\u7528\u65b9\u5f0f\uff0c\u4e3a\u79fb\u52a8\u4e92\u8054\u7f51\u4e1a\u52a1\u7684\u5f00\u53d1\u63d0\u4f9b\u66f4\u591a\u4fbf\u5229\u3002<\/p>\n

\u4e00\u95e8APP\u8bc1\u4e66\u5236\u4f5c\u5de5\u5177(https:\/\/platform.yimenapp.com\/)\u63d0\u4f9bAPP\u8bc1\u4e66\u5728\u7ebf\u5236\u4f5c\uff0c\u652f\u6301\u82f9\u679c\u8bc1\u4e66\u3001\u5b89\u5353\u8bc1\u4e66\u5728\u7ebf\u4e00\u952e\u5feb\u6377\u5236\u4f5c\u3002\u5de5\u5177\u5b8c\u5168\u514d\u8d39\uff0c\u6ce8\u518c\u6210\u4e3a\u4e00\u95e8APP\u5f00\u53d1\u8005\u5373\u53ef\u4f7f\u7528\uff0c\u5168\u4e2d\u6587\u5316\u4e91\u7aefAPP\u8bc1\u4e66\u5de5\u5177\u3002
\n\u4e00\u952e\u5236\u4f5cIOS\u82f9\u679c\u8bc1\u4e66\uff0c\u5305\u542bappstore\u4e0a\u67b6\u8bc1\u4e66\u3001\u5f00\u53d1\u73af\u5883\u6d4b\u8bd5\u8bc1\u4e66\u3001ADhoc\u751f\u4ea7\u73af\u5883\u6d4b\u8bd5\u8bc1\u4e66\u3001\u5728\u7ebf\u751f\u6210P12\u5f00\u53d1\u8005\u8bc1\u4e66\u8bc1\u4e66\uff0cP12\u63a8\u9001\u8bc1\u4e66\u3001P8\u63a8\u9001\u8bc1\u4e66\uff0c\u5feb\u6377\u7ed1\u5b9aUDID\u3001\u81ea\u5b9a\u4e49\u5305\u540dBundle ID\u3001\u5728\u7ebf\u83b7\u53d6\u63cf\u8ff0\u6587\u4ef6\uff1b
\n\u4e00\u952e\u5236\u4f5c\u5b89\u5353\u8bc1\u4e66\uff0c\u652f\u6301\u81ea\u5b9a\u4e49\u5b89\u5353\u5305\u540d\u3001\u7b7e\u540d\u6587\u4ef6\u5bc6\u7801(storepass)\u3001\u522b\u540d(alias)\u3001\u522b\u540d\u5bc6\u7801(keypass)\u3001\u516c\u53f8\/\u673a\u6784\u540d\u79f0 (O)\u3001\u90e8\u95e8 (OU)\u3001\u56fd\u5bb6\/\u5730\u533a (C)\u3001\u7701\u4efd (ST)\u3001\u57ce\u5e02 (L)\u3001\u90ae\u7bb1 (E)\u3001\u4ee5\u53ca\u5b89\u5353\u8bc1\u4e66\u6709\u6548\u671f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728\u79fb\u52a8\u4e92\u8054\u7f51\u65f6\u4ee3\uff0c\u8d8a\u6765\u8d8a\u591a\u7684\u4e1a\u52a1\u9700\u8981\u5728\u7ebf\u7b7e\u540d\u529f\u80fd\uff0c\u5176\u4e2d\u5305\u62ec\u5408\u540c\u7b7e\u7f72\u3001\u6388\u6743\u8ba4\u8bc1\u7b49\u3002\u800c\u5728iOS\u7cfb\u7edf\u4e2d\uff0c\u4e5f\u63d0\u4f9b\u4e86\u4e00\u79cd\u5feb\u901f\u5b9e\u73b0\u5728\u7ebf\u7b7e\u540d\u7684\u65b9\u6cd5\uff0c\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5176\u539f\u7406\u548c\u4f7f\u7528\u65b9\u5f0f\u3002\u4e00\u3001\u539f\u7406iOS\u7cfb\u7edf\u4e2d\u7684\u5728\u7ebf\u7b7e\u540d\u529f<\/p>\n","protected":false},"author":25,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[1543,86,74,1541,1542],"class_list":["post-663","post","type-post","status-publish","format-standard","hentry","category-appzhengshu","tag-ios","tag-86","tag-74","tag-1541","tag-1542"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/663","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=663"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/663\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}