{"id":1103461,"date":"2025-01-08T16:10:48","date_gmt":"2025-01-08T08:10:48","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1103461.html"},"modified":"2025-01-08T16:10:54","modified_gmt":"2025-01-08T08:10:54","slug":"%e5%9b%be%e7%89%87%e8%a6%81%e5%a6%82%e4%bd%95%e5%a4%84%e7%90%86%e6%89%8d%e8%83%bd%e8%a2%abpython%e8%af%86%e5%88%ab","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1103461.html","title":{"rendered":"\u56fe\u7247\u8981\u5982\u4f55\u5904\u7406\u624d\u80fd\u88abpython\u8bc6\u522b"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25065252\/b5c83e67-d83c-4e72-93d1-33a7792d77e7.webp\" alt=\"\u56fe\u7247\u8981\u5982\u4f55\u5904\u7406\u624d\u80fd\u88abpython\u8bc6\u522b\" \/><\/p>\n<p><p> <strong>\u56fe\u7247\u8981\u5982\u4f55\u5904\u7406\u624d\u80fd\u88abPython\u8bc6\u522b<\/strong>\uff1a<strong>\u5b89\u88c5\u5fc5\u8981\u7684\u5e93\u3001\u52a0\u8f7d\u56fe\u50cf\u3001\u9884\u5904\u7406\u56fe\u50cf\u3001\u7279\u5f81\u63d0\u53d6\u3001\u5e94\u7528<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u6a21\u578b<\/strong>\u3002\u5176\u4e2d\uff0c\u5b89\u88c5\u5fc5\u8981\u7684\u5e93\u662f\u6700\u57fa\u7840\u7684\u4e00\u6b65\uff0cPython\u6709\u8bb8\u591a\u56fe\u50cf\u5904\u7406\u5e93\u53ef\u4ee5\u9009\u62e9\uff0c\u5982Pillow\u3001OpenCV\u3001scikit-image\u7b49\u3002\u901a\u8fc7\u8fd9\u4e9b\u5e93\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u52a0\u8f7d\u3001\u9884\u5904\u7406\u548c\u5206\u6790\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><p>\u56fe\u50cf\u5904\u7406\u662f\u8ba1\u7b97\u673a\u89c6\u89c9\u7684\u57fa\u7840\u6b65\u9aa4\uff0cPython\u51ed\u501f\u5176\u5f3a\u5927\u7684\u5e93\u548c\u5de5\u5177\uff0c\u80fd\u591f\u9ad8\u6548\u5730\u5b8c\u6210\u8fd9\u4e00\u4efb\u52a1\u3002\u9996\u5148\uff0c\u4f60\u9700\u8981\u5b89\u88c5\u5fc5\u8981\u7684\u5e93\uff0c\u4f8b\u5982Pillow\u3001OpenCV\u3001scikit-image\u7b49\u3002\u901a\u8fc7\u8fd9\u4e9b\u5e93\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u52a0\u8f7d\u3001\u9884\u5904\u7406\u548c\u5206\u6790\u56fe\u50cf\u3002\u5176\u6b21\uff0c\u52a0\u8f7d\u56fe\u50cf\u662f\u8fdb\u884c\u56fe\u50cf\u5904\u7406\u7684\u7b2c\u4e00\u6b65\uff0c\u53ef\u4ee5\u4f7f\u7528Pillow\u7684Image\u6a21\u5757\u6216OpenCV\u7684imread\u51fd\u6570\u3002\u63a5\u4e0b\u6765\uff0c\u9884\u5904\u7406\u56fe\u50cf\u662f\u975e\u5e38\u91cd\u8981\u7684\u4e00\u6b65\uff0c\u5305\u62ec\u8c03\u6574\u5927\u5c0f\u3001\u7070\u5ea6\u8f6c\u6362\u3001\u4e8c\u503c\u5316\u3001\u53bb\u566a\u7b49\u64cd\u4f5c\u3002\u7279\u5f81\u63d0\u53d6\u662f\u4ece\u56fe\u50cf\u4e2d\u63d0\u53d6\u6709\u7528\u4fe1\u606f\u7684\u8fc7\u7a0b\uff0c\u8fd9\u4e9b\u7279\u5f81\u53ef\u4ee5\u662f\u989c\u8272\u76f4\u65b9\u56fe\u3001\u8fb9\u7f18\u3001\u7eb9\u7406\u7b49\u3002\u6700\u540e\uff0c\u5e94\u7528\u673a\u5668\u5b66\u4e60\u6a21\u578b\uff0c\u5982\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\uff08CNN\uff09\uff0c\u53ef\u4ee5\u5bf9\u56fe\u50cf\u8fdb\u884c\u5206\u7c7b\u3001\u8bc6\u522b\u3001\u68c0\u6d4b\u7b49\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b89\u88c5\u5fc5\u8981\u7684\u5e93<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u8fdb\u884c\u56fe\u50cf\u5904\u7406\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5\u4e00\u4e9bPython\u5e93\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff1a<\/p>\n<\/p>\n<p><h4>1. Pillow<\/h4>\n<\/p>\n<p><p>Pillow\u662fPython Imaging Library\uff08PIL\uff09\u7684\u4e00\u4e2a\u5206\u652f\uff0c\u63d0\u4f9b\u4e86\u5bf9\u56fe\u50cf\u6587\u4ef6\u7684\u6253\u5f00\u3001\u64cd\u4f5c\u548c\u4fdd\u5b58\u529f\u80fd\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\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><h4>2. OpenCV<\/h4>\n<\/p>\n<p><p>OpenCV\u662f\u4e00\u4e2a\u5f00\u6e90\u8ba1\u7b97\u673a\u89c6\u89c9\u548c\u673a\u5668\u5b66\u4e60\u5e93\uff0c\u652f\u6301\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5OpenCV\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>3. scikit-image<\/h4>\n<\/p>\n<p><p>scikit-image\u662f\u4e00\u4e2a\u7528\u4e8e\u56fe\u50cf\u5904\u7406\u7684Python\u5e93\uff0c\u57fa\u4e8escipy\u6784\u5efa\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5scikit-image\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install scikit-image<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u52a0\u8f7d\u56fe\u50cf<\/h3>\n<\/p>\n<p><p>\u52a0\u8f7d\u56fe\u50cf\u662f\u8fdb\u884c\u56fe\u50cf\u5904\u7406\u7684\u7b2c\u4e00\u6b65\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528Pillow\u7684Image\u6a21\u5757\u6216OpenCV\u7684imread\u51fd\u6570\u6765\u52a0\u8f7d\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528Pillow\u52a0\u8f7d\u56fe\u50cf<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u52a0\u8f7d\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><h4>2. \u4f7f\u7528OpenCV\u52a0\u8f7d\u56fe\u50cf<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<h2><strong>\u52a0\u8f7d\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;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>\u4e09\u3001\u9884\u5904\u7406\u56fe\u50cf<\/h3>\n<\/p>\n<p><p>\u9884\u5904\u7406\u56fe\u50cf\u662f\u975e\u5e38\u91cd\u8981\u7684\u4e00\u6b65\uff0c\u5305\u62ec\u8c03\u6574\u5927\u5c0f\u3001\u7070\u5ea6\u8f6c\u6362\u3001\u4e8c\u503c\u5316\u3001\u53bb\u566a\u7b49\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h4>1. \u8c03\u6574\u56fe\u50cf\u5927\u5c0f<\/h4>\n<\/p>\n<p><p>\u8c03\u6574\u56fe\u50cf\u5927\u5c0f\u53ef\u4ee5\u4f7f\u56fe\u50cf\u5904\u7406\u8fc7\u7a0b\u66f4\u52a0\u9ad8\u6548\uff0c\u5e76\u4e14\u5728\u5e94\u7528\u673a\u5668\u5b66\u4e60\u6a21\u578b\u65f6\uff0c\u901a\u5e38\u9700\u8981\u56fa\u5b9a\u5927\u5c0f\u7684\u8f93\u5165\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528Pillow\u8c03\u6574\u56fe\u50cf\u5927\u5c0f<\/p>\n<p>resized_image = image.resize((width, height))<\/p>\n<h2><strong>\u4f7f\u7528OpenCV\u8c03\u6574\u56fe\u50cf\u5927\u5c0f<\/strong><\/h2>\n<p>resized_image = cv2.resize(image, (width, height))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u7070\u5ea6\u8f6c\u6362<\/h4>\n<\/p>\n<p><p>\u5c06\u5f69\u8272\u56fe\u50cf\u8f6c\u6362\u4e3a\u7070\u5ea6\u56fe\u50cf\uff0c\u53ef\u4ee5\u7b80\u5316\u56fe\u50cf\u5904\u7406\u7684\u590d\u6742\u5ea6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528Pillow\u7070\u5ea6\u8f6c\u6362<\/p>\n<p>gray_image = image.convert(&#39;L&#39;)<\/p>\n<h2><strong>\u4f7f\u7528OpenCV\u7070\u5ea6\u8f6c\u6362<\/strong><\/h2>\n<p>gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3. \u4e8c\u503c\u5316<\/h4>\n<\/p>\n<p><p>\u4e8c\u503c\u5316\u662f\u5c06\u7070\u5ea6\u56fe\u50cf\u8f6c\u6362\u4e3a\u53ea\u6709\u9ed1\u767d\u4e24\u79cd\u989c\u8272\u7684\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528Pillow\u4e8c\u503c\u5316<\/p>\n<p>binary_image = gray_image.point(lambda x: 0 if x &lt; 128 else 255, &#39;1&#39;)<\/p>\n<h2><strong>\u4f7f\u7528OpenCV\u4e8c\u503c\u5316<\/strong><\/h2>\n<p>ret, binary_image = cv2.threshold(gray_image, 128, 255, cv2.THRESH_BINARY)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4. \u53bb\u566a<\/h4>\n<\/p>\n<p><p>\u53bb\u566a\u662f\u4e3a\u4e86\u53bb\u9664\u56fe\u50cf\u4e2d\u7684\u566a\u58f0\uff0c\u4f7f\u5f97\u56fe\u50cf\u66f4\u52a0\u6e05\u6670\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528OpenCV\u53bb\u566a<\/p>\n<p>denoised_image = cv2.GaussianBlur(image, (5, 5), 0)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u7279\u5f81\u63d0\u53d6<\/h3>\n<\/p>\n<p><p>\u7279\u5f81\u63d0\u53d6\u662f\u4ece\u56fe\u50cf\u4e2d\u63d0\u53d6\u6709\u7528\u4fe1\u606f\u7684\u8fc7\u7a0b\uff0c\u8fd9\u4e9b\u7279\u5f81\u53ef\u4ee5\u662f\u989c\u8272\u76f4\u65b9\u56fe\u3001\u8fb9\u7f18\u3001\u7eb9\u7406\u7b49\u3002<\/p>\n<\/p>\n<p><h4>1. \u989c\u8272\u76f4\u65b9\u56fe<\/h4>\n<\/p>\n<p><p>\u989c\u8272\u76f4\u65b9\u56fe\u662f\u8868\u793a\u56fe\u50cf\u4e2d\u5404\u4e2a\u989c\u8272\u51fa\u73b0\u9891\u7387\u7684\u56fe\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528OpenCV\u8ba1\u7b97\u989c\u8272\u76f4\u65b9\u56fe<\/p>\n<p>hist = cv2.calcHist([image], [0], None, [256], [0, 256])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u8fb9\u7f18\u68c0\u6d4b<\/h4>\n<\/p>\n<p><p>\u8fb9\u7f18\u68c0\u6d4b\u662f\u8bc6\u522b\u56fe\u50cf\u4e2d\u7269\u4f53\u8fb9\u7f18\u7684\u91cd\u8981\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528OpenCV\u7684Canny\u8fb9\u7f18\u68c0\u6d4b<\/p>\n<p>edges = cv2.Canny(image, 100, 200)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3. \u7eb9\u7406\u5206\u6790<\/h4>\n<\/p>\n<p><p>\u7eb9\u7406\u5206\u6790\u662f\u8bc6\u522b\u56fe\u50cf\u4e2d\u4e0d\u540c\u533a\u57df\u7684\u7eb9\u7406\u7279\u5f81\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528scikit-image\u7684\u5c40\u90e8\u4e8c\u503c\u6a21\u5f0f\uff08LBP\uff09\u8fdb\u884c\u7eb9\u7406\u5206\u6790<\/p>\n<p>from skimage.feature import local_binary_pattern<\/p>\n<p>lbp = local_binary_pattern(gray_image, P=8, R=1, method=&#39;uniform&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u5e94\u7528\u673a\u5668\u5b66\u4e60\u6a21\u578b<\/h3>\n<\/p>\n<p><p>\u5e94\u7528\u673a\u5668\u5b66\u4e60\u6a21\u578b\uff0c\u5982\u5377\u79ef\u795e\u7ecf\u7f51\u7edc\uff08CNN\uff09\uff0c\u53ef\u4ee5\u5bf9\u56fe\u50cf\u8fdb\u884c\u5206\u7c7b\u3001\u8bc6\u522b\u3001\u68c0\u6d4b\u7b49\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><h4>1. \u56fe\u50cf\u5206\u7c7b<\/h4>\n<\/p>\n<p><p>\u56fe\u50cf\u5206\u7c7b\u662f\u5c06\u56fe\u50cf\u5206\u4e3a\u4e0d\u540c\u7c7b\u522b\u7684\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528Keras\u52a0\u8f7d\u9884\u8bad\u7ec3\u7684VGG16\u6a21\u578b\u8fdb\u884c\u56fe\u50cf\u5206\u7c7b<\/p>\n<p>from keras.applications.vgg16 import VGG16<\/p>\n<p>from keras.applications.vgg16 import preprocess_input, decode_predictions<\/p>\n<p>from keras.preprocessing import image<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u52a0\u8f7d\u9884\u8bad\u7ec3\u7684VGG16\u6a21\u578b<\/strong><\/h2>\n<p>model = VGG16(weights=&#39;imagenet&#39;)<\/p>\n<h2><strong>\u52a0\u8f7d\u56fe\u50cf\u5e76\u8fdb\u884c\u9884\u5904\u7406<\/strong><\/h2>\n<p>img = image.load_img(&#39;path_to_image.jpg&#39;, target_size=(224, 224))<\/p>\n<p>x = image.img_to_array(img)<\/p>\n<p>x = np.expand_dims(x, axis=0)<\/p>\n<p>x = preprocess_input(x)<\/p>\n<h2><strong>\u8fdb\u884c\u9884\u6d4b<\/strong><\/h2>\n<p>preds = model.predict(x)<\/p>\n<p>print(&#39;Predicted:&#39;, decode_predictions(preds, top=3)[0])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u76ee\u6807\u68c0\u6d4b<\/h4>\n<\/p>\n<p><p>\u76ee\u6807\u68c0\u6d4b\u662f\u8bc6\u522b\u56fe\u50cf\u4e2d\u7269\u4f53\u7684\u4f4d\u7f6e\u548c\u7c7b\u522b\u7684\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528YOLOv3\u8fdb\u884c\u76ee\u6807\u68c0\u6d4b<\/p>\n<p>import cv2<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u52a0\u8f7dYOLOv3\u6a21\u578b\u548c\u6743\u91cd<\/strong><\/h2>\n<p>net = cv2.dnn.readNet(&#39;yolov3.weights&#39;, &#39;yolov3.cfg&#39;)<\/p>\n<h2><strong>\u52a0\u8f7d\u7c7b\u522b\u540d\u79f0<\/strong><\/h2>\n<p>with open(&#39;coco.names&#39;, &#39;r&#39;) as f:<\/p>\n<p>    classes = [line.strip() for line in f.readlines()]<\/p>\n<h2><strong>\u52a0\u8f7d\u56fe\u50cf\u5e76\u8fdb\u884c\u9884\u5904\u7406<\/strong><\/h2>\n<p>image = cv2.imread(&#39;path_to_image.jpg&#39;)<\/p>\n<p>height, width, channels = image.shape<\/p>\n<p>blob = cv2.dnn.blobFromImage(image, 0.00392, (416, 416), (0, 0, 0), True, crop=False)<\/p>\n<p>net.setInput(blob)<\/p>\n<h2><strong>\u8fdb\u884c\u524d\u5411\u4f20\u64ad<\/strong><\/h2>\n<p>outs = net.forward(net.getUnconnectedOutLayersNames())<\/p>\n<h2><strong>\u89e3\u6790\u8f93\u51fa<\/strong><\/h2>\n<p>class_ids = []<\/p>\n<p>confidences = []<\/p>\n<p>boxes = []<\/p>\n<p>for out in outs:<\/p>\n<p>    for detection in out:<\/p>\n<p>        scores = detection[5:]<\/p>\n<p>        class_id = np.argmax(scores)<\/p>\n<p>        confidence = scores[class_id]<\/p>\n<p>        if confidence &gt; 0.5:<\/p>\n<p>            center_x = int(detection[0] * width)<\/p>\n<p>            center_y = int(detection[1] * height)<\/p>\n<p>            w = int(detection[2] * width)<\/p>\n<p>            h = int(detection[3] * height)<\/p>\n<p>            x = int(center_x - w \/ 2)<\/p>\n<p>            y = int(center_y - h \/ 2)<\/p>\n<p>            boxes.append([x, y, w, h])<\/p>\n<p>            confidences.append(float(confidence))<\/p>\n<p>            class_ids.append(class_id)<\/p>\n<h2><strong>\u5e94\u7528\u975e\u6700\u5927\u503c\u6291\u5236<\/strong><\/h2>\n<p>indices = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4)<\/p>\n<h2><strong>\u7ed8\u5236\u8fb9\u754c\u6846<\/strong><\/h2>\n<p>for i in indices:<\/p>\n<p>    i = i[0]<\/p>\n<p>    box = boxes[i]<\/p>\n<p>    x, y, w, h = box[0], box[1], box[2], box[3]<\/p>\n<p>    label = str(classes[class_ids[i]])<\/p>\n<p>    cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)<\/p>\n<p>    cv2.putText(image, label, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imshow(&#39;Image&#39;, image)<\/p>\n<p>cv2.waitKey(0)<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u56fe\u50cf\u5904\u7406\u662f\u8ba1\u7b97\u673a\u89c6\u89c9\u7684\u91cd\u8981\u7ec4\u6210\u90e8\u5206\uff0cPython\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5e93\u548c\u5de5\u5177\uff0c\u4f7f\u5f97\u56fe\u50cf\u5904\u7406\u53d8\u5f97\u66f4\u52a0\u7b80\u5355\u548c\u9ad8\u6548\u3002\u901a\u8fc7\u5b89\u88c5\u5fc5\u8981\u7684\u5e93\u3001\u52a0\u8f7d\u56fe\u50cf\u3001\u9884\u5904\u7406\u56fe\u50cf\u3001\u7279\u5f81\u63d0\u53d6\u548c\u5e94\u7528\u673a\u5668\u5b66\u4e60\u6a21\u578b\uff0c\u4f60\u53ef\u4ee5\u5b9e\u73b0\u5404\u79cd\u56fe\u50cf\u5904\u7406\u4efb\u52a1\u3002\u5e0c\u671b\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u4f60\u80fd\u591f\u638c\u63e1\u57fa\u672c\u7684\u56fe\u50cf\u5904\u7406\u65b9\u6cd5\uff0c\u5e76\u5728\u5b9e\u8df5\u4e2d\u5e94\u7528\u8fd9\u4e9b\u6280\u672f\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5c06\u56fe\u7247\u683c\u5f0f\u8f6c\u6362\u4e3aPython\u53ef\u8bc6\u522b\u7684\u683c\u5f0f\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u5e38\u89c1\u7684\u56fe\u50cf\u5904\u7406\u5e93\u5982PIL\uff08Pillow\uff09\u548cOpenCV\u652f\u6301\u591a\u79cd\u56fe\u50cf\u683c\u5f0f\uff0c\u5305\u62ecJPEG\u3001PNG\u3001BMP\u7b49\u3002\u5982\u679c\u60a8\u7684\u56fe\u7247\u683c\u5f0f\u4e0d\u88ab\u652f\u6301\uff0c\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e9b\u5e93\u8fdb\u884c\u683c\u5f0f\u8f6c\u6362\u3002\u4f8b\u5982\uff0cPIL\u53ef\u4ee5\u901a\u8fc7<code>Image.open()<\/code>\u51fd\u6570\u8bfb\u53d6\u56fe\u7247\uff0c\u7136\u540e\u4f7f\u7528<code>Image.save()<\/code>\u65b9\u6cd5\u5c06\u5176\u4fdd\u5b58\u4e3a\u5176\u4ed6\u683c\u5f0f\u3002\u786e\u4fdd\u5728\u8f6c\u6362\u524d\u4e86\u89e3\u76ee\u6807\u683c\u5f0f\u7684\u7279\u6027\uff0c\u4ee5\u786e\u4fdd\u6700\u4f73\u8d28\u91cf\u3002<\/p>\n<p><strong>Python\u4e2d\u5982\u4f55\u8bfb\u53d6\u548c\u5904\u7406\u56fe\u7247\u6570\u636e\uff1f<\/strong><br \/>\u8bfb\u53d6\u56fe\u7247\u6570\u636e\u65f6\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528PIL\u5e93\u7684<code>Image.open()<\/code>\u65b9\u6cd5\uff0c\u6216\u4f7f\u7528OpenCV\u7684<code>cv2.imread()<\/code>\u51fd\u6570\u3002\u8fd9\u4e24\u79cd\u65b9\u6cd5\u90fd\u53ef\u4ee5\u52a0\u8f7d\u56fe\u7247\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u6570\u7ec4\u683c\u5f0f\uff0c\u65b9\u4fbf\u540e\u7eed\u5904\u7406\u3002\u5904\u7406\u56fe\u7247\u6570\u636e\u65f6\uff0c\u53ef\u4ee5\u8fdb\u884c\u5404\u79cd\u64cd\u4f5c\uff0c\u6bd4\u5982\u8c03\u6574\u5927\u5c0f\u3001\u65cb\u8f6c\u3001\u88c1\u526a\u548c\u6ee4\u955c\u5904\u7406\u7b49\uff0c\u5177\u4f53\u529f\u80fd\u53ef\u4ee5\u53c2\u8003\u76f8\u5e94\u5e93\u7684\u6587\u6863\u3002<\/p>\n<p><strong>\u5982\u4f55\u63d0\u9ad8Python\u5bf9\u56fe\u7247\u7684\u5904\u7406\u901f\u5ea6\uff1f<\/strong><br \/>\u4e3a\u4e86\u63d0\u9ad8\u56fe\u7247\u5904\u7406\u901f\u5ea6\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528NumPy\u6570\u7ec4\u6765\u52a0\u901f\u56fe\u50cf\u7684\u8fd0\u7b97\u3002\u901a\u8fc7\u5c06\u56fe\u7247\u8f6c\u6362\u4e3aNumPy\u6570\u7ec4\uff0c\u60a8\u53ef\u4ee5\u5229\u7528\u5176\u9ad8\u6548\u7684\u77e9\u9635\u8fd0\u7b97\u7279\u6027\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u591a\u7ebf\u7a0b\u6216GPU\u52a0\u901f\u7684\u5e93\u5982CuPy\u548cTensorFlow\u4e5f\u80fd\u663e\u8457\u63d0\u5347\u5904\u7406\u6027\u80fd\u3002\u5728\u5904\u7406\u5927\u6279\u91cf\u56fe\u50cf\u65f6\uff0c\u6279\u5904\u7406\u6280\u672f\u4e5f\u80fd\u6709\u6548\u51cf\u5c11\u65f6\u95f4\u5f00\u9500\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u56fe\u7247\u8981\u5982\u4f55\u5904\u7406\u624d\u80fd\u88abPython\u8bc6\u522b\uff1a\u5b89\u88c5\u5fc5\u8981\u7684\u5e93\u3001\u52a0\u8f7d\u56fe\u50cf\u3001\u9884\u5904\u7406\u56fe\u50cf\u3001\u7279\u5f81\u63d0\u53d6\u3001\u5e94\u7528\u673a\u5668\u5b66\u4e60\u6a21\u578b\u3002\u5176\u4e2d\uff0c\u5b89 [&hellip;]","protected":false},"author":3,"featured_media":1103471,"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\/1103461"}],"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=1103461"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1103461\/revisions"}],"predecessor-version":[{"id":1103475,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1103461\/revisions\/1103475"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1103471"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1103461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1103461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1103461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}