{"id":1124229,"date":"2025-01-08T19:39:25","date_gmt":"2025-01-08T11:39:25","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1124229.html"},"modified":"2025-01-08T19:39:29","modified_gmt":"2025-01-08T11:39:29","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8python%e6%9b%bf%e6%8d%a2%e5%9b%be%e7%89%87%e4%b8%80%e4%ba%9b%e9%a2%9c%e8%89%b2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1124229.html","title":{"rendered":"\u5982\u4f55\u4f7f\u7528python\u66ff\u6362\u56fe\u7247\u4e00\u4e9b\u989c\u8272"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25085353\/383a8b09-4338-4704-ad5d-ee773581411c.webp\" alt=\"\u5982\u4f55\u4f7f\u7528python\u66ff\u6362\u56fe\u7247\u4e00\u4e9b\u989c\u8272\" \/><\/p>\n<p><p> <strong>\u5982\u4f55\u4f7f\u7528Python\u66ff\u6362\u56fe\u7247\u4e00\u4e9b\u989c\u8272<\/strong><\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528Python\u66ff\u6362\u56fe\u7247\u4e2d\u7684\u989c\u8272\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u4f8b\u5982\u4f7f\u7528Pillow\u5e93\u3001OpenCV\u5e93\u7b49\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u8fdb\u884c\u989c\u8272\u66ff\u6362\uff0c\u5305\u62ec\u5982\u4f55\u5b89\u88c5\u5e93\u3001\u8bfb\u53d6\u56fe\u7247\u3001\u6267\u884c\u989c\u8272\u66ff\u6362\u4ee5\u53ca\u4fdd\u5b58\u4fee\u6539\u540e\u7684\u56fe\u7247\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5Python\u56fe\u50cf\u5904\u7406\u5e93<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5\u7528\u4e8e\u56fe\u50cf\u5904\u7406\u7684\u5e93\u3002\u672c\u6587\u5c06\u4f7f\u7528Pillow\u548cOpenCV\u5e93\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\u5b83\u4eec\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install pillow<\/p>\n<p>pip install opencv-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528Pillow\u66ff\u6362\u989c\u8272<\/p>\n<\/p>\n<p><p>Pillow\u662f\u4e00\u4e2a\u53cb\u597d\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u9002\u5408\u521d\u5b66\u8005\u4f7f\u7528\u3002\u5b83\u53ef\u4ee5\u8f7b\u677e\u5730\u8bfb\u53d6\u3001\u4fee\u6539\u548c\u4fdd\u5b58\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><h3>1.\u8bfb\u53d6\u548c\u663e\u793a\u56fe\u50cf<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u8bfb\u53d6\u56fe\u50cf\u5e76\u663e\u793a\u5b83\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u8bfb\u53d6\u56fe\u50cf<\/strong><\/h2>\n<p>image = Image.open(&#39;path_to_image.jpg&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2.\u66ff\u6362\u989c\u8272<\/h3>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u8981\u5c06\u56fe\u50cf\u4e2d\u7684\u4e00\u79cd\u7279\u5b9a\u989c\u8272\uff08\u4f8b\u5982\u7ea2\u8272\uff09\u66ff\u6362\u4e3a\u53e6\u4e00\u79cd\u989c\u8272\uff08\u4f8b\u5982\u84dd\u8272\uff09\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def replace_color(image, old_color, new_color):<\/p>\n<p>    # \u83b7\u53d6\u56fe\u50cf\u7684\u50cf\u7d20\u6570\u636e<\/p>\n<p>    data = image.load()<\/p>\n<p>    # \u904d\u5386\u6bcf\u4e00\u4e2a\u50cf\u7d20<\/p>\n<p>    for y in range(image.size[1]):<\/p>\n<p>        for x in range(image.size[0]):<\/p>\n<p>            # \u5982\u679c\u50cf\u7d20\u989c\u8272\u4e0e\u65e7\u989c\u8272\u5339\u914d\uff0c\u5219\u66ff\u6362\u4e3a\u65b0\u989c\u8272<\/p>\n<p>            if data[x, y] == old_color:<\/p>\n<p>                data[x, y] = new_color<\/p>\n<h2><strong>\u5b9a\u4e49\u65e7\u989c\u8272\u548c\u65b0\u989c\u8272<\/strong><\/h2>\n<p>old_color = (255, 0, 0)  # \u7ea2\u8272<\/p>\n<p>new_color = (0, 0, 255)  # \u84dd\u8272<\/p>\n<h2><strong>\u6267\u884c\u989c\u8272\u66ff\u6362<\/strong><\/h2>\n<p>replace_color(image, old_color, new_color)<\/p>\n<h2><strong>\u663e\u793a\u4fee\u6539\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>image.show()<\/p>\n<h2><strong>\u4fdd\u5b58\u4fee\u6539\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>image.save(&#39;path_to_modified_image.jpg&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3.\u6279\u91cf\u66ff\u6362\u989c\u8272<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u66ff\u6362\u56fe\u50cf\u4e2d\u7684\u591a\u79cd\u989c\u8272\uff0c\u53ef\u4ee5\u5c06\u591a\u4e2a\u65e7\u989c\u8272\u548c\u65b0\u989c\u8272\u653e\u5165\u5217\u8868\u4e2d\u8fdb\u884c\u6279\u91cf\u66ff\u6362\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def replace_colors(image, color_map):<\/p>\n<p>    data = image.load()<\/p>\n<p>    for y in range(image.size[1]):<\/p>\n<p>        for x in range(image.size[0]):<\/p>\n<p>            if data[x, y] in color_map:<\/p>\n<p>                data[x, y] = color_map[data[x, y]]<\/p>\n<p>color_map = {<\/p>\n<p>    (255, 0, 0): (0, 0, 255),  # \u7ea2\u8272 -&gt; \u84dd\u8272<\/p>\n<p>    (0, 255, 0): (255, 255, 0)  # \u7eff\u8272 -&gt; \u9ec4\u8272<\/p>\n<p>}<\/p>\n<p>replace_colors(image, color_map)<\/p>\n<p>image.show()<\/p>\n<p>image.save(&#39;path_to_modified_image_batch.jpg&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528OpenCV\u66ff\u6362\u989c\u8272<\/p>\n<\/p>\n<p><p>OpenCV\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\uff0c\u9002\u5408\u5904\u7406\u590d\u6742\u7684\u56fe\u50cf\u5904\u7406\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><h3>1.\u8bfb\u53d6\u548c\u663e\u793a\u56fe\u50cf<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<h2><strong>\u8bfb\u53d6\u56fe\u50cf<\/strong><\/h2>\n<p>image = cv2.imread(&#39;path_to_image.jpg&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imshow(&#39;Original Image&#39;, image)<\/p>\n<p>cv2.w<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>tKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2.\u66ff\u6362\u989c\u8272<\/h3>\n<\/p>\n<p><p>\u5047\u8bbe\u6211\u4eec\u8981\u5c06\u56fe\u50cf\u4e2d\u7684\u4e00\u79cd\u7279\u5b9a\u989c\u8272\u66ff\u6362\u4e3a\u53e6\u4e00\u79cd\u989c\u8272\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def replace_color(image, old_color, new_color):<\/p>\n<p>    # \u521b\u5efa\u4e00\u4e2a\u63a9\u7801\uff0c\u627e\u51fa\u6240\u6709\u65e7\u989c\u8272\u7684\u4f4d\u7f6e<\/p>\n<p>    mask = cv2.inRange(image, old_color, old_color)<\/p>\n<p>    # \u5c06\u65b0\u989c\u8272\u5e94\u7528\u5230\u63a9\u7801\u4f4d\u7f6e<\/p>\n<p>    image[mask != 0] = new_color<\/p>\n<h2><strong>\u5b9a\u4e49\u65e7\u989c\u8272\u548c\u65b0\u989c\u8272\uff08BGR\u683c\u5f0f\uff09<\/strong><\/h2>\n<p>old_color = [0, 0, 255]  # \u7ea2\u8272<\/p>\n<p>new_color = [255, 0, 0]  # \u84dd\u8272<\/p>\n<h2><strong>\u6267\u884c\u989c\u8272\u66ff\u6362<\/strong><\/h2>\n<p>replace_color(image, old_color, new_color)<\/p>\n<h2><strong>\u663e\u793a\u4fee\u6539\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imshow(&#39;Modified Image&#39;, image)<\/p>\n<p>cv2.waitKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<h2><strong>\u4fdd\u5b58\u4fee\u6539\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imwrite(&#39;path_to_modified_image.jpg&#39;, image)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3.\u4f7f\u7528\u989c\u8272\u8303\u56f4\u66ff\u6362\u989c\u8272<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u66ff\u6362\u4e00\u4e2a\u989c\u8272\u8303\u56f4\u5185\u7684\u989c\u8272\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def replace_color_range(image, lower_bound, upper_bound, new_color):<\/p>\n<p>    # \u521b\u5efa\u4e00\u4e2a\u63a9\u7801\uff0c\u627e\u51fa\u6240\u6709\u5728\u989c\u8272\u8303\u56f4\u5185\u7684\u4f4d\u7f6e<\/p>\n<p>    mask = cv2.inRange(image, lower_bound, upper_bound)<\/p>\n<p>    # \u5c06\u65b0\u989c\u8272\u5e94\u7528\u5230\u63a9\u7801\u4f4d\u7f6e<\/p>\n<p>    image[mask != 0] = new_color<\/p>\n<h2><strong>\u5b9a\u4e49\u989c\u8272\u8303\u56f4\u548c\u65b0\u989c\u8272\uff08BGR\u683c\u5f0f\uff09<\/strong><\/h2>\n<p>lower_bound = [0, 0, 100]  # \u7ea2\u8272\u4e0b\u754c<\/p>\n<p>upper_bound = [0, 0, 255]  # \u7ea2\u8272\u4e0a\u754c<\/p>\n<p>new_color = [255, 0, 0]  # \u84dd\u8272<\/p>\n<h2><strong>\u6267\u884c\u989c\u8272\u66ff\u6362<\/strong><\/h2>\n<p>replace_color_range(image, lower_bound, upper_bound, new_color)<\/p>\n<h2><strong>\u663e\u793a\u4fee\u6539\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imshow(&#39;Modified Image&#39;, image)<\/p>\n<p>cv2.waitKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<h2><strong>\u4fdd\u5b58\u4fee\u6539\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imwrite(&#39;path_to_modified_image_range.jpg&#39;, image)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u4f18\u5316\u548c\u9ad8\u7ea7\u5e94\u7528<\/p>\n<\/p>\n<p><h3>1.\u6027\u80fd\u4f18\u5316<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5927\u56fe\u50cf\u6216\u9700\u8981\u9ad8\u6548\u5904\u7406\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u8fdb\u884c\u4f18\u5316\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u591a\u7ebf\u7a0b\u5904\u7406\uff1a<\/strong> \u5c06\u56fe\u50cf\u5206\u5272\u6210\u591a\u4e2a\u90e8\u5206\u5e76\u4f7f\u7528\u591a\u7ebf\u7a0b\u8fdb\u884c\u5904\u7406\u3002<\/li>\n<li><strong>GPU\u52a0\u901f\uff1a<\/strong> \u4f7f\u7528OpenCV\u7684GPU\u6a21\u5757\u6216\u5176\u4ed6GPU\u52a0\u901f\u5e93\u3002<\/li>\n<\/ul>\n<p><h3>2.\u9ad8\u7ea7\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u7b80\u5355\u7684\u989c\u8272\u66ff\u6362\uff0c\u8fd8\u53ef\u4ee5\u8fdb\u884c\u590d\u6742\u7684\u56fe\u50cf\u5904\u7406\u4efb\u52a1\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>\u989c\u8272\u7a7a\u95f4\u8f6c\u6362\uff1a<\/strong> \u5c06\u56fe\u50cf\u4ece\u4e00\u79cd\u989c\u8272\u7a7a\u95f4\u8f6c\u6362\u5230\u53e6\u4e00\u79cd\u989c\u8272\u7a7a\u95f4\uff08\u4f8b\u5982RGB\u5230HSV\uff09\u3002<\/li>\n<li><strong>\u56fe\u50cf\u5206\u5272\uff1a<\/strong> \u4f7f\u7528\u5206\u5272\u7b97\u6cd5\u5c06\u56fe\u50cf\u5206\u5272\u6210\u4e0d\u540c\u7684\u90e8\u5206\uff0c\u7136\u540e\u5bf9\u6bcf\u4e2a\u90e8\u5206\u8fdb\u884c\u5904\u7406\u3002<\/li>\n<li><strong>\u56fe\u50cf\u589e\u5f3a\uff1a<\/strong> \u4f7f\u7528\u6ee4\u6ce2\u5668\u548c\u5377\u79ef\u64cd\u4f5c\u589e\u5f3a\u56fe\u50cf\u8d28\u91cf\u3002<\/li>\n<\/ul>\n<p><h3>3.\u793a\u4f8b\uff1a\u56fe\u50cf\u5206\u5272\u548c\u989c\u8272\u66ff\u6362<\/h3>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528K-means\u805a\u7c7b\u8fdb\u884c\u56fe\u50cf\u5206\u5272\u5e76\u66ff\u6362\u989c\u8272\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u8bfb\u53d6\u56fe\u50cf\u5e76\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570<\/strong><\/h2>\n<p>image = cv2.imread(&#39;path_to_image.jpg&#39;)<\/p>\n<p>data = image.reshape((-1, 3))<\/p>\n<p>data = np.float32(data)<\/p>\n<h2><strong>\u5b9a\u4e49K-means\u53c2\u6570<\/strong><\/h2>\n<p>criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.2)<\/p>\n<p>k = 3<\/p>\n<h2><strong>\u6267\u884cK-means\u805a\u7c7b<\/strong><\/h2>\n<p>_, labels, centers = cv2.kmeans(data, k, None, criteria, 10, cv2.KMEANS_RANDOM_CENTERS)<\/p>\n<h2><strong>\u5c06\u4e2d\u5fc3\u8f6c\u6362\u4e3auint8\u7c7b\u578b\u5e76\u66ff\u6362\u989c\u8272<\/strong><\/h2>\n<p>centers = np.uint8(centers)<\/p>\n<p>result = centers[labels.flatten()]<\/p>\n<p>result_image = result.reshape(image.shape)<\/p>\n<h2><strong>\u663e\u793a\u4fee\u6539\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imshow(&#39;Segmented Image&#39;, result_image)<\/p>\n<p>cv2.waitKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<h2><strong>\u4fdd\u5b58\u4fee\u6539\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imwrite(&#39;path_to_segmented_image.jpg&#39;, result_image)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u60a8\u5e94\u8be5\u80fd\u591f\u4f7f\u7528Python\u66ff\u6362\u56fe\u7247\u4e2d\u7684\u989c\u8272\uff0c\u65e0\u8bba\u662f\u7b80\u5355\u7684\u989c\u8272\u66ff\u6362\u8fd8\u662f\u590d\u6742\u7684\u56fe\u50cf\u5904\u7406\u4efb\u52a1\u3002\u5e0c\u671b\u8fd9\u4e9b\u65b9\u6cd5\u548c\u6280\u5de7\u80fd\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u8fdb\u884c\u56fe\u50cf\u5904\u7406\u5de5\u4f5c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u7528Python\u66ff\u6362\u56fe\u7247\u4e2d\u7684\u7279\u5b9a\u989c\u8272\uff1f<\/strong><br \/>\u4f7f\u7528Python\u66ff\u6362\u56fe\u7247\u4e2d\u7684\u7279\u5b9a\u989c\u8272\u53ef\u4ee5\u901a\u8fc7\u591a\u4e2a\u5e93\u5b9e\u73b0\uff0c\u5982Pillow\u548cOpenCV\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u52a0\u8f7d\u56fe\u7247\uff0c\u7136\u540e\u904d\u5386\u6bcf\u4e2a\u50cf\u7d20\uff0c\u6839\u636e\u6761\u4ef6\u66ff\u6362\u989c\u8272\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528Pillow\u5e93\u7684<code>Image<\/code>\u6a21\u5757\u6765\u6253\u5f00\u56fe\u7247\uff0c\u4f7f\u7528<code>getdata()<\/code>\u65b9\u6cd5\u83b7\u53d6\u50cf\u7d20\u6570\u636e\uff0c\u627e\u5230\u9700\u8981\u66ff\u6362\u7684\u989c\u8272\u540e\u8fdb\u884c\u4fee\u6539\uff0c\u6700\u540e\u4fdd\u5b58\u56fe\u7247\u3002\u5177\u4f53\u4ee3\u7801\u793a\u4f8b\u53ef\u4ee5\u5728\u76f8\u5173\u6587\u6863\u4e2d\u627e\u5230\u3002<\/p>\n<p><strong>\u4f7f\u7528Python\u66ff\u6362\u989c\u8272\u65f6\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u4e8b\u9879\uff1f<\/strong><br \/>\u5728\u66ff\u6362\u56fe\u7247\u989c\u8272\u65f6\uff0c\u9700\u6ce8\u610f\u989c\u8272\u7684\u5339\u914d\u3002\u4e0d\u540c\u7684\u989c\u8272\u8868\u793a\u65b9\u5f0f\uff08\u5982RGB\u3001HEX\u7b49\uff09\u53ef\u80fd\u5f71\u54cd\u66ff\u6362\u6548\u679c\u3002\u6b64\u5916\uff0c\u786e\u4fdd\u66ff\u6362\u7684\u989c\u8272\u8303\u56f4\u8db3\u591f\u7cbe\u786e\uff0c\u4ee5\u514d\u5f71\u54cd\u5230\u4e0d\u60f3\u66f4\u6539\u7684\u90e8\u5206\u3002\u5bf9\u4e8e\u590d\u6742\u7684\u56fe\u7247\uff0c\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u989c\u8272\u8ddd\u79bb\u7b97\u6cd5\u6765\u5224\u65ad\u54ea\u4e9b\u989c\u8272\u9700\u8981\u88ab\u66ff\u6362\u3002<\/p>\n<p><strong>\u6709\u6ca1\u6709\u7b80\u5355\u7684\u65b9\u6cd5\u53ef\u4ee5\u6279\u91cf\u66ff\u6362\u591a\u4e2a\u56fe\u7247\u4e2d\u7684\u989c\u8272\uff1f<\/strong><br \/>\u662f\u7684\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528Python\u4e2d\u7684\u5faa\u73af\u7ed3\u6784\u6765\u6279\u91cf\u5904\u7406\u591a\u4e2a\u56fe\u7247\u3002\u9996\u5148\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>os<\/code>\u5e93\u83b7\u53d6\u6307\u5b9a\u6587\u4ef6\u5939\u4e2d\u7684\u6240\u6709\u56fe\u7247\u6587\u4ef6\uff0c\u7136\u540e\u5bf9\u6bcf\u5f20\u56fe\u7247\u5e94\u7528\u76f8\u540c\u7684\u989c\u8272\u66ff\u6362\u903b\u8f91\u3002\u7ed3\u5408Pillow\u6216OpenCV\u5e93\uff0c\u53ef\u4ee5\u5b9e\u73b0\u9ad8\u6548\u7684\u6279\u91cf\u5904\u7406\uff0c\u8282\u7701\u624b\u52a8\u64cd\u4f5c\u7684\u65f6\u95f4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5982\u4f55\u4f7f\u7528Python\u66ff\u6362\u56fe\u7247\u4e00\u4e9b\u989c\u8272 \u4f7f\u7528Python\u66ff\u6362\u56fe\u7247\u4e2d\u7684\u989c\u8272\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u4f8b\u5982\u4f7f\u7528Pillo [&hellip;]","protected":false},"author":3,"featured_media":1124237,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1124229"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1124229"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1124229\/revisions"}],"predecessor-version":[{"id":1124238,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1124229\/revisions\/1124238"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1124237"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1124229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1124229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1124229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}