{"id":1099122,"date":"2025-01-08T15:27:29","date_gmt":"2025-01-08T07:27:29","guid":{"rendered":""},"modified":"2025-01-08T15:27:32","modified_gmt":"2025-01-08T07:27:32","slug":"python%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9%e5%9b%be%e5%83%8f%e7%9a%84%e4%bd%8d%e6%b7%b1-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1099122.html","title":{"rendered":"python\u5982\u4f55\u4fee\u6539\u56fe\u50cf\u7684\u4f4d\u6df1"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25063002\/bf724da3-6fd8-40c5-b17c-d81537b47e2e.webp\" alt=\"python\u5982\u4f55\u4fee\u6539\u56fe\u50cf\u7684\u4f4d\u6df1\" \/><\/p>\n<p><p> <strong>\u8981\u4fee\u6539\u56fe\u50cf\u7684\u4f4d\u6df1\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u5982Python\u4e2d\u7684Pillow\u5e93\u3001OpenCV\u5e93\u7b49\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528Pillow\u5e93\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8f6c\u6362\u56fe\u50cf\u6a21\u5f0f\u6765\u4fee\u6539\u56fe\u50cf\u7684\u4f4d\u6df1\u3002\u4f8b\u5982\uff0c\u5c068\u4f4d\u56fe\u50cf\u8f6c\u6362\u4e3a24\u4f4d\u56fe\u50cf\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\u3002\u9996\u5148\uff0c\u5b89\u88c5Pillow\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pillow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6765\u4fee\u6539\u56fe\u50cf\u7684\u4f4d\u6df1\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u6253\u5f00\u56fe\u50cf<\/strong><\/h2>\n<p>img = Image.open(&#39;path_to_image&#39;)<\/p>\n<h2><strong>\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3aRGB\u6a21\u5f0f\uff0824\u4f4d\uff09<\/strong><\/h2>\n<p>img = img.convert(&#39;RGB&#39;)<\/p>\n<h2><strong>\u4fdd\u5b58\u4fee\u6539\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>img.save(&#39;path_to_new_image&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u56fe\u50cf\u7684\u4f4d\u6df1\u4ece8\u4f4d\u8f6c\u6362\u4e3a24\u4f4d\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u5982\u4f55\u4f7f\u7528Pillow\u5e93\u548cOpenCV\u5e93\u4fee\u6539\u56fe\u50cf\u7684\u4f4d\u6df1\uff0c\u5e76\u8ba8\u8bba\u56fe\u50cf\u4f4d\u6df1\u7684\u91cd\u8981\u6027\u53ca\u5176\u5e94\u7528\u3002<\/p>\n<\/p>\n<hr>\n<p><h2>\u4e00\u3001PILLOW\u5e93\u4fee\u6539\u56fe\u50cf\u4f4d\u6df1<\/h2>\n<\/p>\n<p><p>Pillow\uff08PIL\uff09\u5e93\u662fPython\u4e2d\u5e7f\u6cdb\u4f7f\u7528\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u652f\u6301\u591a\u79cd\u56fe\u50cf\u683c\u5f0f\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u64cd\u4f5c\u529f\u80fd\u3002\u5728\u4fee\u6539\u56fe\u50cf\u4f4d\u6df1\u65f6\uff0cPillow\u5e93\u663e\u5f97\u5341\u5206\u4fbf\u6377\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u5b89\u88c5Pillow\u5e93<\/h3>\n<\/p>\n<p><p>\u8981\u4f7f\u7528Pillow\u5e93\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5\u5b83\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pillow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u6253\u5f00\u548c\u8f6c\u6362\u56fe\u50cf<\/h3>\n<\/p>\n<p><p>Pillow\u5e93\u63d0\u4f9b\u4e86\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u6253\u5f00\u548c\u8f6c\u6362\u56fe\u50cf\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5c068\u4f4d\u56fe\u50cf\u8f6c\u6362\u4e3a24\u4f4d\u56fe\u50cf\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u6253\u5f00\u56fe\u50cf<\/strong><\/h2>\n<p>img = Image.open(&#39;path_to_image&#39;)<\/p>\n<h2><strong>\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3aRGB\u6a21\u5f0f\uff0824\u4f4d\uff09<\/strong><\/h2>\n<p>img = img.convert(&#39;RGB&#39;)<\/p>\n<h2><strong>\u4fdd\u5b58\u4fee\u6539\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>img.save(&#39;path_to_new_image&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528<code>Image.open<\/code>\u65b9\u6cd5\u6253\u5f00\u56fe\u50cf\uff0c\u7136\u540e\u4f7f\u7528<code>convert<\/code>\u65b9\u6cd5\u5c06\u56fe\u50cf\u6a21\u5f0f\u8f6c\u6362\u4e3aRGB\u6a21\u5f0f\uff0cRGB\u6a21\u5f0f\u662f\u4e00\u79cd24\u4f4d\u6a21\u5f0f\uff0c\u6bcf\u4e2a\u50cf\u7d20\u4f7f\u752824\u4f4d\uff083\u4e2a\u5b57\u8282\uff09\u8868\u793a\u989c\u8272\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u5176\u4ed6\u6a21\u5f0f\u8f6c\u6362<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3aRGB\u6a21\u5f0f\u5916\uff0cPillow\u8fd8\u652f\u6301\u5176\u4ed6\u6a21\u5f0f\u7684\u8f6c\u6362\uff0c\u4f8b\u5982\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3a\u7070\u5ea6\u6a21\u5f0f\uff088\u4f4d\uff09\u6216RGBA\u6a21\u5f0f\uff0832\u4f4d\uff09\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8f6c\u6362\u4e3a\u7070\u5ea6\u6a21\u5f0f\uff088\u4f4d\uff09<\/p>\n<p>gray_img = img.convert(&#39;L&#39;)<\/p>\n<h2><strong>\u8f6c\u6362\u4e3aRGBA\u6a21\u5f0f\uff0832\u4f4d\uff09<\/strong><\/h2>\n<p>rgba_img = img.convert(&#39;RGBA&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u7075\u6d3b\u5730\u4fee\u6539\u56fe\u50cf\u7684\u4f4d\u6df1\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001OPENCV\u5e93\u4fee\u6539\u56fe\u50cf\u4f4d\u6df1<\/h2>\n<\/p>\n<p><p>OpenCV\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\uff0c\u652f\u6301\u591a\u79cd\u56fe\u50cf\u548c\u89c6\u9891\u5904\u7406\u529f\u80fd\u3002\u4f7f\u7528OpenCV\u4e5f\u53ef\u4ee5\u8f7b\u677e\u5730\u4fee\u6539\u56fe\u50cf\u7684\u4f4d\u6df1\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u5b89\u88c5OpenCV\u5e93<\/h3>\n<\/p>\n<p><p>\u8981\u4f7f\u7528OpenCV\u5e93\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5\u5b83\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install opencv-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u6253\u5f00\u548c\u8f6c\u6362\u56fe\u50cf<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528OpenCV\u6253\u5f00\u548c\u8f6c\u6362\u56fe\u50cf\u4e0ePillow\u7c7b\u4f3c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5c068\u4f4d\u56fe\u50cf\u8f6c\u6362\u4e3a24\u4f4d\u56fe\u50cf\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<h2><strong>\u6253\u5f00\u56fe\u50cf<\/strong><\/h2>\n<p>img = cv2.imread(&#39;path_to_image&#39;, cv2.IMREAD_GRAYSCALE)<\/p>\n<h2><strong>\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3aRGB\u6a21\u5f0f\uff0824\u4f4d\uff09<\/strong><\/h2>\n<p>rgb_img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)<\/p>\n<h2><strong>\u4fdd\u5b58\u4fee\u6539\u540e\u7684\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imwrite(&#39;path_to_new_image&#39;, rgb_img)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528<code>cv2.imread<\/code>\u65b9\u6cd5\u4ee5\u7070\u5ea6\u6a21\u5f0f\u6253\u5f00\u56fe\u50cf\uff0c\u7136\u540e\u4f7f\u7528<code>cv2.cvtColor<\/code>\u65b9\u6cd5\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3aRGB\u6a21\u5f0f\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u5176\u4ed6\u6a21\u5f0f\u8f6c\u6362<\/h3>\n<\/p>\n<p><p>OpenCV\u540c\u6837\u652f\u6301\u591a\u79cd\u6a21\u5f0f\u8f6c\u6362\uff0c\u4f8b\u5982\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3aRGBA\u6a21\u5f0f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8f6c\u6362\u4e3aRGBA\u6a21\u5f0f\uff0832\u4f4d\uff09<\/p>\n<p>rgba_img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGBA)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u7075\u6d3b\u5730\u4fee\u6539\u56fe\u50cf\u7684\u4f4d\u6df1\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u56fe\u50cf\u4f4d\u6df1\u7684\u91cd\u8981\u6027<\/h2>\n<\/p>\n<p><p>\u56fe\u50cf\u4f4d\u6df1\uff08Bit Depth\uff09\u6307\u7684\u662f\u56fe\u50cf\u4e2d\u6bcf\u4e2a\u50cf\u7d20\u6240\u4f7f\u7528\u7684\u4f4d\u6570\u3002\u4f4d\u6df1\u8d8a\u9ad8\uff0c\u56fe\u50cf\u80fd\u591f\u8868\u793a\u7684\u989c\u8272\u6216\u7070\u5ea6\u7ea7\u522b\u8d8a\u591a\uff0c\u56fe\u50cf\u7684\u8d28\u91cf\u4e5f\u5c31\u8d8a\u9ad8\u3002\u5e38\u89c1\u7684\u4f4d\u6df1\u5305\u62ec\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>8\u4f4d<\/strong>\uff1a\u901a\u5e38\u7528\u4e8e\u7070\u5ea6\u56fe\u50cf\uff0c\u6bcf\u4e2a\u50cf\u7d20\u4f7f\u75288\u4f4d\u8868\u793a\uff0c\u80fd\u591f\u8868\u793a256\u79cd\u7070\u5ea6\u7ea7\u522b\u3002<\/li>\n<li><strong>24\u4f4d<\/strong>\uff1a\u901a\u5e38\u7528\u4e8e\u5f69\u8272\u56fe\u50cf\uff0c\u6bcf\u4e2a\u50cf\u7d20\u4f7f\u752824\u4f4d\u8868\u793a\uff08RGB\uff0c\u6bcf\u4e2a\u901a\u90538\u4f4d\uff09\uff0c\u80fd\u591f\u8868\u793a1677\u4e07\u79cd\u989c\u8272\u3002<\/li>\n<li><strong>32\u4f4d<\/strong>\uff1a\u901a\u5e38\u7528\u4e8e\u5e26\u6709\u900f\u660e\u901a\u9053\u7684\u5f69\u8272\u56fe\u50cf\uff0c\u6bcf\u4e2a\u50cf\u7d20\u4f7f\u752832\u4f4d\u8868\u793a\uff08RGBA\uff0c\u6bcf\u4e2a\u901a\u90538\u4f4d\uff09\uff0c\u80fd\u591f\u8868\u793a1677\u4e07\u79cd\u989c\u8272\u548c256\u7ea7\u900f\u660e\u5ea6\u3002<\/li>\n<\/ul>\n<p><h3>1\u3001\u7070\u5ea6\u56fe\u50cf<\/h3>\n<\/p>\n<p><p>\u7070\u5ea6\u56fe\u50cf\u901a\u5e38\u4f7f\u75288\u4f4d\u8868\u793a\uff0c\u6bcf\u4e2a\u50cf\u7d20\u4f7f\u7528\u4e00\u4e2a\u5b57\u8282\uff088\u4f4d\uff09\u8868\u793a\u7070\u5ea6\u7ea7\u522b\u3002\u7070\u5ea6\u7ea7\u522b\u4ece0\uff08\u9ed1\u8272\uff09\u5230255\uff08\u767d\u8272\uff09\uff0c\u4e2d\u95f4\u7684\u503c\u8868\u793a\u4e0d\u540c\u7684\u7070\u5ea6\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u5f69\u8272\u56fe\u50cf<\/h3>\n<\/p>\n<p><p>\u5f69\u8272\u56fe\u50cf\u901a\u5e38\u4f7f\u752824\u4f4d\u8868\u793a\uff0c\u6bcf\u4e2a\u50cf\u7d20\u4f7f\u7528\u4e09\u4e2a\u5b57\u8282\uff0824\u4f4d\uff09\u8868\u793a\u989c\u8272\u4fe1\u606f\u3002\u6bcf\u4e2a\u5b57\u8282\u5206\u522b\u8868\u793a\u7ea2\u8272\u3001\u7eff\u8272\u548c\u84dd\u8272\u901a\u9053\u7684\u5f3a\u5ea6\u3002RGB\u6a21\u5f0f\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u5f69\u8272\u56fe\u50cf\u8868\u793a\u65b9\u5f0f\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u5e26\u900f\u660e\u901a\u9053\u7684\u56fe\u50cf<\/h3>\n<\/p>\n<p><p>\u5e26\u900f\u660e\u901a\u9053\u7684\u56fe\u50cf\u901a\u5e38\u4f7f\u752832\u4f4d\u8868\u793a\uff0c\u6bcf\u4e2a\u50cf\u7d20\u4f7f\u7528\u56db\u4e2a\u5b57\u8282\uff0832\u4f4d\uff09\u8868\u793a\u989c\u8272\u548c\u900f\u660e\u5ea6\u4fe1\u606f\u3002RGBA\u6a21\u5f0f\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u8868\u793a\u65b9\u5f0f\uff0c\u5206\u522b\u8868\u793a\u7ea2\u8272\u3001\u7eff\u8272\u3001\u84dd\u8272\u548c\u900f\u660e\u5ea6\u901a\u9053\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u5e94\u7528\u573a\u666f<\/h2>\n<\/p>\n<p><h3>1\u3001\u56fe\u50cf\u5904\u7406\u548c\u8ba1\u7b97\u673a\u89c6\u89c9<\/h3>\n<\/p>\n<p><p>\u5728\u56fe\u50cf\u5904\u7406\u548c\u8ba1\u7b97\u673a\u89c6\u89c9\u4e2d\uff0c\u4fee\u6539\u56fe\u50cf\u7684\u4f4d\u6df1\u662f\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u5728\u8fdb\u884c\u56fe\u50cf\u5206\u5272\u3001\u8fb9\u7f18\u68c0\u6d4b\u3001\u7279\u5f81\u63d0\u53d6\u7b49\u4efb\u52a1\u65f6\uff0c\u901a\u5e38\u9700\u8981\u5c06\u56fe\u50cf\u8f6c\u6362\u4e3a\u7070\u5ea6\u6a21\u5f0f\uff088\u4f4d\uff09\u4ee5\u7b80\u5316\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u56fe\u50cf\u5b58\u50a8\u548c\u4f20\u8f93<\/h3>\n<\/p>\n<p><p>\u56fe\u50cf\u7684\u4f4d\u6df1\u5bf9\u56fe\u50cf\u7684\u5b58\u50a8\u548c\u4f20\u8f93\u4e5f\u6709\u91cd\u8981\u5f71\u54cd\u3002\u4f4d\u6df1\u8d8a\u9ad8\uff0c\u56fe\u50cf\u7684\u6587\u4ef6\u5927\u5c0f\u4e5f\u5c31\u8d8a\u5927\u3002\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u901a\u8fc7\u964d\u4f4e\u56fe\u50cf\u7684\u4f4d\u6df1\u6765\u51cf\u5c11\u6587\u4ef6\u5927\u5c0f\uff0c\u4ece\u800c\u63d0\u9ad8\u5b58\u50a8\u548c\u4f20\u8f93\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u56fe\u50cf\u663e\u793a\u548c\u6253\u5370<\/h3>\n<\/p>\n<p><p>\u5728\u56fe\u50cf\u663e\u793a\u548c\u6253\u5370\u4e2d\uff0c\u56fe\u50cf\u7684\u4f4d\u6df1\u4e5f\u8d77\u7740\u91cd\u8981\u4f5c\u7528\u3002\u9ad8\u4f4d\u6df1\u7684\u56fe\u50cf\u80fd\u591f\u63d0\u4f9b\u66f4\u9ad8\u7684\u56fe\u50cf\u8d28\u91cf\uff0c\u4f46\u540c\u65f6\u4e5f\u9700\u8981\u66f4\u9ad8\u7684\u786c\u4ef6\u8981\u6c42\u3002\u5728\u67d0\u4e9b\u5e94\u7528\u4e2d\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u9009\u62e9\u5408\u9002\u7684\u4f4d\u6df1\u4ee5\u5e73\u8861\u56fe\u50cf\u8d28\u91cf\u548c\u786c\u4ef6\u8d44\u6e90\u3002<\/p>\n<\/p>\n<p><h3>4\u3001\u533b\u5b66\u56fe\u50cf\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u5728\u533b\u5b66\u56fe\u50cf\u5904\u7406\u9886\u57df\uff0c\u56fe\u50cf\u7684\u4f4d\u6df1\u5bf9\u8bca\u65ad\u548c\u5206\u6790\u81f3\u5173\u91cd\u8981\u3002\u533b\u5b66\u56fe\u50cf\u901a\u5e38\u9700\u8981\u9ad8\u4f4d\u6df1\uff08\u4f8b\u598216\u4f4d\u621632\u4f4d\uff09\u4ee5\u6355\u6349\u66f4\u591a\u7684\u7ec6\u8282\u4fe1\u606f\uff0c\u4ece\u800c\u63d0\u9ad8\u8bca\u65ad\u7684\u51c6\u786e\u6027\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u4fee\u6539\u56fe\u50cf\u7684\u4f4d\u6df1\u662f\u56fe\u50cf\u5904\u7406\u4e2d\u7684\u5e38\u89c1\u64cd\u4f5c\uff0c\u53ef\u4ee5\u901a\u8fc7Pillow\u5e93\u548cOpenCV\u5e93\u8f7b\u677e\u5b9e\u73b0\u3002\u4e0d\u540c\u7684\u5e94\u7528\u573a\u666f\u5bf9\u56fe\u50cf\u7684\u4f4d\u6df1\u6709\u4e0d\u540c\u7684\u8981\u6c42\uff0c\u901a\u8fc7\u5408\u7406\u9009\u62e9\u548c\u8f6c\u6362\u56fe\u50cf\u7684\u4f4d\u6df1\uff0c\u53ef\u4ee5\u5728\u4fdd\u8bc1\u56fe\u50cf\u8d28\u91cf\u7684\u540c\u65f6\uff0c\u63d0\u9ad8\u5b58\u50a8\u548c\u4f20\u8f93\u6548\u7387\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u4f4d\u6df1\u548c\u56fe\u50cf\u5904\u7406\u65b9\u6cd5\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u6ee1\u8db3\u5404\u7c7b\u56fe\u50cf\u5904\u7406\u4efb\u52a1\u7684\u8981\u6c42\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5224\u65ad\u6211\u7684\u56fe\u50cf\u5f53\u524d\u7684\u4f4d\u6df1\u662f\u591a\u5c11\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u4f7f\u7528\u56fe\u50cf\u5904\u7406\u5e93\u5982PIL\uff08Pillow\uff09\u6216OpenCV\u6765\u68c0\u67e5\u56fe\u50cf\u7684\u4f4d\u6df1\u3002\u4f7f\u7528PIL\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u52a0\u8f7d\u56fe\u50cf\u5e76\u67e5\u770b\u5176mode\u5c5e\u6027\u6765\u83b7\u53d6\u4f4d\u6df1\u4fe1\u606f\uff0c\u4f8b\u5982\u201cRGB\u201d\u8868\u793a8\u4f4d\u6df1\uff0c\u800c\u201cRGBA\u201d\u8868\u793a32\u4f4d\u6df1\u3002OpenCV\u5219\u53ef\u4ee5\u901a\u8fc7\u8bfb\u53d6\u56fe\u50cf\u5e76\u67e5\u770b\u6570\u636e\u7c7b\u578b\u6765\u83b7\u5f97\u4f4d\u6df1\u5ea6\u4fe1\u606f\u3002<\/p>\n<p><strong>\u4fee\u6539\u56fe\u50cf\u4f4d\u6df1\u4f1a\u5f71\u54cd\u56fe\u50cf\u8d28\u91cf\u5417\uff1f<\/strong><br \/>\u662f\u7684\uff0c\u4fee\u6539\u56fe\u50cf\u7684\u4f4d\u6df1\u53ef\u80fd\u4f1a\u5f71\u54cd\u56fe\u50cf\u8d28\u91cf\u3002\u4f8b\u5982\uff0c\u5c06\u4f4d\u6df1\u4ece16\u4f4d\u964d\u4f4e\u52308\u4f4d\u53ef\u80fd\u4f1a\u5bfc\u81f4\u989c\u8272\u4fe1\u606f\u7684\u4e22\u5931\u548c\u56fe\u50cf\u7ec6\u8282\u7684\u51cf\u5c11\u3002\u56e0\u6b64\uff0c\u5efa\u8bae\u5728\u8fdb\u884c\u4f4d\u6df1\u4fee\u6539\u65f6\u8c28\u614e\u64cd\u4f5c\uff0c\u5e76\u8003\u8651\u4fdd\u5b58\u539f\u59cb\u56fe\u50cf\u4ee5\u5907\u4e0d\u65f6\u4e4b\u9700\u3002<\/p>\n<p><strong>\u4f7f\u7528Python\u4fee\u6539\u56fe\u50cf\u4f4d\u6df1\u9700\u8981\u54ea\u4e9b\u5e93\uff1f<\/strong><br \/>\u5e38\u7528\u7684\u5e93\u5305\u62ecPillow\u548cOpenCV\u3002Pillow\u63d0\u4f9b\u4e86\u7b80\u5355\u6613\u7528\u7684\u63a5\u53e3\u6765\u5904\u7406\u56fe\u50cf\u53ca\u5176\u5c5e\u6027\uff0c\u9002\u5408\u521d\u5b66\u8005\u3002\u800cOpenCV\u5219\u529f\u80fd\u5f3a\u5927\uff0c\u9002\u5408\u9700\u8981\u8fdb\u884c\u590d\u6742\u56fe\u50cf\u5904\u7406\u7684\u5f00\u53d1\u8005\u3002\u6839\u636e\u60a8\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5e93\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u8fdb\u884c\u4f4d\u6df1\u4fee\u6539\u64cd\u4f5c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u4fee\u6539\u56fe\u50cf\u7684\u4f4d\u6df1\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u5982Python\u4e2d\u7684Pillow\u5e93\u3001OpenCV\u5e93\u7b49\u3002 \u4f7f\u7528Pillow [&hellip;]","protected":false},"author":3,"featured_media":1099132,"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\/1099122"}],"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=1099122"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1099122\/revisions"}],"predecessor-version":[{"id":1099133,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1099122\/revisions\/1099133"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1099132"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1099122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1099122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1099122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}