{"id":1046989,"date":"2024-12-31T13:38:36","date_gmt":"2024-12-31T05:38:36","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1046989.html"},"modified":"2024-12-31T13:38:38","modified_gmt":"2024-12-31T05:38:38","slug":"python-%e5%a6%82%e4%bd%95%e6%89%93%e5%bc%80%e4%b8%80%e5%bc%a0%e5%9b%be%e7%89%87","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1046989.html","title":{"rendered":"python \u5982\u4f55\u6253\u5f00\u4e00\u5f20\u56fe\u7247"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/87f4ba85-9e62-4534-acfe-9827b0d9d0b3.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python \u5982\u4f55\u6253\u5f00\u4e00\u5f20\u56fe\u7247\" \/><\/p>\n<p><p> <strong>Python\u6253\u5f00\u4e00\u5f20\u56fe\u7247\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528PIL\u5e93\u3001\u4f7f\u7528OpenCV\u5e93\u3001\u4f7f\u7528matplotlib\u5e93<\/strong>\u3002\u5176\u4e2d\uff0c\u4f7f\u7528PIL\u5e93\u662f\u6700\u7b80\u5355\u4e14\u5e38\u89c1\u7684\u65b9\u6cd5\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528PIL\u5e93\u6253\u5f00\u4e00\u5f20\u56fe\u7247\u3002<\/p>\n<\/p>\n<p><p>PIL\uff08Python Imaging Library\uff09\u662f\u4e00\u4e2a\u529f\u80fd\u975e\u5e38\u5f3a\u5927\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u652f\u6301\u6253\u5f00\u3001\u64cd\u4f5c\u548c\u4fdd\u5b58\u591a\u79cd\u683c\u5f0f\u7684\u56fe\u50cf\u3002\u4e3a\u4e86\u4f7f\u7528PIL\u5e93\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5Pillow\u6a21\u5757\uff0c\u8fd9\u662fPIL\u7684\u4e00\u4e2a\u5206\u652f\u548c\u517c\u5bb9\u7248\u672c\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Pillow\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pillow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6253\u5f00\u4e00\u5f20\u56fe\u7247\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\/your\/image.jpg&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>img.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c<code>Image.open<\/code>\u51fd\u6570\u7528\u4e8e\u6253\u5f00\u6307\u5b9a\u8def\u5f84\u7684\u56fe\u50cf\u6587\u4ef6\uff0c<code>img.show<\/code>\u7528\u4e8e\u663e\u793a\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u5728Python\u4e2d\u6253\u5f00\u56fe\u50cf\u7684\u5176\u4ed6\u65b9\u6cd5\uff0c\u5305\u62ecOpenCV\u548cmatplotlib\u5e93\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528PIL\u5e93<\/h3>\n<\/p>\n<p><p>PIL\u5e93\u662fPython\u4e2d\u5904\u7406\u56fe\u50cf\u7684\u6807\u51c6\u5e93\u3002\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u5904\u7406\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<p><h4>1.1\u3001\u6253\u5f00\u548c\u663e\u793a\u56fe\u50cf<\/h4>\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\/your\/image.jpg&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>img.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>1.2\u3001\u83b7\u53d6\u56fe\u50cf\u4fe1\u606f<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528PIL\u5e93\uff0c\u53ef\u4ee5\u8f7b\u677e\u83b7\u53d6\u56fe\u50cf\u7684\u57fa\u672c\u4fe1\u606f\uff0c\u5982\u5c3a\u5bf8\u3001\u683c\u5f0f\u7b49\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(f&quot;\u56fe\u50cf\u683c\u5f0f: {img.format}&quot;)<\/p>\n<p>print(f&quot;\u56fe\u50cf\u5c3a\u5bf8: {img.size}&quot;)<\/p>\n<p>print(f&quot;\u56fe\u50cf\u6a21\u5f0f: {img.mode}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>1.3\u3001\u56fe\u50cf\u7684\u57fa\u672c\u64cd\u4f5c<\/h4>\n<\/p>\n<p><p>PIL\u5e93\u8fd8\u63d0\u4f9b\u4e86\u8bf8\u5982\u88c1\u526a\u3001\u65cb\u8f6c\u3001\u7f29\u653e\u7b49\u57fa\u672c\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u88c1\u526a\u56fe\u50cf<\/p>\n<p>cropped_img = img.crop((100, 100, 400, 400))<\/p>\n<h2><strong>\u65cb\u8f6c\u56fe\u50cf<\/strong><\/h2>\n<p>rotated_img = img.rotate(45)<\/p>\n<h2><strong>\u7f29\u653e\u56fe\u50cf<\/strong><\/h2>\n<p>resized_img = img.resize((200, 200))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528OpenCV\u5e93<\/h3>\n<\/p>\n<p><p>OpenCV\uff08Open Source Computer Vision Library\uff09\u662f\u4e00\u4e2a\u5f00\u6e90\u8ba1\u7b97\u673a\u89c6\u89c9\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u8f6f\u4ef6\u5e93\u3002\u5b83\u5305\u542b\u4e86\u8d85\u8fc72500\u4e2a\u4f18\u5316\u7684\u7b97\u6cd5\uff0c\u53ef\u4ee5\u7528\u4e8e\u56fe\u50cf\u548c\u89c6\u9891\u5904\u7406\u3002\u5b89\u88c5OpenCV\u5e93\u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install opencv-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.1\u3001\u6253\u5f00\u548c\u663e\u793a\u56fe\u50cf<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528OpenCV\u6253\u5f00\u548c\u663e\u793a\u56fe\u50cf\u7684\u4ee3\u7801\u5982\u4e0b\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\/your\/image.jpg&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imshow(&#39;image&#39;, img)<\/p>\n<h2><strong>\u6309\u4efb\u610f\u952e\u5173\u95ed\u7a97\u53e3<\/strong><\/h2>\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><h4>2.2\u3001\u83b7\u53d6\u56fe\u50cf\u4fe1\u606f<\/h4>\n<\/p>\n<p><p>OpenCV\u4e2d\uff0c\u56fe\u50cf\u662f\u4ee5numpy\u6570\u7ec4\u7684\u5f62\u5f0f\u5b58\u50a8\u7684\uff0c\u56e0\u6b64\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528numpy\u7684\u65b9\u6cd5\u83b7\u53d6\u56fe\u50cf\u4fe1\u606f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>print(f&quot;\u56fe\u50cf\u5f62\u72b6: {img.shape}&quot;)<\/p>\n<p>print(f&quot;\u56fe\u50cf\u5c3a\u5bf8: {img.size}&quot;)<\/p>\n<p>print(f&quot;\u56fe\u50cf\u6570\u636e\u7c7b\u578b: {img.dtype}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.3\u3001\u56fe\u50cf\u7684\u57fa\u672c\u64cd\u4f5c<\/h4>\n<\/p>\n<p><p>OpenCV\u5e93\u4e5f\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u56fe\u50cf\u64cd\u4f5c\u529f\u80fd\uff0c\u5982\u88c1\u526a\u3001\u65cb\u8f6c\u3001\u7f29\u653e\u7b49\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u88c1\u526a\u56fe\u50cf<\/p>\n<p>cropped_img = img[100:400, 100:400]<\/p>\n<h2><strong>\u65cb\u8f6c\u56fe\u50cf<\/strong><\/h2>\n<p>(h, w) = img.shape[:2]<\/p>\n<p>center = (w \/ 2, h \/ 2)<\/p>\n<p>M = cv2.getRotationMatrix2D(center, 45, 1.0)<\/p>\n<p>rotated_img = cv2.warpAffine(img, M, (w, h))<\/p>\n<h2><strong>\u7f29\u653e\u56fe\u50cf<\/strong><\/h2>\n<p>resized_img = cv2.resize(img, (200, 200))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528matplotlib\u5e93<\/h3>\n<\/p>\n<p><p>matplotlib\u662f\u4e00\u4e2a\u7ed8\u56fe\u5e93\uff0c\u5e38\u7528\u4e8e\u7ed8\u5236\u56fe\u5f62\u548c\u56fe\u50cf\u3002\u5b89\u88c5matplotlib\u5e93\u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install matplotlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.1\u3001\u6253\u5f00\u548c\u663e\u793a\u56fe\u50cf<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528matplotlib\u6253\u5f00\u548c\u663e\u793a\u56fe\u50cf\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import matplotlib.image as mpimg<\/p>\n<h2><strong>\u6253\u5f00\u56fe\u50cf<\/strong><\/h2>\n<p>img = mpimg.imread(&#39;path\/to\/your\/image.jpg&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>plt.imshow(img)<\/p>\n<p>plt.axis(&#39;off&#39;)  # \u5173\u95ed\u5750\u6807\u8f74<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.2\u3001\u83b7\u53d6\u56fe\u50cf\u4fe1\u606f<\/h4>\n<\/p>\n<p><p>\u4e0eOpenCV\u7c7b\u4f3c\uff0cmatplotlib\u4e2d\u56fe\u50cf\u4e5f\u5b58\u50a8\u4e3anumpy\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528numpy\u7684\u65b9\u6cd5\u83b7\u53d6\u56fe\u50cf\u4fe1\u606f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(f&quot;\u56fe\u50cf\u5f62\u72b6: {img.shape}&quot;)<\/p>\n<p>print(f&quot;\u56fe\u50cf\u6570\u636e\u7c7b\u578b: {img.dtype}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.3\u3001\u56fe\u50cf\u7684\u57fa\u672c\u64cd\u4f5c<\/h4>\n<\/p>\n<p><p>matplotlib\u5e93\u4e3b\u8981\u7528\u4e8e\u663e\u793a\u56fe\u50cf\uff0c\u4f46\u7ed3\u5408numpy\u5e93\uff0c\u4e5f\u53ef\u4ee5\u8fdb\u884c\u4e00\u4e9b\u57fa\u672c\u7684\u56fe\u50cf\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u88c1\u526a\u56fe\u50cf<\/strong><\/h2>\n<p>cropped_img = img[100:400, 100:400]<\/p>\n<h2><strong>\u65cb\u8f6c\u56fe\u50cf<\/strong><\/h2>\n<p>rotated_img = np.rot90(img)<\/p>\n<h2><strong>\u7f29\u653e\u56fe\u50cf<\/strong><\/h2>\n<p>resized_img = np.array(Image.fromarray(img).resize((200, 200)))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u5176\u4ed6\u5e38\u7528\u56fe\u50cf\u5904\u7406\u5e93<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4e0a\u8ff0\u5e93\uff0c\u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u5e38\u7528\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u5982scikit-image\u3001imageio\u7b49\u3002\u8fd9\u91cc\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0b\u5b83\u4eec\u7684\u7528\u6cd5\uff1a<\/p>\n<\/p>\n<p><h4>4.1\u3001\u4f7f\u7528scikit-image\u5e93<\/h4>\n<\/p>\n<p><p>scikit-image\u662f\u4e00\u4e2a\u4e13\u95e8\u7528\u4e8e\u56fe\u50cf\u5904\u7406\u7684Python\u5e93\uff0c\u63d0\u4f9b\u4e86\u8bb8\u591a\u9ad8\u7ea7\u56fe\u50cf\u5904\u7406\u529f\u80fd\u3002\u5b89\u88c5scikit-image\u5e93\u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install scikit-image<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528scikit-image\u6253\u5f00\u548c\u663e\u793a\u56fe\u50cf\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from skimage import io<\/p>\n<h2><strong>\u6253\u5f00\u56fe\u50cf<\/strong><\/h2>\n<p>img = io.imread(&#39;path\/to\/your\/image.jpg&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>io.imshow(img)<\/p>\n<p>io.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4.2\u3001\u4f7f\u7528imageio\u5e93<\/h4>\n<\/p>\n<p><p>imageio\u662f\u4e00\u4e2a\u7528\u4e8e\u8bfb\u53d6\u548c\u5199\u5165\u56fe\u50cf\u6570\u636e\u7684Python\u5e93\uff0c\u652f\u6301\u591a\u79cd\u56fe\u50cf\u683c\u5f0f\u3002\u5b89\u88c5imageio\u5e93\u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install imageio<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528imageio\u6253\u5f00\u548c\u663e\u793a\u56fe\u50cf\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import imageio<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u6253\u5f00\u56fe\u50cf<\/strong><\/h2>\n<p>img = imageio.imread(&#39;path\/to\/your\/image.jpg&#39;)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>plt.imshow(img)<\/p>\n<p>plt.axis(&#39;off&#39;)  # \u5173\u95ed\u5750\u6807\u8f74<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528Python\u4e2d\u7684\u591a\u79cd\u5e93\uff08\u5305\u62ecPIL\u3001OpenCV\u3001matplotlib\u3001scikit-image\u3001imageio\uff09\u6253\u5f00\u548c\u663e\u793a\u56fe\u50cf\u3002\u6bcf\u4e2a\u5e93\u90fd\u6709\u5176\u72ec\u7279\u7684\u529f\u80fd\u548c\u4f18\u52bf\uff0c\u9009\u62e9\u5408\u9002\u7684\u5e93\u53d6\u51b3\u4e8e\u5177\u4f53\u9700\u6c42\u3002\u603b\u7684\u6765\u8bf4\uff0c<strong>PIL\u5e93\u9002\u5408\u8fdb\u884c\u7b80\u5355\u56fe\u50cf\u5904\u7406\uff0cOpenCV\u5e93\u9002\u5408\u8fdb\u884c\u590d\u6742\u7684\u56fe\u50cf\u548c\u89c6\u9891\u5904\u7406\uff0cmatplotlib\u5e93\u9002\u5408\u56fe\u50cf\u7684\u53ef\u89c6\u5316\u663e\u793a<\/strong>\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\uff0c\u80fd\u591f\u66f4\u597d\u5730\u7406\u89e3\u548c\u5e94\u7528Python\u8fdb\u884c\u56fe\u50cf\u5904\u7406\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8bfb\u53d6\u548c\u663e\u793a\u56fe\u7247\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528Python\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u5982PIL\uff08Pillow\uff09\u6216OpenCV\uff0c\u6765\u8bfb\u53d6\u548c\u663e\u793a\u56fe\u7247\u3002\u4f7f\u7528Pillow\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7<code>Image.open()<\/code>\u65b9\u6cd5\u52a0\u8f7d\u56fe\u7247\uff0c\u968f\u540e\u4f7f\u7528<code>Image.show()<\/code>\u6765\u663e\u793a\u56fe\u50cf\u3002\u4f7f\u7528OpenCV\u65f6\uff0c\u4f7f\u7528<code>cv2.imread()<\/code>\u8bfb\u53d6\u56fe\u50cf\uff0c\u63a5\u7740\u4f7f\u7528<code>cv2.imshow()<\/code>\u663e\u793a\u3002\u786e\u4fdd\u5b89\u88c5\u76f8\u5173\u5e93\uff0c\u4f8b\u5982\u4f7f\u7528<code>pip install Pillow<\/code>\u6216<code>pip install opencv-python<\/code>\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u6253\u5f00\u56fe\u7247\u65f6\uff0c\u652f\u6301\u54ea\u4e9b\u6587\u4ef6\u683c\u5f0f\uff1f<\/strong><br \/>Python\u7684\u56fe\u50cf\u5904\u7406\u5e93\u652f\u6301\u591a\u79cd\u6587\u4ef6\u683c\u5f0f\uff0c\u5305\u62ec\u4f46\u4e0d\u9650\u4e8eJPEG\u3001PNG\u3001BMP\u3001GIF\u7b49\u3002Pillow\u5e93\u652f\u6301\u5e38\u89c1\u7684\u56fe\u50cf\u683c\u5f0f\uff0c\u800cOpenCV\u5219\u4e3b\u8981\u5904\u7406JPEG\u548cPNG\u683c\u5f0f\u3002\u5982\u679c\u4f7f\u7528\u7279\u5b9a\u7684\u683c\u5f0f\uff0c\u786e\u4fdd\u4f60\u7684\u5e93\u652f\u6301\u8be5\u683c\u5f0f\uff0c\u5e76\u6839\u636e\u9700\u6c42\u8fdb\u884c\u8f6c\u6362\u3002<\/p>\n<p><strong>\u6211\u8be5\u5982\u4f55\u5904\u7406\u6253\u5f00\u7684\u56fe\u7247\uff0c\u4f8b\u5982\u8c03\u6574\u5927\u5c0f\u6216\u65cb\u8f6c\uff1f<\/strong><br \/>\u4f7f\u7528Pillow\u5e93\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528<code>resize()<\/code>\u65b9\u6cd5\u8c03\u6574\u56fe\u7247\u5927\u5c0f\uff0c\u6216\u4f7f\u7528<code>rotate()<\/code>\u65b9\u6cd5\u8fdb\u884c\u65cb\u8f6c\u3002\u4f8b\u5982\uff0c\u8981\u5c06\u56fe\u50cf\u8c03\u6574\u4e3a\u6307\u5b9a\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>image.resize((new_width, new_height))<\/code>\u3002\u5982\u679c\u4f7f\u7528OpenCV\uff0c\u7c7b\u4f3c\u7684\u529f\u80fd\u53ef\u4ee5\u901a\u8fc7<code>cv2.resize()<\/code>\u548c<code>cv2.rotate()<\/code>\u65b9\u6cd5\u5b9e\u73b0\u3002\u8fd9\u4e9b\u64cd\u4f5c\u53ef\u4ee5\u5e2e\u52a9\u6ee1\u8db3\u4e0d\u540c\u7684\u56fe\u50cf\u5904\u7406\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u6253\u5f00\u4e00\u5f20\u56fe\u7247\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528PIL\u5e93\u3001\u4f7f\u7528OpenCV\u5e93\u3001\u4f7f\u7528matplotlib\u5e93\u3002\u5176\u4e2d\uff0c\u4f7f\u7528P [&hellip;]","protected":false},"author":3,"featured_media":1046997,"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\/1046989"}],"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=1046989"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1046989\/revisions"}],"predecessor-version":[{"id":1046999,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1046989\/revisions\/1046999"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1046997"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1046989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1046989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1046989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}