{"id":1119648,"date":"2025-01-08T18:46:39","date_gmt":"2025-01-08T10:46:39","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1119648.html"},"modified":"2025-01-08T18:46:41","modified_gmt":"2025-01-08T10:46:41","slug":"python%e5%a6%82%e4%bd%95%e6%8a%8a%e5%9b%be%e5%83%8f%e7%9f%a9%e9%98%b5%e8%bd%ac%e6%8d%a2%e6%88%90%e5%88%97%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1119648.html","title":{"rendered":"python\u5982\u4f55\u628a\u56fe\u50cf\u77e9\u9635\u8f6c\u6362\u6210\u5217\u8868"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25082639\/133f0480-e5c6-4cff-add8-f19cf06291cf.webp\" alt=\"python\u5982\u4f55\u628a\u56fe\u50cf\u77e9\u9635\u8f6c\u6362\u6210\u5217\u8868\" \/><\/p>\n<p><p> <strong>Python\u5c06\u56fe\u50cf\u77e9\u9635\u8f6c\u6362\u6210\u5217\u8868\u7684\u65b9\u6cd5\u4e3b\u8981\u5305\u62ec\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a\u4f7f\u7528NumPy\u5e93\u8bfb\u53d6\u548c\u5904\u7406\u56fe\u50cf\u77e9\u9635\u3001\u5c06\u77e9\u9635\u8f6c\u6362\u4e3a\u5217\u8868\u3001\u786e\u4fdd\u6570\u636e\u7684\u4e00\u81f4\u6027\u3002<\/strong> \u5176\u4e2d\uff0c\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u901a\u8fc7NumPy\u548cPillow\u5e93\u8fdb\u884c\u56fe\u50cf\u7684\u8bfb\u53d6\u548c\u5904\u7406\u3002\u4e0b\u9762\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5b9e\u73b0\u8fd9\u4e00\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u8bfb\u53d6\u56fe\u50cf\u5e76\u8f6c\u6362\u6210\u77e9\u9635<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u8bfb\u53d6\u56fe\u50cf\u5e76\u5c06\u5176\u8f6c\u6362\u6210\u77e9\u9635\u7684\u5e38\u7528\u65b9\u6cd5\u662f\u4f7f\u7528Pillow\u5e93\u3002Pillow\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u8bfb\u53d6\u3001\u5904\u7406\u548c\u4fdd\u5b58\u56fe\u50cf\u3002\u8981\u4f7f\u7528Pillow\u5e93\uff0c\u6211\u4eec\u9700\u8981\u5148\u5b89\u88c5\u5b83\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pillow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Pillow\u5e93\u8bfb\u53d6\u56fe\u50cf\uff0c\u5e76\u5c06\u5176\u8f6c\u6362\u4e3aNumPy\u77e9\u9635\u3002NumPy\u662f\u4e00\u4e2a\u7528\u4e8e\u5904\u7406\u591a\u7ef4\u6570\u7ec4\u7684\u5f3a\u5927\u5e93\uff0c\u6211\u4eec\u4e5f\u9700\u8981\u5148\u5b89\u88c5\u5b83\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528Pillow\u548cNumPy\u5e93\u8bfb\u53d6\u56fe\u50cf\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u77e9\u9635\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u8bfb\u53d6\u56fe\u50cf<\/strong><\/h2>\n<p>image = Image.open(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4<\/strong><\/h2>\n<p>image_matrix = np.array(image)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528Pillow\u5e93\u7684<code>Image.open<\/code>\u65b9\u6cd5\u8bfb\u53d6\u56fe\u50cf\u6587\u4ef6\uff0c\u7136\u540e\u4f7f\u7528NumPy\u5e93\u7684<code>np.array<\/code>\u65b9\u6cd5\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4\uff08\u5373\u77e9\u9635\uff09\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u5c06\u77e9\u9635\u8f6c\u6362\u4e3a\u5217\u8868<\/p>\n<\/p>\n<p><p>\u4e00\u65e6\u6211\u4eec\u5f97\u5230\u4e86\u56fe\u50cf\u7684\u77e9\u9635\u8868\u793a\uff0c\u5c31\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u5c06\u5176\u8f6c\u6362\u4e3a\u5217\u8868\u3002NumPy\u6570\u7ec4\u63d0\u4f9b\u4e86\u4e00\u4e2a<code>tolist<\/code>\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u5d4c\u5957\u5217\u8868\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u5982\u4f55\u5c06\u56fe\u50cf\u77e9\u9635\u8f6c\u6362\u4e3a\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5c06\u77e9\u9635\u8f6c\u6362\u4e3a\u5217\u8868<\/p>\n<p>image_list = image_matrix.tolist()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528NumPy\u6570\u7ec4\u7684<code>tolist<\/code>\u65b9\u6cd5\u5c06\u56fe\u50cf\u77e9\u9635\u8f6c\u6362\u4e3a\u5d4c\u5957\u5217\u8868\u3002\u8fd9\u4e2a\u5d4c\u5957\u5217\u8868\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f\u4e00\u4e2a\u5b50\u5217\u8868\uff0c\u8868\u793a\u56fe\u50cf\u7684\u4e00\u4e2a\u50cf\u7d20\u884c\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u786e\u4fdd\u6570\u636e\u4e00\u81f4\u6027<\/p>\n<\/p>\n<p><p>\u5728\u5c06\u56fe\u50cf\u77e9\u9635\u8f6c\u6362\u4e3a\u5217\u8868\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u786e\u4fdd\u6570\u636e\u7684\u4e00\u81f4\u6027\u3002\u4f8b\u5982\uff0c\u56fe\u50cf\u7684\u6bcf\u4e2a\u50cf\u7d20\u901a\u5e38\u7531\u591a\u4e2a\u901a\u9053\uff08\u4f8b\u5982\u7ea2\u8272\u3001\u7eff\u8272\u548c\u84dd\u8272\uff09\u8868\u793a\uff0c\u8fd9\u4e9b\u901a\u9053\u7684\u6570\u636e\u9700\u8981\u4fdd\u6301\u4e00\u81f4\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u5982\u4f55\u786e\u4fdd\u6570\u636e\u7684\u4e00\u81f4\u6027\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u786e\u4fdd\u56fe\u50cf\u662fRGB\u683c\u5f0f<\/p>\n<p>if image.mode != &#39;RGB&#39;:<\/p>\n<p>    image = image.convert(&#39;RGB&#39;)<\/p>\n<h2><strong>\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4<\/strong><\/h2>\n<p>image_matrix = np.array(image)<\/p>\n<h2><strong>\u5c06\u77e9\u9635\u8f6c\u6362\u4e3a\u5217\u8868<\/strong><\/h2>\n<p>image_list = image_matrix.tolist()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u68c0\u67e5\u56fe\u50cf\u7684\u6a21\u5f0f\u662f\u5426\u4e3aRGB\u6a21\u5f0f\u3002\u5982\u679c\u4e0d\u662f\uff0c\u6211\u4eec\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3aRGB\u6a21\u5f0f\u3002\u7136\u540e\uff0c\u6211\u4eec\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4\uff0c\u5e76\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u5d4c\u5957\u5217\u8868\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u5904\u7406\u4e0d\u540c\u683c\u5f0f\u7684\u56fe\u50cf<\/p>\n<\/p>\n<p><p>\u4e0d\u540c\u683c\u5f0f\u7684\u56fe\u50cf\uff08\u4f8b\u5982\u7070\u5ea6\u56fe\u50cf\u3001RGBA\u56fe\u50cf\u7b49\uff09\u5728\u8f6c\u6362\u4e3a\u77e9\u9635\u548c\u5217\u8868\u65f6\u53ef\u80fd\u9700\u8981\u4e0d\u540c\u7684\u5904\u7406\u65b9\u5f0f\u3002\u4e0b\u9762\u662f\u4e00\u4e9b\u5e38\u89c1\u683c\u5f0f\u7684\u5904\u7406\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u7070\u5ea6\u56fe\u50cf<\/strong><\/li>\n<\/ol>\n<p><p>\u7070\u5ea6\u56fe\u50cf\u53ea\u6709\u4e00\u4e2a\u901a\u9053\uff0c\u56e0\u6b64\u5728\u5c06\u5176\u8f6c\u6362\u4e3a\u77e9\u9635\u548c\u5217\u8868\u65f6\uff0c\u6211\u4eec\u53ea\u9700\u8981\u5904\u7406\u4e00\u4e2a\u901a\u9053\u7684\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u5982\u4f55\u5904\u7406\u7070\u5ea6\u56fe\u50cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u786e\u4fdd\u56fe\u50cf\u662f\u7070\u5ea6\u683c\u5f0f<\/p>\n<p>if image.mode != &#39;L&#39;:<\/p>\n<p>    image = image.convert(&#39;L&#39;)<\/p>\n<h2><strong>\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4<\/strong><\/h2>\n<p>image_matrix = np.array(image)<\/p>\n<h2><strong>\u5c06\u77e9\u9635\u8f6c\u6362\u4e3a\u5217\u8868<\/strong><\/h2>\n<p>image_list = image_matrix.tolist()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u786e\u4fdd\u56fe\u50cf\u662f\u7070\u5ea6\u683c\u5f0f\uff08\u6a21\u5f0f\u4e3a&#39;L&#39;\uff09\u3002\u7136\u540e\uff0c\u6211\u4eec\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4\uff0c\u5e76\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u5d4c\u5957\u5217\u8868\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>RGBA\u56fe\u50cf<\/strong><\/li>\n<\/ol>\n<p><p>RGBA\u56fe\u50cf\u5305\u542b\u7ea2\u8272\u3001\u7eff\u8272\u3001\u84dd\u8272\u548c\u900f\u660e\u5ea6\u56db\u4e2a\u901a\u9053\u3002\u5728\u5c06\u5176\u8f6c\u6362\u4e3a\u77e9\u9635\u548c\u5217\u8868\u65f6\uff0c\u6211\u4eec\u9700\u8981\u5904\u7406\u56db\u4e2a\u901a\u9053\u7684\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u5982\u4f55\u5904\u7406RGBA\u56fe\u50cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u786e\u4fdd\u56fe\u50cf\u662fRGBA\u683c\u5f0f<\/p>\n<p>if image.mode != &#39;RGBA&#39;:<\/p>\n<p>    image = image.convert(&#39;RGBA&#39;)<\/p>\n<h2><strong>\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4<\/strong><\/h2>\n<p>image_matrix = np.array(image)<\/p>\n<h2><strong>\u5c06\u77e9\u9635\u8f6c\u6362\u4e3a\u5217\u8868<\/strong><\/h2>\n<p>image_list = image_matrix.tolist()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u786e\u4fdd\u56fe\u50cf\u662fRGBA\u683c\u5f0f\uff08\u6a21\u5f0f\u4e3a&#39;RGBA&#39;\uff09\u3002\u7136\u540e\uff0c\u6211\u4eec\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4\uff0c\u5e76\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u5d4c\u5957\u5217\u8868\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u5904\u7406\u5927\u56fe\u50cf<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u5927\u56fe\u50cf\uff0c\u8f6c\u6362\u4e3a\u77e9\u9635\u548c\u5217\u8868\u53ef\u80fd\u4f1a\u5360\u7528\u5927\u91cf\u5185\u5b58\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5bf9\u56fe\u50cf\u8fdb\u884c\u5206\u5757\u5904\u7406\u6765\u51cf\u5c11\u5185\u5b58\u5360\u7528\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u5982\u4f55\u5bf9\u5927\u56fe\u50cf\u8fdb\u884c\u5206\u5757\u5904\u7406\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def process_image_in_chunks(image, chunk_size=100):<\/p>\n<p>    # \u83b7\u53d6\u56fe\u50cf\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6<\/p>\n<p>    width, height = image.size<\/p>\n<p>    # \u521d\u59cb\u5316\u7ed3\u679c\u5217\u8868<\/p>\n<p>    result = []<\/p>\n<p>    # \u904d\u5386\u56fe\u50cf\u7684\u6bcf\u4e2a\u5757<\/p>\n<p>    for y in range(0, height, chunk_size):<\/p>\n<p>        for x in range(0, width, chunk_size):<\/p>\n<p>            # \u63d0\u53d6\u5f53\u524d\u5757<\/p>\n<p>            box = (x, y, x + chunk_size, y + chunk_size)<\/p>\n<p>            chunk = image.crop(box)<\/p>\n<p>            # \u5c06\u5757\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4<\/p>\n<p>            chunk_matrix = np.array(chunk)<\/p>\n<p>            # \u5c06\u5757\u77e9\u9635\u8f6c\u6362\u4e3a\u5217\u8868\uff0c\u5e76\u6dfb\u52a0\u5230\u7ed3\u679c\u5217\u8868\u4e2d<\/p>\n<p>            result.append(chunk_matrix.tolist())<\/p>\n<p>    return result<\/p>\n<h2><strong>\u8bfb\u53d6\u56fe\u50cf<\/strong><\/h2>\n<p>image = Image.open(&#39;example.jpg&#39;)<\/p>\n<h2><strong>\u786e\u4fdd\u56fe\u50cf\u662fRGB\u683c\u5f0f<\/strong><\/h2>\n<p>if image.mode != &#39;RGB&#39;:<\/p>\n<p>    image = image.convert(&#39;RGB&#39;)<\/p>\n<h2><strong>\u5bf9\u56fe\u50cf\u8fdb\u884c\u5206\u5757\u5904\u7406<\/strong><\/h2>\n<p>image_list_chunks = process_image_in_chunks(image)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a<code>process_image_in_chunks<\/code>\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u56fe\u50cf\u548c\u4e00\u4e2a\u5757\u5927\u5c0f\u53c2\u6570\u3002\u6211\u4eec\u904d\u5386\u56fe\u50cf\u7684\u6bcf\u4e2a\u5757\uff0c\u5c06\u6bcf\u4e2a\u5757\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4\uff0c\u7136\u540e\u5c06\u5176\u8f6c\u6362\u4e3a\u5217\u8868\uff0c\u5e76\u5c06\u5217\u8868\u6dfb\u52a0\u5230\u7ed3\u679c\u5217\u8868\u4e2d\u3002\u8fd9\u6837\uff0c\u6211\u4eec\u53ef\u4ee5\u9010\u5757\u5904\u7406\u5927\u56fe\u50cf\uff0c\u51cf\u5c11\u5185\u5b58\u5360\u7528\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Python\u5c06\u56fe\u50cf\u77e9\u9635\u8f6c\u6362\u4e3a\u5217\u8868\u7684\u65b9\u6cd5\u3002\u6211\u4eec\u9996\u5148\u4f7f\u7528Pillow\u5e93\u8bfb\u53d6\u56fe\u50cf\uff0c\u5e76\u5c06\u5176\u8f6c\u6362\u4e3aNumPy\u77e9\u9635\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528NumPy\u6570\u7ec4\u7684<code>tolist<\/code>\u65b9\u6cd5\u5c06\u77e9\u9635\u8f6c\u6362\u4e3a\u5d4c\u5957\u5217\u8868\u3002\u6211\u4eec\u8fd8\u8ba8\u8bba\u4e86\u5982\u4f55\u786e\u4fdd\u6570\u636e\u7684\u4e00\u81f4\u6027\uff0c\u4ee5\u53ca\u5982\u4f55\u5904\u7406\u4e0d\u540c\u683c\u5f0f\u7684\u56fe\u50cf\u548c\u5927\u56fe\u50cf\u3002\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06\u56fe\u50cf\u77e9\u9635\u8f6c\u6362\u4e3a\u5217\u8868\uff0c\u5e76\u5728\u540e\u7eed\u7684\u56fe\u50cf\u5904\u7406\u548c\u5206\u6790\u4e2d\u4f7f\u7528\u8fd9\u4e9b\u5217\u8868\u6570\u636e\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5c06Python\u4e2d\u7684\u56fe\u50cf\u77e9\u9635\u8f6c\u6362\u4e3a\u5217\u8868\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u56fe\u50cf\u901a\u5e38\u4ee5NumPy\u6570\u7ec4\u7684\u5f62\u5f0f\u5b58\u50a8\u3002\u5f53\u4f60\u60f3\u5c06\u4e00\u4e2a\u56fe\u50cf\u77e9\u9635\u8f6c\u6362\u4e3a\u5217\u8868\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u7684<code>tolist()<\/code>\u65b9\u6cd5\u3002\u8fd9\u79cd\u65b9\u6cd5\u5c06\u6574\u4e2a\u77e9\u9635\u8f6c\u6362\u4e3a\u5d4c\u5957\u5217\u8868\uff0c\u4fbf\u4e8e\u8fdb\u884c\u8fdb\u4e00\u6b65\u7684\u6570\u636e\u5904\u7406\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-python\">import numpy as np\nfrom PIL import Image\n\n# \u6253\u5f00\u56fe\u50cf\u5e76\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4\nimage = Image.open(&#39;example.jpg&#39;)\nimage_matrix = np.array(image)\n\n# \u5c06NumPy\u6570\u7ec4\u8f6c\u6362\u4e3a\u5217\u8868\nimage_list = image_matrix.tolist()\n<\/code><\/pre>\n<p><strong>\u56fe\u50cf\u77e9\u9635\u8f6c\u6362\u4e3a\u5217\u8868\u7684\u5e94\u7528\u573a\u666f\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u5c06\u56fe\u50cf\u77e9\u9635\u8f6c\u6362\u4e3a\u5217\u8868\u7684\u5e94\u7528\u573a\u666f\u5305\u62ec\u4f46\u4e0d\u9650\u4e8e\u56fe\u50cf\u5904\u7406\u3001<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u6a21\u578b\u8f93\u5165\u3001\u6570\u636e\u53ef\u89c6\u5316\u7b49\u3002\u5728\u673a\u5668\u5b66\u4e60\u9886\u57df\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u56fe\u50cf\u8bc6\u522b\u4efb\u52a1\u65f6\uff0c\u901a\u5e38\u9700\u8981\u5c06\u56fe\u50cf\u6570\u636e\u8f6c\u6362\u4e3a\u5217\u8868\u683c\u5f0f\uff0c\u4ee5\u4fbf\u4e8e\u6784\u5efa\u7279\u5f81\u5411\u91cf\u548c\u8fdb\u884c\u8bad\u7ec3\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u5217\u8868\u7ed3\u6784\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u56fe\u50cf\u6570\u636e\u7684\u4fee\u6539\u548c\u5206\u6790\u3002<\/p>\n<p><strong>\u4f7f\u7528Python\u5e93\u8fdb\u884c\u56fe\u50cf\u77e9\u9635\u8f6c\u6362\u65f6\uff0c\u6709\u54ea\u4e9b\u63a8\u8350\u7684\u5e93\uff1f<\/strong><br \/>\u5904\u7406\u56fe\u50cf\u77e9\u9635\u8f6c\u6362\u65f6\uff0c\u63a8\u8350\u4f7f\u7528\u4ee5\u4e0b\u51e0\u4e2aPython\u5e93\uff1a  <\/p>\n<ol>\n<li><strong>NumPy<\/strong>\uff1a\u5f3a\u5927\u7684\u6570\u503c\u8ba1\u7b97\u5e93\uff0c\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u6570\u7ec4\u5904\u7406\u529f\u80fd\uff0c\u975e\u5e38\u9002\u5408\u8fdb\u884c\u77e9\u9635\u8f6c\u6362\u548c\u64cd\u4f5c\u3002  <\/li>\n<li><strong>Pillow<\/strong>\uff08PIL\uff09\uff1a\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u80fd\u591f\u65b9\u4fbf\u5730\u6253\u5f00\u3001\u64cd\u4f5c\u548c\u4fdd\u5b58\u56fe\u50cf\u3002  <\/li>\n<li><strong>OpenCV<\/strong>\uff1a\u7528\u4e8e\u8ba1\u7b97\u673a\u89c6\u89c9\u7684\u5e93\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u5904\u7406\u529f\u80fd\uff0c\u5305\u62ec\u8bfb\u53d6\u548c\u8f6c\u6362\u56fe\u50cf\u6570\u636e\u3002<br \/>\u8fd9\u4e9b\u5e93\u7684\u7ed3\u5408\u4f7f\u7528\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u5b9e\u73b0\u56fe\u50cf\u77e9\u9635\u4e0e\u5217\u8868\u4e4b\u95f4\u7684\u5feb\u901f\u8f6c\u6362\u548c\u5904\u7406\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"Python\u5c06\u56fe\u50cf\u77e9\u9635\u8f6c\u6362\u6210\u5217\u8868\u7684\u65b9\u6cd5\u4e3b\u8981\u5305\u62ec\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a\u4f7f\u7528NumPy\u5e93\u8bfb\u53d6\u548c\u5904\u7406\u56fe\u50cf\u77e9\u9635\u3001\u5c06\u77e9\u9635\u8f6c\u6362\u4e3a\u5217 [&hellip;]","protected":false},"author":3,"featured_media":1119652,"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\/1119648"}],"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=1119648"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1119648\/revisions"}],"predecessor-version":[{"id":1119658,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1119648\/revisions\/1119658"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1119652"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1119648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1119648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1119648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}