{"id":49225,"date":"2025-07-30T16:26:53","date_gmt":"2025-07-30T08:26:53","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/49225.html"},"modified":"2025-07-30T16:26:53","modified_gmt":"2025-07-30T08:26:53","slug":"python-%e7%bc%96%e7%a8%8b%e7%9a%84%e5%9b%be%e5%83%8f%e5%a4%84%e7%90%86%e5%bf%85%e5%ad%a6%e6%8a%80%e5%b7%a7","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/49225.html","title":{"rendered":"Python \u7f16\u7a0b\u7684\u56fe\u50cf\u5904\u7406\u5fc5\u5b66\u6280\u5de7"},"content":{"rendered":"<h5>1. \u5411\u91cf\u5316\u64cd\u4f5c\u66ff\u4ee3\u9010\u50cf\u7d20\u5904\u7406<\/h5>\n<p>\u6ce8\u610f\uff1a\u9010\u50cf\u7d20\u5904\u7406\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(n\u00b2)\uff0c\u53ef\u80fd\u5bfc\u81f4\u5904\u7406\u901f\u5ea6\u4e0b\u964d90%<\/p>\n<p>\ud83d\udc49\u793a\u4f8b\uff1a\u4f7f\u7528OpenCV\u548cNumPy**\u5b9e\u73b0\u7070\u5ea6\u5316<\/p>\n<\/p>\n<p>import cv2<br \/>\nimport numpy as np<\/p>\n<p># \u6807\u51c6\u7248 (\u9010\u50cf\u7d20)<br \/>\ndef pixel_by_pixel(img):<br \/>\n    height, width = img.shape[:2]<br \/>\n    for y in range(height):<br \/>\n        for x in range(width):<br \/>\n            b, g, r = img[y, x]<br \/>\n            gray = int(0.114*b + 0.587*g + 0.299*r)  # ITU-R BT.601\u516c\u5f0f<br \/>\n            img[y, x] = [gray, gray, gray]<\/p>\n<p># \u4f18\u5316\u7248 (\u5411\u91cf\u5316)<br \/>\ndef vectorized(img):<br \/>\n    return cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)<\/p>\n<p>img = cv2.imread(\\&#8221;test.jpg\\&#8221;)<br \/>\nvectorized(img)  # \u5904\u7406\u901f\u5ea6\u63d0\u53471000\u500d <\/p>\n<ul id=\"code_id_0\"><\/ul>\n<h5>2. \u5185\u5b58\u6620\u5c04\u907f\u514d\u5168\u91cf\u52a0\u8f7d<\/h5>\n<p>\u8b66\u544a\uff1a\u5927\u56fe\u50cf\u5904\u7406\u65f6\u53ef\u80fd\u5f15\u53d1\u5185\u5b58\u6ea2\u51fa<\/p>\n<p>\ud83d\udc49\u793a\u4f8b\uff1a\u4f7f\u7528cv2.IMREAD_UNCHANGED\u53c2\u6570<\/p>\n<p># \u6807\u51c6\u7248 (\u5168\u91cf\u52a0\u8f7d)<br \/>\nimg = cv2.imread(\\&#8221;large_image.tif\\&#8221;)<\/p>\n<p># \u4f18\u5316\u7248 (\u5185\u5b58\u6620\u5c04)<br \/>\nimg = cv2.imreadmulti<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb184\u6b21\u3002\u3010\u56fe\u50cf\u5904\u7406\u4f18\u5316\u6280\u672f\u6458\u8981\u3011\u672c\u6587\u63d0\u51fa10\u79cd\u9ad8\u6548\u56fe\u50cf\u5904\u7406\u65b9\u6cd5\uff1a1\uff09\u5411\u91cf\u5316\u64cd\u4f5c\u66ff\u4ee3\u9010\u50cf\u7d20\u5904\u7406\uff0c\u901f\u5ea6\u63d0\u53471000\u500d\uff1b2\uff09\u5185\u5b58\u6620\u5c04\u907f\u514d\u5927\u56fe\u50cf\u5185\u5b58\u6ea2\u51fa\uff1b3\uff09\u7ebf\u7a0b\u6c60\u6279\u91cf\u5904\u7406\u51cf\u5c1140% I\/O\u5f00\u9500\uff1b4\uff09\u751f\u6210\u5668\u964d\u4f4e\u5185\u5b58\u5360\u7528\uff1b5\uff09\u9884\u5206\u914d\u6570\u7ec4\u907f\u514d\u52a8\u6001\u6269\u5c55\uff1b6\uff09\u539f\u5730\u64cd\u4f5c\u51cf\u5c11\u5185\u5b58\u590d\u5236\uff1b7\uff09\u9009\u62e9\u5408\u9002\u56fe\u50cf\u683c\u5f0f\u63d0\u534735%\u901f\u5ea6\uff1b8\uff09\u7f13\u5b58\u4e2d\u95f4\u7ed3\u679c\uff1b9\uff09GPU\u52a0\u901f\uff1b10\uff09C\u6269\u5c55\u4f18\u5316\u5173\u952e\u4ee3\u7801\u3002\u5b9e\u6218\u6848\u4f8b\u4e2d\uff0c1000\u5f202048&#215;2048\u9065\u611f\u56fe\u50cf\u5904\u7406\u65f6\u95f4\u4ece45\u79d2\u964d\u81f33\u79d2\uff0c\u7efc\u5408\u8fd0\u7528\u5411\u91cf\u5316\u3001\u6279\u91cf\u5904\u7406\u548c\u9884\u5206\u914d\u7b49\u6280\u672f\u5b9e\u73b0\u663e\u8457\u6027\u80fd\u63d0\u5347\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,3829,190,4773],"topic":[],"class_list":["post-49225","post","type-post","status-publish","format-standard","hentry","category-server","tag-python","tag-3829","tag-190","tag-4773"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python \u7f16\u7a0b\u7684\u56fe\u50cf\u5904\u7406\u5fc5\u5b66\u6280\u5de7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/49225.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python \u7f16\u7a0b\u7684\u56fe\u50cf\u5904\u7406\u5fc5\u5b66\u6280\u5de7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb184\u6b21\u3002\u3010\u56fe\u50cf\u5904\u7406\u4f18\u5316\u6280\u672f\u6458\u8981\u3011\u672c\u6587\u63d0\u51fa10\u79cd\u9ad8\u6548\u56fe\u50cf\u5904\u7406\u65b9\u6cd5\uff1a1\uff09\u5411\u91cf\u5316\u64cd\u4f5c\u66ff\u4ee3\u9010\u50cf\u7d20\u5904\u7406\uff0c\u901f\u5ea6\u63d0\u53471000\u500d\uff1b2\uff09\u5185\u5b58\u6620\u5c04\u907f\u514d\u5927\u56fe\u50cf\u5185\u5b58\u6ea2\u51fa\uff1b3\uff09\u7ebf\u7a0b\u6c60\u6279\u91cf\u5904\u7406\u51cf\u5c1140% I\/O\u5f00\u9500\uff1b4\uff09\u751f\u6210\u5668\u964d\u4f4e\u5185\u5b58\u5360\u7528\uff1b5\uff09\u9884\u5206\u914d\u6570\u7ec4\u907f\u514d\u52a8\u6001\u6269\u5c55\uff1b6\uff09\u539f\u5730\u64cd\u4f5c\u51cf\u5c11\u5185\u5b58\u590d\u5236\uff1b7\uff09\u9009\u62e9\u5408\u9002\u56fe\u50cf\u683c\u5f0f\u63d0\u534735%\u901f\u5ea6\uff1b8\uff09\u7f13\u5b58\u4e2d\u95f4\u7ed3\u679c\uff1b9\uff09GPU\u52a0\u901f\uff1b10\uff09C\u6269\u5c55\u4f18\u5316\u5173\u952e\u4ee3\u7801\u3002\u5b9e\u6218\u6848\u4f8b\u4e2d\uff0c1000\u5f202048x2048\u9065\u611f\u56fe\u50cf\u5904\u7406\u65f6\u95f4\u4ece45\u79d2\u964d\u81f33\u79d2\uff0c\u7efc\u5408\u8fd0\u7528\u5411\u91cf\u5316\u3001\u6279\u91cf\u5904\u7406\u548c\u9884\u5206\u914d\u7b49\u6280\u672f\u5b9e\u73b0\u663e\u8457\u6027\u80fd\u63d0\u5347\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/49225.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-30T08:26:53+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/49225.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/49225.html\",\"name\":\"Python \u7f16\u7a0b\u7684\u56fe\u50cf\u5904\u7406\u5fc5\u5b66\u6280\u5de7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-30T08:26:53+00:00\",\"dateModified\":\"2025-07-30T08:26:53+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/49225.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/49225.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/49225.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python \u7f16\u7a0b\u7684\u56fe\u50cf\u5904\u7406\u5fc5\u5b66\u6280\u5de7\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python \u7f16\u7a0b\u7684\u56fe\u50cf\u5904\u7406\u5fc5\u5b66\u6280\u5de7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/49225.html","og_locale":"zh_CN","og_type":"article","og_title":"Python \u7f16\u7a0b\u7684\u56fe\u50cf\u5904\u7406\u5fc5\u5b66\u6280\u5de7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb184\u6b21\u3002\u3010\u56fe\u50cf\u5904\u7406\u4f18\u5316\u6280\u672f\u6458\u8981\u3011\u672c\u6587\u63d0\u51fa10\u79cd\u9ad8\u6548\u56fe\u50cf\u5904\u7406\u65b9\u6cd5\uff1a1\uff09\u5411\u91cf\u5316\u64cd\u4f5c\u66ff\u4ee3\u9010\u50cf\u7d20\u5904\u7406\uff0c\u901f\u5ea6\u63d0\u53471000\u500d\uff1b2\uff09\u5185\u5b58\u6620\u5c04\u907f\u514d\u5927\u56fe\u50cf\u5185\u5b58\u6ea2\u51fa\uff1b3\uff09\u7ebf\u7a0b\u6c60\u6279\u91cf\u5904\u7406\u51cf\u5c1140% I\/O\u5f00\u9500\uff1b4\uff09\u751f\u6210\u5668\u964d\u4f4e\u5185\u5b58\u5360\u7528\uff1b5\uff09\u9884\u5206\u914d\u6570\u7ec4\u907f\u514d\u52a8\u6001\u6269\u5c55\uff1b6\uff09\u539f\u5730\u64cd\u4f5c\u51cf\u5c11\u5185\u5b58\u590d\u5236\uff1b7\uff09\u9009\u62e9\u5408\u9002\u56fe\u50cf\u683c\u5f0f\u63d0\u534735%\u901f\u5ea6\uff1b8\uff09\u7f13\u5b58\u4e2d\u95f4\u7ed3\u679c\uff1b9\uff09GPU\u52a0\u901f\uff1b10\uff09C\u6269\u5c55\u4f18\u5316\u5173\u952e\u4ee3\u7801\u3002\u5b9e\u6218\u6848\u4f8b\u4e2d\uff0c1000\u5f202048x2048\u9065\u611f\u56fe\u50cf\u5904\u7406\u65f6\u95f4\u4ece45\u79d2\u964d\u81f33\u79d2\uff0c\u7efc\u5408\u8fd0\u7528\u5411\u91cf\u5316\u3001\u6279\u91cf\u5904\u7406\u548c\u9884\u5206\u914d\u7b49\u6280\u672f\u5b9e\u73b0\u663e\u8457\u6027\u80fd\u63d0\u5347\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/49225.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-30T08:26:53+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/49225.html","url":"https:\/\/www.wsisp.com\/helps\/49225.html","name":"Python \u7f16\u7a0b\u7684\u56fe\u50cf\u5904\u7406\u5fc5\u5b66\u6280\u5de7 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-30T08:26:53+00:00","dateModified":"2025-07-30T08:26:53+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/49225.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/49225.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/49225.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python \u7f16\u7a0b\u7684\u56fe\u50cf\u5904\u7406\u5fc5\u5b66\u6280\u5de7"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/49225","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=49225"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/49225\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=49225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=49225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=49225"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=49225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}