{"id":492,"date":"2023-11-04T12:15:12","date_gmt":"2023-11-04T04:15:12","guid":{"rendered":"http:\/\/ai.gitpp.com\/?p=492"},"modified":"2023-11-04T12:16:41","modified_gmt":"2023-11-04T04:16:41","slug":"github%e9%a1%b9%e7%9b%ae%e8%bf%9b%e9%98%b6%ef%bc%9a%e5%a6%82%e4%bd%95%e5%9c%a8%e7%9f%ad%e7%9f%ad-5-%e5%88%86%e9%92%9f%e5%86%85%e6%9e%84%e5%bb%ba%e4%b8%80%e4%b8%aa%e5%bc%ba%e5%a4%a7%e7%9a%84%e7%a7%bb","status":"publish","type":"post","link":"http:\/\/ai.gitpp.com\/index.php\/2023\/11\/04\/github%e9%a1%b9%e7%9b%ae%e8%bf%9b%e9%98%b6%ef%bc%9a%e5%a6%82%e4%bd%95%e5%9c%a8%e7%9f%ad%e7%9f%ad-5-%e5%88%86%e9%92%9f%e5%86%85%e6%9e%84%e5%bb%ba%e4%b8%80%e4%b8%aa%e5%bc%ba%e5%a4%a7%e7%9a%84%e7%a7%bb\/","title":{"rendered":"GitHub\u9879\u76ee\u8fdb\u9636\uff1a\u5982\u4f55\u5728\u77ed\u77ed 5 \u5206\u949f\u5185\u6784\u5efa\u4e00\u4e2a\u5f3a\u5927\u7684\u79fb\u52a8\u6587\u6863\u626b\u63cf\u4eea\uff0c\u6709\u6e90\u4ee3\u7801"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u7528\u624b\u673a\u8bc6\u522b\u626b\u63cf\u6587\u5b57\uff0c\u76ee\u524d\u5df2\u7ecf\u975e\u5e38\u6210\u719f\uff0c\u672c\u6587\u4ecb\u7ecd<\/p>\n\n\n\n<p>\u5c06\u4ee5\u4e0a\u56fe\u7247\u6587\u5b57\u63d0\u53d6\u51fa\u6765<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"437\" src=\"http:\/\/ai.gitpp.com\/wp-content\/uploads\/2023\/11\/w1.jpg\" alt=\"\" class=\"wp-image-493\" srcset=\"http:\/\/ai.gitpp.com\/wp-content\/uploads\/2023\/11\/w1.jpg 600w, http:\/\/ai.gitpp.com\/wp-content\/uploads\/2023\/11\/w1-300x219.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/figure>\n\n\n\n<p>\u4f7f\u7528 OpenCV \u6784\u5efa\u6587\u6863\u626b\u63cf\u4eea\u53ea\u9700\u4e09\u4e2a\u7b80\u5355\u6b65\u9aa4\u5373\u53ef\u5b8c\u6210\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6b65\u9aa41\uff1a<\/strong>\u68c0\u6d4b\u8fb9\u7f18\u3002<\/li>\n\n\n\n<li><strong>\u6b65\u9aa4 2\uff1a<\/strong>\u4f7f\u7528\u56fe\u50cf\u4e2d\u7684\u8fb9\u7f18\u627e\u5230\u4ee3\u8868\u6b63\u5728\u626b\u63cf\u7684\u7eb8\u5f20\u7684\u8f6e\u5ed3\uff08\u8f6e\u5ed3\uff09\u3002<\/li>\n\n\n\n<li><strong>\u6b65\u9aa4 3\uff1a<\/strong>\u5e94\u7528\u900f\u89c6\u53d8\u6362\u4ee5\u83b7\u5f97\u6587\u6863\u7684\u81ea\u4e0a\u800c\u4e0b\u89c6\u56fe\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u771f\u7684\u3002\u5c31\u662f\u8fd9\u6837\u3002<\/p>\n\n\n\n<p>\u53ea\u9700\u4e09\u4e2a\u6b65\u9aa4\uff0c\u60a8\u5c31\u53ef\u4ee5\u5c06\u81ea\u5df1\u7684\u6587\u6863\u626b\u63cf\u5e94\u7528\u7a0b\u5e8f\u63d0\u4ea4\u5230 App Store\u3002<\/p>\n\n\n\n<p>\u542c\u8d77\u6765\u5f88\u6709\u8da3\uff1f<\/p>\n\n\n\n<p>\u8bf7\u7ee7\u7eed\u9605\u8bfb\u3002\u5e76\u89e3\u9501\u6784\u5efa\u60a8\u81ea\u5df1\u7684\u624b\u673a\u626b\u63cf\u4eea\u5e94\u7528\u7a0b\u5e8f\u7684\u79d8\u5bc6\u3002<\/p>\n\n\n\n<p>\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\uff0c\u5c06\u5176\u547d\u540d\u4e3a<code>scan.py<\/code>\uff0c\u7136\u540e\u8ba9\u6211\u4eec\u5f00\u59cb\u5427\u3002<\/p>\n\n\n\n<p>#\u5bfc\u5165\u5fc5\u8981\u7684\u5305<br>\u4ece pyimagesearch.transform \u5bfc\u5165 four_point_transform<br>\u4eceskimage.filters\u5bfc\u5165threshold_local<br>\u5c06 numpy \u5bfc\u5165\u4e3a np<br>\u5bfc\u5165argparse<br>\u5bfc\u5165CV2<br>\u5bfc\u5165imutils<\/p>\n\n\n\n<p># \u6784\u9020\u53c2\u6570\u89e3\u6790\u5668\u5e76\u89e3\u6790\u53c2\u6570<br>ap = argparse.ArgumentParser()<br>ap.add_argument(&#8220;-i&#8221;, &#8220;&#8211;image&#8221;, required = True,<br>help =\u201c\u8981\u626b\u63cf\u7684\u56fe\u50cf\u7684\u8def\u5f84\u201d\uff09<\/p>\n\n\n\n<p>args = vars(ap.parse_args())<br><\/p>\n\n\n\n<p><strong>\u7b2c 2-7 \u884c<\/strong>\u5904\u7406\u5bfc\u5165\u6211\u4eec\u9700\u8981\u7684\u5fc5\u8981 Python \u5305\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u8fd8\u5c06\u4f7f\u7528\u8be5<code>imutils<\/code>&nbsp;\u6a21\u5757\uff0c\u5176\u4e2d\u5305\u542b\u7528\u4e8e\u8c03\u6574\u56fe\u50cf\u5927\u5c0f\u3001\u65cb\u8f6c\u548c\u88c1\u526a\u56fe\u50cf\u7684\u4fbf\u5229\u529f\u80fd\u3002<code>imutils<\/code>&nbsp;\u60a8\u53ef\u4ee5\u5728\u6211\u7684\u8fd9\u7bc7\u6587\u7ae0\u4e2d\u9605\u8bfb\u66f4\u591a\u76f8\u5173\u5185\u5bb9\u3002\u8981\u5b89\u88c5<code>imutils<\/code>\uff0c\u53ea\u9700\uff1a$ pip install &#8211;upgrade imutils<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\uff0c\u8ba9\u6211\u4eec<code>threshold_local<\/code>&nbsp;\u4ecescikit-image\u5bfc\u5165\u8be5\u51fd\u6570\u3002\u6b64\u529f\u80fd\u5c06\u5e2e\u52a9\u6211\u4eec\u83b7\u5f97\u626b\u63cf\u56fe\u50cf\u7684\u201c\u9ed1\u767d\u201d\u611f\u89c9\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b2c 1 \u6b65\uff1a\u8fb9\u7f18\u68c0\u6d4b<\/h2>\n\n\n\n<p>\u4f7f\u7528 OpenCV \u6784\u5efa\u6587\u6863\u626b\u63cf\u4eea\u5e94\u7528\u7a0b\u5e8f\u7684\u7b2c\u4e00\u6b65\u662f\u6267\u884c\u8fb9\u7f18\u68c0\u6d4b\u3002\u8ba9\u6211\u4eec\u6765\u770b\u770b\uff1a# \u52a0\u8f7d\u56fe\u50cf\u5e76\u8ba1\u7b97\u65e7\u9ad8\u5ea6\u7684\u6bd4\u4f8b<\/p>\n\n\n\n<p># \u5230\u65b0\u7684\u9ad8\u5ea6\uff0c\u514b\u9686\u5b83\uff0c\u5e76\u8c03\u6574\u5b83\u7684\u5927\u5c0f<br>image = cv2.imread(args[&#8220;image&#8221;])<br>ratio = image.shape[0] \/ 500.0<br>orig = image.copy()<br>image = imutils.resize(image, height = 500)<\/p>\n\n\n\n<p># convert the image to grayscale, blur it, and find edges<br># in the image<br>gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)<br>gray = cv2.GaussianBlur(gray, (5, 5), 0)<br>edged = cv2.Canny(gray, 75, 200)<\/p>\n\n\n\n<p># show the original image and the edge detected image<br>print(&#8220;STEP 1: Edge Detection&#8221;)<br>cv2.imshow(&#8220;Image&#8221;, image)<br>cv2.imshow(&#8220;Edged&#8221;, edged)<br>cv2.waitKey(0)<br>cv2.destroyAllWindows()<\/p>\n\n\n\n<p><strong>\u9996\u5148\uff0c\u6211\u4eec\u5728\u7b2c 17 \u884c<\/strong>\u4ece\u78c1\u76d8\u52a0\u8f7d\u56fe\u50cf\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u52a0\u5feb\u56fe\u50cf\u5904\u7406\u901f\u5ea6\uff0c\u5e76\u4f7f\u8fb9\u7f18\u68c0\u6d4b\u6b65\u9aa4\u66f4\u52a0\u51c6\u786e\uff0c\u6211\u4eec\u5c06\u626b\u63cf\u56fe\u50cf\u7684\u5927\u5c0f\u8c03\u6574\u4e3a\u7b2c<strong>17-20 \u884c<\/strong>\u7684 500 \u50cf\u7d20\u9ad8\u5ea6\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u8fd8\u7279\u522b\u6ce8\u610f\u8ddf\u8e2a<code>ratio<\/code>&nbsp;\u56fe\u50cf\u7684\u539f\u59cb\u9ad8\u5ea6\u5230\u65b0\u9ad8\u5ea6\uff08<strong>\u7b2c 18 \u884c<\/strong>\uff09\u2014\u2014\u8fd9\u5c06\u4f7f\u6211\u4eec\u80fd\u591f\u5bf9<em>\u539f\u59cb<\/em>\u56fe\u50cf\u800c\u4e0d\u662f<em>\u8c03\u6574\u5927\u5c0f\u7684<\/em>\u56fe\u50cf\u6267\u884c\u626b\u63cf\u3002<\/p>\n\n\n\n<p><strong>\u4ece\u8fd9\u91cc\u5f00\u59cb\uff0c\u6211\u4eec\u5728\u7b2c 24<\/strong>\u884c\u5c06\u56fe\u50cf\u4ece RGB \u8f6c\u6362\u4e3a\u7070\u5ea6\uff0c\u6267\u884c\u9ad8\u65af\u6a21\u7cca\u4ee5\u53bb\u9664\u9ad8\u9891\u566a\u58f0\uff08\u6709\u52a9\u4e8e\u6b65\u9aa4 2 \u4e2d\u7684\u8f6e\u5ed3\u68c0\u6d4b\uff09\uff0c\u5e76\u5728<strong>\u7b2c 26 \u884c<\/strong>\u6267\u884c Canny \u8fb9\u7f18\u68c0\u6d4b\u3002<\/p>\n\n\n\n<p>\u6b65\u9aa4 1 \u7684\u8f93\u51fa\u663e\u793a\u5728<strong>\u7b2c 30 \u884c\u548c\u7b2c 31 \u884c<\/strong>\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"428\" src=\"http:\/\/ai.gitpp.com\/wp-content\/uploads\/2023\/11\/w2.jpg\" alt=\"\" class=\"wp-image-494\" srcset=\"http:\/\/ai.gitpp.com\/wp-content\/uploads\/2023\/11\/w2.jpg 600w, http:\/\/ai.gitpp.com\/wp-content\/uploads\/2023\/11\/w2-300x214.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/figure>\n\n\n\n<p>\u6b65\u9aa4 1 \u7684\u8f93\u51fa\u663e\u793a\u5728<strong>\u7b2c 30 \u884c\u548c\u7b2c 31 \u884c<\/strong>\u3002<\/p>\n\n\n\n<p>\u8bf7\u770b\u4e0b\u9762\u7684\u793a\u4f8b\u6587\u6863\uff1a<\/p>\n\n\n\n<p>\u5728\u5de6\u8fb9\u4f60\u53ef\u4ee5\u770b\u5230\u6211\u4ece Whole Foods \u5bc4\u6765\u7684\u6536\u636e\u3002\u6ce8\u610f\u7167\u7247\u662f\u5982\u4f55\u4ee5\u4e00\u5b9a\u89d2\u5ea6\u62cd\u6444\u7684\u3002\u8fd9\u7edd\u5bf9\u4e0d\u662f 90 \u5ea6\u3001\u81ea\u4e0a\u800c\u4e0b\u7684\u9875\u9762\u89c6\u56fe\u3002\u6b64\u5916\uff0c\u56fe\u4e2d\u8fd8\u6709\u6211\u7684\u529e\u516c\u684c\u3002\u5f53\u7136\uff0c\u8fd9\u4e0d\u662f\u4efb\u4f55\u624b\u6bb5\u7684\u201c\u626b\u63cf\u201d\u3002\u6211\u4eec\u5df2\u7ecf\u5b8c\u6210\u4e86\u6211\u4eec\u7684\u5de5\u4f5c\u3002<\/p>\n\n\n\n<p>\u7136\u800c\uff0c\u5728\u53f3\u4fa7\u60a8\u53ef\u4ee5\u770b\u5230\u6267\u884c\u8fb9\u7f18\u68c0\u6d4b\u540e\u7684\u56fe\u50cf\u3002\u6211\u4eec\u53ef\u4ee5\u6e05\u695a\u5730\u770b\u5230\u6536\u636e\u7684\u8f6e\u5ed3\u3002<\/p>\n\n\n\n<p>\u4e0d\u9519\u7684\u5f00\u59cb\u3002<\/p>\n\n\n\n<p>\u8ba9\u6211\u4eec\u7ee7\u7eed\u6b65\u9aa4 2\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b2c\u4e8c\u6b65\uff1a\u5bfb\u627e\u8f6e\u5ed3<\/h2>\n\n\n\n<p>\u8f6e\u5ed3\u68c0\u6d4b\u5e76\u4e0d\u4e00\u5b9a\u5f88\u56f0\u96be\u3002<\/p>\n\n\n\n<p>\u4e8b\u5b9e\u4e0a\uff0c\u5728\u6784\u5efa\u6587\u6863\u626b\u63cf\u4eea\u65f6\uff0c\u60a8\u5b9e\u9645\u4e0a\u62e5\u6709\u4e00\u4e2a<em>\u5f88\u5927\u7684\u4f18\u52bf&#8230;&#8230;<\/em><\/p>\n\n\n\n<p>\u82b1\u70b9\u65f6\u95f4\u8003\u8651\u4e00\u4e0b\u6211\u4eec\u5b9e\u9645\u6b63\u5728\u6784\u5efa\u7684\u5185\u5bb9\u3002<\/p>\n\n\n\n<p>\u6587\u6863\u626b\u63cf\u4eea\u53ea\u9700\u626b\u63cf\u4e00\u5f20\u7eb8\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u5047\u8bbe\u4e00\u5f20\u7eb8\u662f\u4e00\u4e2a\u77e9\u5f62\u3002<\/p>\n\n\n\n<p>\u77e9\u5f62\u6709\u56db\u4e2a\u8fb9\u3002<\/p>\n\n\n\n<p>\u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u542f\u53d1\u5f0f\u65b9\u6cd5\u6765\u5e2e\u52a9\u6211\u4eec\u6784\u5efa\u6587\u6863\u626b\u63cf\u4eea\u3002<\/p>\n\n\n\n<p>\u542f\u53d1\u5f0f\u662f\u8fd9\u6837\u7684\uff1a\u6211\u4eec\u5047\u8bbe\u56fe\u50cf\u4e2d<em>\u6070\u597d\u6709\u56db\u4e2a\u70b9\u7684<\/em><em>\u6700\u5927\u8f6e\u5ed3<\/em>\u662f\u6211\u4eec\u8981\u626b\u63cf\u7684\u7eb8\u5f20\u3002<em><\/em><\/p>\n\n\n\n<p>\u8fd9\u4e5f\u662f\u4e00\u4e2a\u76f8\u5f53\u5b89\u5168\u7684\u5047\u8bbe &#8211; \u626b\u63cf\u4eea\u5e94\u7528\u7a0b\u5e8f\u53ea\u662f\u5047\u8bbe\u60a8\u8981\u626b\u63cf\u7684\u6587\u6863\u662f\u6211\u4eec\u56fe\u50cf\u7684\u4e3b\u8981\u7126\u70b9\u3002\u5e76\u4e14\u53ef\u4ee5\u5b89\u5168\u5730\u5047\u8bbe\uff08\u6216\u81f3\u5c11\u5e94\u8be5\u5982\u6b64\uff09\u8fd9\u5f20\u7eb8\u6709\u56db\u4e2a\u8fb9\u7f18\u3002<\/p>\n\n\n\n<p>\u8fd9\u6b63\u662f\u4e0b\u9762\u7684\u4ee3\u7801\u6240\u505a\u7684\uff1a<br># \u627e\u5230\u8fb9\u7f18\u56fe\u50cf\u4e2d\u7684\u8f6e\u5ed3\uff0c\u53ea\u4fdd\u7559<br># \u6700\u5927\u7684\uff0c\u5e76\u521d\u59cb\u5316\u5c4f\u5e55\u8f6e\u5ed3cnts = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)<br>cnts = imutils.grab_contours(cnts)<br>cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:5]<\/p>\n\n\n\n<p># loop over the contours<br>for c in cnts:<br># approximate the contour<br>peri = cv2.arcLength(c, True)<br>approx = cv2.approxPolyDP(c, 0.02 * peri, True)<\/p>\n\n\n\n<p># if our approximated contour has four points, then we<br># can assume that we have found our screen<br>if len(approx) == 4:<br>screenCnt = approx<br>break<\/p>\n\n\n\n<p># show the contour (outline) of the piece of paper<br>print(&#8220;STEP 2: Find contours of paper&#8221;)<br>cv2.drawContours(image, [screenCnt], -1, (0, 255, 0), 2)<br>cv2.imshow(&#8220;Outline&#8221;, image)<br>cv2.waitKey(0)<br>cv2.destroyAllWindows()<\/p>\n\n\n\n<p><strong>\u6211\u4eec\u9996\u5148\u5728\u7b2c 37<\/strong>\u884c\u627e\u5230\u8fb9\u7f18\u56fe\u50cf\u4e2d\u7684\u8f6e\u5ed3\u3002<strong>\u6211\u4eec\u8fd8\u5904\u7406\u4e86 OpenCV 2.4\u3001OpenCV 3 \u548c OpenCV 4 \u5728\u7b2c 38 \u884c<\/strong>\u4ee5\u4e0d\u540c\u65b9\u5f0f\u8fd4\u56de\u8f6e\u5ed3\u7684\u4e8b\u5b9e\u3002<\/p>\n\n\n\n<p>\u6211\u559c\u6b22\u505a\u7684\u4e00\u4e2a\u5de7\u5999\u7684\u6027\u80fd\u9ed1\u5ba2\u5b9e\u9645\u4e0a\u662f\u6309\u533a\u57df\u5bf9\u8f6e\u5ed3\u8fdb\u884c\u6392\u5e8f\uff0c\u5e76\u53ea\u4fdd\u7559\u6700\u5927\u7684\u8f6e\u5ed3\uff08<strong>\u7b2c 39 \u884c<\/strong>\uff09\u3002\u8fd9\u4f7f\u6211\u4eec\u80fd\u591f\u4ec5\u68c0\u67e5\u6700\u5927\u7684\u8f6e\u5ed3\uff0c\u800c\u4e22\u5f03\u5176\u4f59\u7684\u3002<\/p>\n\n\n\n<p><strong>\u7136\u540e\uff0c\u6211\u4eec\u5f00\u59cb\u5728Line 42<\/strong>\u4e0a\u7684\u8f6e\u5ed3\u4e0a\u5faa\u73af\uff0c\u5e76\u8fd1\u4f3c\u8ba1\u7b97<strong>Line 44 \u548c 45<\/strong>\u4e0a\u7684\u70b9\u6570\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u8fd1\u4f3c\u8f6e\u5ed3\u6709\u56db\u4e2a\u70b9\uff08<strong>\u7b2c 49 \u884c<\/strong>\uff09\uff0c\u6211\u4eec\u5047\u8bbe\u6211\u4eec\u5df2\u7ecf\u5728\u56fe\u50cf\u4e2d\u627e\u5230\u4e86\u6587\u6863\u3002<\/p>\n\n\n\n<p>\u518d\u8bf4\u4e00\u6b21\uff0c\u8fd9\u662f\u4e00\u4e2a\u76f8\u5f53\u5b89\u5168\u7684\u5047\u8bbe\u3002\u626b\u63cf\u4eea\u5e94\u7528\u7a0b\u5e8f\u5c06\u5047\u8bbe (1) \u8981\u626b\u63cf\u7684\u6587\u6863\u662f\u56fe\u50cf\u7684\u4e3b\u8981\u7126\u70b9\uff0c\u5e76\u4e14 (2) \u6587\u6863\u662f\u77e9\u5f62\u7684\uff0c\u56e0\u6b64\u5c06\u5177\u6709\u56db\u4e2a\u4e0d\u540c\u7684\u8fb9\u7f18\u3002<\/p>\n\n\n\n<p>\u4ece\u90a3\u91cc\u5f00\u59cb\uff0c<strong>\u7b2c 55 \u884c\u548c\u7b2c 56 \u884c<\/strong>\u663e\u793a\u4e86\u6211\u4eec\u8981\u626b\u63cf\u7684\u6587\u6863\u7684\u8f6e\u5ed3\u3002<\/p>\n\n\n\n<p>\u73b0\u5728\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u793a\u4f8b\u56fe\u50cf\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"822\" src=\"http:\/\/ai.gitpp.com\/wp-content\/uploads\/2023\/11\/w3.jpg\" alt=\"\" class=\"wp-image-495\" srcset=\"http:\/\/ai.gitpp.com\/wp-content\/uploads\/2023\/11\/w3.jpg 600w, http:\/\/ai.gitpp.com\/wp-content\/uploads\/2023\/11\/w3-219x300.jpg 219w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/figure>\n\n\n\n<p>\u6b63\u5982\u60a8\u6240\u770b\u5230\u7684\uff0c\u6211\u4eec\u5df2\u7ecf\u6210\u529f\u5730\u5229\u7528\u8fb9\u7f18\u68c0\u6d4b\u56fe\u50cf\u6765\u627e\u5230\u6587\u6863\u7684\u8f6e\u5ed3\uff08\u8f6e\u5ed3\uff09\uff0c\u5982\u6536\u636e\u5468\u56f4\u7684\u7eff\u8272\u77e9\u5f62\u6240\u793a\u3002<\/p>\n\n\n\n<p>\u6700\u540e\uff0c\u8ba9\u6211\u4eec\u7ee7\u7eed\u6b65\u9aa4 3\uff0c\u8fd9\u5c06\u662f\u4f7f\u7528\u6211\u7684 four_point_transform \u51fd\u6570\u7684\u4e00\u4e2a\u7b80\u5355\u6b65\u9aa4\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7b2c 3 \u6b65\uff1a\u5e94\u7528\u900f\u89c6\u53d8\u6362\u548c\u9608\u503c<\/h2>\n\n\n\n<p>\u6784\u5efa\u79fb\u52a8\u6587\u6863\u626b\u63cf\u4eea\u7684\u6700\u540e\u4e00\u6b65\u662f\u83b7\u53d6\u4ee3\u8868\u6587\u6863\u8f6e\u5ed3\u7684\u56db\u4e2a\u70b9\u5e76\u5e94\u7528\u900f\u89c6\u53d8\u6362\u4ee5\u83b7\u5f97\u56fe\u50cf\u7684\u81ea\u4e0a\u800c\u4e0b\u7684\u201c\u9e1f\u77b0\u56fe\u201d\u3002<\/p>\n\n\n\n<p>\u8ba9\u6211\u4eec\u6765\u770b\u770b\uff1a# \u5e94\u7528\u56db\u70b9\u53d8\u6362\u4ee5\u83b7\u5f97\u81ea\u9876\u5411\u4e0b<br># \u539f\u59cb\u56fe\u50cf\u7684\u89c6\u56fewarped = four_point_transform(orig, screenCnt.reshape(4, 2) * ratio)<\/p>\n\n\n\n<p># convert the warped image to grayscale, then threshold it<br># to give it that &#8216;black and white&#8217; paper effect<br>warped = cv2.cvtColor(warped, cv2.COLOR_BGR2GRAY)<br>T = threshold_local(warped, 11, offset = 10, method = &#8220;gaussian&#8221;)<br>warped = (warped &gt; T).astype(&#8220;uint8&#8221;) * 255<\/p>\n\n\n\n<p># show the original and scanned images<br>print(&#8220;STEP 3: Apply perspective transform&#8221;)<br>cv2.imshow(&#8220;Original&#8221;, imutils.resize(orig, height = 650))<br>cv2.imshow(&#8220;Scanned&#8221;, imutils.resize(warped, height = 650))<br>cv2.waitKey(0)<\/p>\n\n\n\n<p><strong>\u7b2c 62 \u884c<\/strong>\u6267\u884c\u626d\u66f2\u53d8\u6362\u3002\u4e8b\u5b9e\u4e0a\uff0c\u6240\u6709\u7e41\u91cd\u7684\u5de5\u4f5c\u90fd\u662f\u7531\u8be5<code>four_point_transform<\/code>&nbsp;\u51fd\u6570\u5904\u7406\u7684\u3002\u540c\u6837\uff0c\u60a8\u53ef\u4ee5\u5728\u4e0a\u5468\u7684\u5e16\u5b50\u4e2d\u9605\u8bfb\u6709\u5173\u6b64\u529f\u80fd\u7684\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u5c06\u5411 \u4e2d\u4f20\u9012\u4e24\u4e2a\u53c2\u6570<code>four_point_transform<\/code>\uff1a\u7b2c\u4e00\u4e2a\u662f\u4ece\u78c1\u76d8\u52a0\u8f7d\u7684\u539f\u59cb\u56fe\u50cf\uff08<em>\u4e0d\u662f<\/em>\u8c03\u6574\u5927\u5c0f\u7684\u56fe\u50cf\uff09\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u8868\u793a\u6587\u6863\u7684\u8f6e\u5ed3\u4e58\u4ee5\u8c03\u6574\u5927\u5c0f\u7684\u6bd4\u7387\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\uff0c\u60a8\u53ef\u80fd\u60f3\u77e5\u9053\uff0c\u4e3a\u4ec0\u4e48\u6211\u4eec\u8981\u4e58\u4ee5\u8c03\u6574\u5927\u5c0f\u7684\u6bd4\u7387\uff1f<\/p>\n\n\n\n<p>\u6211\u4eec\u4e58\u4ee5\u8c03\u6574\u5927\u5c0f\u7684\u6bd4\u7387\uff0c\u56e0\u4e3a\u6211\u4eec\u6267\u884c\u4e86\u8fb9\u7f18\u68c0\u6d4b\u5e76\u5728<em>\u9ad8\u5ea6 = 500<\/em>\u50cf\u7d20\u7684\u8c03\u6574\u5927\u5c0f\u7684\u56fe\u50cf\u4e0a\u627e\u5230\u4e86\u8f6e\u5ed3\u3002<\/p>\n\n\n\n<p>\u7136\u800c\uff0c\u6211\u4eec\u60f3\u8981\u5728<em>\u539f\u59cb<\/em>\u56fe\u50cf\u4e0a\u6267\u884c\u626b\u63cf\uff0c<strong><em>\u800c\u4e0d\u662f<\/em><\/strong>\u8c03\u6574<em>\u5927\u5c0f\u7684<\/em>\u56fe\u50cf\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u8f6e\u5ed3\u70b9\u4e58\u4ee5\u8c03\u6574\u5927\u5c0f\u7684\u6bd4\u7387\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u83b7\u5f97\u56fe\u50cf\u7684\u9ed1\u767d\u611f\u89c9\uff0c\u6211\u4eec\u83b7\u53d6\u626d\u66f2\u7684\u56fe\u50cf\uff0c\u5c06\u5176\u8f6c\u6362\u4e3a\u7070\u5ea6\u5e76\u5728<strong>\u7b2c 66-68 \u884c<\/strong>\u5e94\u7528\u81ea\u9002\u5e94\u9608\u503c\u5904\u7406\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>\u6700\u540e\uff0c\u6211\u4eec\u5728\u7b2c 72-74 \u884c<\/strong>\u663e\u793a\u8f93\u51fa\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Python+OpenCV\u6587\u6863\u626b\u63cf\u7ed3\u679c<\/h1>\n\n\n\n<p>\u8bf4\u5230\u8f93\u51fa\uff0c\u8bf7\u901a\u8fc7\u8fd0\u884c\u811a\u672c\u6765\u67e5\u770b\u6211\u4eec\u7684\u793a\u4f8b\u6587\u6863\uff1a<\/p>\n\n\n\n<p><strong>$ python scan.py &#8211;image images\/receipt.jpg<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"437\" src=\"http:\/\/ai.gitpp.com\/wp-content\/uploads\/2023\/11\/w4-1.jpg\" alt=\"\" class=\"wp-image-499\" srcset=\"http:\/\/ai.gitpp.com\/wp-content\/uploads\/2023\/11\/w4-1.jpg 600w, http:\/\/ai.gitpp.com\/wp-content\/uploads\/2023\/11\/w4-1-300x219.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/figure>\n\n\n\n<p>\u5de6\u8fb9\u662f\u4ece\u78c1\u76d8\u52a0\u8f7d\u7684\u539f\u59cb\u56fe\u50cf\u3002\u53f3\u8fb9\u662f\u626b\u63cf\u56fe\u50cf\uff01<\/p>\n\n\n\n<p>\u8bf7\u6ce8\u610f\u626b\u63cf\u56fe\u50cf\u7684\u89c6\u89d2\u5982\u4f55\u53d8\u5316\u2014\u2014\u6211\u4eec\u6709\u4e00\u4e2a\u81ea\u4e0a\u800c\u4e0b\u7684 90 \u5ea6\u56fe\u50cf\u89c6\u56fe\u3002<\/p>\n\n\n\n<p>\u5f97\u76ca\u4e8e\u6211\u4eec\u7684\u81ea\u9002\u5e94\u9608\u503c\u5904\u7406\uff0c\u6211\u4eec\u8fd8\u4e3a\u6587\u6863\u5e26\u6765\u4e86\u6f02\u4eae\u3001\u5e72\u51c0\u7684\u9ed1\u767d\u611f\u89c9\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u5df2\u7ecf\u6210\u529f\u6784\u5efa\u4e86\u6587\u6863\u626b\u63cf\u4eea\uff01<\/p>\n\n\n\n<p>\u6240\u6709\u8fd9\u4e9b\u90fd\u5728\u4e0d\u5230 5 \u5206\u949f\u7684\u65f6\u95f4\u5185\u5b8c\u6210\uff0c\u4ee3\u7801\u4e0d\u5230 75 \u884c\uff08\u65e0\u8bba\u5982\u4f55\uff0c\u5176\u4e2d\u5927\u90e8\u5206\u90fd\u662f\u6ce8\u91ca\uff09\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7528\u624b\u673a\u8bc6\u522b\u626b\u63cf\u6587\u5b57\uff0c\u76ee\u524d\u5df2\u7ecf\u975e\u5e38\u6210\u719f\uff0c\u672c\u6587\u4ecb\u7ecd \u5c06\u4ee5\u4e0a\u56fe\u7247\u6587\u5b57\u63d0\u53d6\u51fa\u6765 \u4f7f\u7528 OpenCV \u6784\u5efa\u6587\u6863\u626b\u63cf\u4eea\u53ea\u9700 [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"class_list":["post-492","post","type-post","status-publish","format-standard","hentry","category-github"],"blocksy_meta":"","_links":{"self":[{"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/posts\/492","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=492"}],"version-history":[{"count":3,"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/posts\/492\/revisions"}],"predecessor-version":[{"id":500,"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/posts\/492\/revisions\/500"}],"wp:attachment":[{"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=492"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}