{"id":1172135,"date":"2025-01-15T16:45:03","date_gmt":"2025-01-15T08:45:03","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1172135.html"},"modified":"2025-01-15T16:45:07","modified_gmt":"2025-01-15T08:45:07","slug":"python%e5%a6%82%e4%bd%95%e5%9c%a8%e5%9b%be%e5%83%8f%e4%b8%8a%e7%94%bb%e5%9c%88","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1172135.html","title":{"rendered":"python\u5982\u4f55\u5728\u56fe\u50cf\u4e0a\u753b\u5708"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26074322\/6629dfdf-d4df-4c1c-9257-4db8eacb7fb2.webp\" alt=\"python\u5982\u4f55\u5728\u56fe\u50cf\u4e0a\u753b\u5708\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u5e93\u5728\u56fe\u50cf\u4e0a\u753b\u5708\u3002\u5e38\u7528\u7684\u5e93\u6709OpenCV\u3001PIL\uff08Pillow\uff09\u548cMatplotlib\u3002<\/strong> \u5176\u4e2d\uff0cOpenCV\u662f\u6700\u5e38\u7528\u7684\u56fe\u50cf\u5904\u7406\u5e93\uff0c\u56e0\u4e3a\u5b83\u529f\u80fd\u5f3a\u5927\u3001\u4f7f\u7528\u65b9\u4fbf\u3001\u6548\u7387\u9ad8\u3002\u4ee5\u4e0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528OpenCV\u5728\u56fe\u50cf\u4e0a\u753b\u5708\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528OpenCV\u5728\u56fe\u50cf\u4e0a\u753b\u5708\u975e\u5e38\u7b80\u5355\uff0c\u4e3b\u8981\u6b65\u9aa4\u5305\u62ec\u52a0\u8f7d\u56fe\u50cf\u3001\u5b9a\u4e49\u5706\u5fc3\u548c\u534a\u5f84\u3001\u8c03\u7528\u753b\u5708\u51fd\u6570\u7b49\u3002<\/strong> \u5177\u4f53\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<h2><strong>\u8bfb\u53d6\u56fe\u50cf<\/strong><\/h2>\n<p>image = cv2.imread(&#39;path\/to\/your\/image.jpg&#39;)<\/p>\n<h2><strong>\u5b9a\u4e49\u5706\u5fc3\u548c\u534a\u5f84<\/strong><\/h2>\n<p>center_coordinates = (120, 100)  # \u5706\u5fc3\u5750\u6807 (x, y)<\/p>\n<p>radius = 50  # \u5706\u7684\u534a\u5f84<\/p>\n<h2><strong>\u5b9a\u4e49\u989c\u8272\u548c\u539a\u5ea6<\/strong><\/h2>\n<p>color = (0, 255, 0)  # \u7eff\u8272 (B, G, R)<\/p>\n<p>thickness = 2  # \u7ebf\u6761\u539a\u5ea6<\/p>\n<h2><strong>\u5728\u56fe\u50cf\u4e0a\u753b\u5708<\/strong><\/h2>\n<p>cv2.circle(image, center_coordinates, radius, color, thickness)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>cv2.imshow(&#39;Image with Circle&#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><p><strong>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4f7f\u7528cv2.imread\u51fd\u6570\u52a0\u8f7d\u56fe\u50cf\uff0c\u7136\u540e\u4f7f\u7528cv2.circle\u51fd\u6570\u5728\u56fe\u50cf\u4e0a\u753b\u5708\u3002cv2.circle\u51fd\u6570\u7684\u53c2\u6570\u5305\u62ec\u56fe\u50cf\u3001\u5706\u5fc3\u5750\u6807\u3001\u534a\u5f84\u3001\u989c\u8272\u548c\u7ebf\u6761\u539a\u5ea6\u3002\u6700\u540e\uff0c\u6211\u4eec\u4f7f\u7528cv2.imshow\u51fd\u6570\u663e\u793a\u5904\u7406\u540e\u7684\u56fe\u50cf\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4f7f\u7528PIL\u548cMatplotlib\u5728\u56fe\u50cf\u4e0a\u753b\u5708\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528PIL\u5728\u56fe\u50cf\u4e0a\u753b\u5708<\/h3>\n<\/p>\n<p><p>PIL\uff08Python Imaging Library\uff09\u662f\u4e00\u4e2a\u7528\u4e8e\u56fe\u50cf\u5904\u7406\u7684Python\u5e93\uff0c\u540e\u6765\u88abPillow\u66ff\u4ee3\u3002\u4f7f\u7528Pillow\u5728\u56fe\u50cf\u4e0a\u753b\u5708\u4e5f\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u6b65\u9aa4\u548c\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u52a0\u8f7d\u56fe\u50cf<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u52a0\u8f7d\u56fe\u50cf\uff0c\u53ef\u4ee5\u4f7f\u7528<code>Image.open<\/code>\u51fd\u6570\u6765\u5b8c\u6210\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image, ImageDraw<\/p>\n<h2><strong>\u6253\u5f00\u56fe\u50cf<\/strong><\/h2>\n<p>image = Image.open(&#39;path\/to\/your\/image.jpg&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5b9a\u4e49\u5706\u5fc3\u548c\u534a\u5f84<\/h4>\n<\/p>\n<p><p>\u5b9a\u4e49\u5706\u5fc3\u5750\u6807\u548c\u534a\u5f84\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8c03\u6574\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">center_coordinates = (120, 100)  # \u5706\u5fc3\u5750\u6807 (x, y)<\/p>\n<p>radius = 50  # \u5706\u7684\u534a\u5f84<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u753b\u5708<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528<code>ImageDraw.Draw<\/code>\u7c7b\u7684<code>ellipse<\/code>\u65b9\u6cd5\u6765\u753b\u5708\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u7ed8\u56fe\u5bf9\u8c61<\/p>\n<p>draw = ImageDraw.Draw(image)<\/p>\n<h2><strong>\u5b9a\u4e49\u5706\u7684\u8fb9\u754c\u6846<\/strong><\/h2>\n<p>left_up_point = (center_coordinates[0] - radius, center_coordinates[1] - radius)<\/p>\n<p>right_down_point = (center_coordinates[0] + radius, center_coordinates[1] + radius)<\/p>\n<h2><strong>\u753b\u5708<\/strong><\/h2>\n<p>draw.ellipse([left_up_point, right_down_point], outline=&#39;green&#39;, width=2)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>image.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Matplotlib\u5728\u56fe\u50cf\u4e0a\u753b\u5708<\/h3>\n<\/p>\n<p><p>Matplotlib\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u7ed8\u56fe\u5e93\uff0c\u4e5f\u53ef\u4ee5\u7528\u4e8e\u5728\u56fe\u50cf\u4e0a\u753b\u5708\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Matplotlib\u5728\u56fe\u50cf\u4e0a\u753b\u5708\u7684\u8be6\u7ec6\u6b65\u9aa4\u548c\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u52a0\u8f7d\u56fe\u50cf<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4f7f\u7528<code>imread<\/code>\u51fd\u6570\u52a0\u8f7d\u56fe\u50cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import matplotlib.patches as patches<\/p>\n<h2><strong>\u8bfb\u53d6\u56fe\u50cf<\/strong><\/h2>\n<p>image = plt.imread(&#39;path\/to\/your\/image.jpg&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5b9a\u4e49\u5706\u5fc3\u548c\u534a\u5f84<\/h4>\n<\/p>\n<p><p>\u5b9a\u4e49\u5706\u5fc3\u5750\u6807\u548c\u534a\u5f84\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">center_coordinates = (120, 100)  # \u5706\u5fc3\u5750\u6807 (x, y)<\/p>\n<p>radius = 50  # \u5706\u7684\u534a\u5f84<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u753b\u5708<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528<code>patches.Circle<\/code>\u7c7b\u6765\u753b\u5708\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u56fe\u5f62\u548c\u5b50\u56fe<\/p>\n<p>fig, ax = plt.subplots()<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>ax.imshow(image)<\/p>\n<h2><strong>\u521b\u5efa\u5706\u5f62\u8865\u4e01<\/strong><\/h2>\n<p>circle = patches.Circle(center_coordinates, radius, linewidth=2, edgecolor=&#39;green&#39;, facecolor=&#39;none&#39;)<\/p>\n<h2><strong>\u6dfb\u52a0\u5706\u5f62\u8865\u4e01\u5230\u5b50\u56fe<\/strong><\/h2>\n<p>ax.add_patch(circle)<\/p>\n<h2><strong>\u663e\u793a\u56fe\u50cf<\/strong><\/h2>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u5728\u56fe\u50cf\u4e0a\u753b\u5708\u7684\u5e94\u7528\u573a\u666f<\/h3>\n<\/p>\n<p><p>\u5728\u56fe\u50cf\u4e0a\u753b\u5708\u7684\u64cd\u4f5c\u5728\u8bb8\u591a\u56fe\u50cf\u5904\u7406\u548c\u8ba1\u7b97\u673a\u89c6\u89c9\u4efb\u52a1\u4e2d\u975e\u5e38\u5e38\u89c1\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e94\u7528\u573a\u666f\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u76ee\u6807\u68c0\u6d4b<\/h4>\n<\/p>\n<p><p>\u5728\u76ee\u6807\u68c0\u6d4b\u4efb\u52a1\u4e2d\uff0c\u901a\u5e38\u9700\u8981\u5728\u68c0\u6d4b\u5230\u7684\u76ee\u6807\u5468\u56f4\u753b\u5708\u6216\u77e9\u5f62\u6846\uff0c\u4ee5\u6807\u8bc6\u76ee\u6807\u7684\u4f4d\u7f6e\u3002\u4f8b\u5982\uff0c\u5728\u81ea\u52a8\u9a7e\u9a76\u8f66\u8f86\u4e2d\uff0c\u4f7f\u7528\u6444\u50cf\u5934\u68c0\u6d4b\u524d\u65b9\u7684\u884c\u4eba\u3001\u8f66\u8f86\u7b49\u76ee\u6807\uff0c\u5e76\u5728\u56fe\u50cf\u4e0a\u753b\u5708\u6807\u8bb0\u8fd9\u4e9b\u76ee\u6807\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u533b\u5b66\u56fe\u50cf\u5206\u6790<\/h4>\n<\/p>\n<p><p>\u5728\u533b\u5b66\u56fe\u50cf\u5206\u6790\u4e2d\uff0c\u533b\u751f\u6216\u7814\u7a76\u4eba\u5458\u7ecf\u5e38\u9700\u8981\u5728\u56fe\u50cf\u4e0a\u6807\u8bb0\u611f\u5174\u8da3\u7684\u533a\u57df\uff08\u5982\u80bf\u7624\u3001\u75c5\u53d8\u7b49\uff09\u3002\u901a\u8fc7\u5728\u56fe\u50cf\u4e0a\u753b\u5708\uff0c\u53ef\u4ee5\u76f4\u89c2\u5730\u663e\u793a\u548c\u6807\u8bb0\u8fd9\u4e9b\u533a\u57df\uff0c\u4fbf\u4e8e\u540e\u7eed\u5206\u6790\u548c\u8bca\u65ad\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u4eba\u8138\u8bc6\u522b<\/h4>\n<\/p>\n<p><p>\u5728\u4eba\u8138\u8bc6\u522b\u4efb\u52a1\u4e2d\uff0c\u901a\u5e38\u9700\u8981\u5728\u68c0\u6d4b\u5230\u7684\u4eba\u8138\u5468\u56f4\u753b\u5708\uff0c\u4ee5\u6807\u8bc6\u4eba\u8138\u7684\u4f4d\u7f6e\u3002\u8fd9\u6837\u53ef\u4ee5\u65b9\u4fbf\u5730\u663e\u793a\u68c0\u6d4b\u7ed3\u679c\uff0c\u5e76\u8fdb\u884c\u8fdb\u4e00\u6b65\u7684\u5904\u7406\u548c\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h4>4\u3001\u56fe\u50cf\u7f16\u8f91<\/h4>\n<\/p>\n<p><p>\u5728\u56fe\u50cf\u7f16\u8f91\u8f6f\u4ef6\u4e2d\uff0c\u7528\u6237\u53ef\u4ee5\u4f7f\u7528\u753b\u5708\u5de5\u5177\u5728\u56fe\u50cf\u4e0a\u8fdb\u884c\u6807\u8bb0\u3001\u6ce8\u91ca\u7b49\u64cd\u4f5c\u3002\u8fd9\u4e9b\u5de5\u5177\u901a\u5e38\u63d0\u4f9b\u4e30\u5bcc\u7684\u7ed8\u56fe\u529f\u80fd\uff0c\u7528\u6237\u53ef\u4ee5\u6839\u636e\u9700\u8981\u9009\u62e9\u4e0d\u540c\u7684\u989c\u8272\u3001\u7ebf\u6761\u539a\u5ea6\u7b49\u53c2\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684\u5e93<\/h3>\n<\/p>\n<p><p>\u5728\u9009\u62e9\u5408\u9002\u7684\u5e93\u6765\u5728\u56fe\u50cf\u4e0a\u753b\u5708\u65f6\uff0c\u9700\u8981\u8003\u8651\u4ee5\u4e0b\u51e0\u4e2a\u56e0\u7d20\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u529f\u80fd\u9700\u6c42<\/h4>\n<\/p>\n<p><p>\u4e0d\u540c\u7684\u5e93\u5177\u6709\u4e0d\u540c\u7684\u529f\u80fd\u548c\u7279\u6027\u3002OpenCV\u529f\u80fd\u5f3a\u5927\uff0c\u9002\u7528\u4e8e\u590d\u6742\u7684\u56fe\u50cf\u5904\u7406\u548c\u8ba1\u7b97\u673a\u89c6\u89c9\u4efb\u52a1\uff1bPIL\u9002\u7528\u4e8e\u7b80\u5355\u7684\u56fe\u50cf\u5904\u7406\u64cd\u4f5c\uff1bMatplotlib\u9002\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\u548c\u7b80\u5355\u7684\u56fe\u50cf\u7ed8\u5236\u64cd\u4f5c\u3002\u6839\u636e\u5177\u4f53\u7684\u529f\u80fd\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5e93\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u6027\u80fd\u8981\u6c42<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u5bf9\u6027\u80fd\u8981\u6c42\u8f83\u9ad8\uff0cOpenCV\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\uff0c\u56e0\u4e3a\u5b83\u4f7f\u7528C++\u5b9e\u73b0\uff0c\u5177\u6709\u8f83\u9ad8\u7684\u6548\u7387\u3002\u5982\u679c\u5bf9\u6027\u80fd\u8981\u6c42\u4e0d\u9ad8\uff0c\u53ef\u4ee5\u9009\u62e9PIL\u6216Matplotlib\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u6613\u7528\u6027<\/h4>\n<\/p>\n<p><p>\u4e0d\u540c\u7684\u5e93\u5728\u6613\u7528\u6027\u65b9\u9762\u4e5f\u6709\u5dee\u5f02\u3002OpenCV\u5177\u6709\u4e30\u5bcc\u7684\u51fd\u6570\u548c\u6587\u6863\uff0c\u4f46\u4f7f\u7528\u8d77\u6765\u53ef\u80fd\u76f8\u5bf9\u590d\u6742\uff1bPIL\u548cMatplotlib\u7684\u4f7f\u7528\u8f83\u4e3a\u7b80\u5355\uff0c\u9002\u5408\u521d\u5b66\u8005\u548c\u7b80\u5355\u7684\u5e94\u7528\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p><strong>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u5e93\u5728\u56fe\u50cf\u4e0a\u753b\u5708\u3002\u5e38\u7528\u7684\u5e93\u6709OpenCV\u3001PIL\uff08Pillow\uff09\u548cMatplotlib\u3002OpenCV\u529f\u80fd\u5f3a\u5927\uff0c\u9002\u7528\u4e8e\u590d\u6742\u7684\u56fe\u50cf\u5904\u7406\u548c\u8ba1\u7b97\u673a\u89c6\u89c9\u4efb\u52a1\uff1bPIL\u9002\u7528\u4e8e\u7b80\u5355\u7684\u56fe\u50cf\u5904\u7406\u64cd\u4f5c\uff1bMatplotlib\u9002\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\u548c\u7b80\u5355\u7684\u56fe\u50cf\u7ed8\u5236\u64cd\u4f5c\u3002\u6839\u636e\u5177\u4f53\u7684\u529f\u80fd\u9700\u6c42\u3001\u6027\u80fd\u8981\u6c42\u548c\u6613\u7528\u6027\u9009\u62e9\u5408\u9002\u7684\u5e93\u3002<\/strong><\/p>\n<\/p>\n<p><p><strong>\u5728\u56fe\u50cf\u4e0a\u753b\u5708\u7684\u64cd\u4f5c\u5728\u8bb8\u591a\u56fe\u50cf\u5904\u7406\u548c\u8ba1\u7b97\u673a\u89c6\u89c9\u4efb\u52a1\u4e2d\u975e\u5e38\u5e38\u89c1\uff0c\u5982\u76ee\u6807\u68c0\u6d4b\u3001\u533b\u5b66\u56fe\u50cf\u5206\u6790\u3001\u4eba\u8138\u8bc6\u522b\u548c\u56fe\u50cf\u7f16\u8f91\u7b49\u3002\u901a\u8fc7\u5728\u56fe\u50cf\u4e0a\u753b\u5708\uff0c\u53ef\u4ee5\u76f4\u89c2\u5730\u663e\u793a\u548c\u6807\u8bb0\u611f\u5174\u8da3\u7684\u533a\u57df\uff0c\u4fbf\u4e8e\u540e\u7eed\u5206\u6790\u548c\u5904\u7406\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u5e0c\u671b\u901a\u8fc7\u672c\u7bc7\u6587\u7ae0\uff0c\u60a8\u80fd\u591f\u4e86\u89e3\u5982\u4f55\u4f7f\u7528Python\u5728\u56fe\u50cf\u4e0a\u753b\u5708\uff0c\u5e76\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5e93\u8fdb\u884c\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528OpenCV\u5e93\u7ed8\u5236\u5706\u5708\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u4f7f\u7528OpenCV\u5e93\u53ef\u4ee5\u8f7b\u677e\u5730\u5728\u56fe\u50cf\u4e0a\u7ed8\u5236\u5706\u5708\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u5b89\u88c5OpenCV\u5e93\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4<code>pip install opencv-python<\/code>\u6765\u5b8c\u6210\u3002\u63a5\u4e0b\u6765\uff0c\u4f7f\u7528<code>cv2.circle()<\/code>\u51fd\u6570\u6765\u5b9a\u4e49\u5706\u7684\u4e2d\u5fc3\u4f4d\u7f6e\u3001\u534a\u5f84\u548c\u989c\u8272\u3002\u4f8b\u5982\uff0c<code>cv2.circle(image, (center_x, center_y), radius, (color_b, color_g, color_r), thickness)<\/code>\uff0c\u5176\u4e2d<code>thickness<\/code>\u53c2\u6570\u53ef\u4ee5\u8bbe\u7f6e\u4e3a-1\u6765\u586b\u5145\u5706\u3002<\/p>\n<p><strong>\u9664\u4e86OpenCV\uff0c\u8fd8\u6709\u54ea\u4e9b\u5e93\u53ef\u4ee5\u5728\u56fe\u50cf\u4e0a\u7ed8\u5236\u5706\u5708\uff1f<\/strong><br \/>\u9664\u4e86OpenCV\uff0c\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u5e93\u5982Matplotlib\u548cPIL\uff08Pillow\uff09\u3002Matplotlib\u53ef\u4ee5\u901a\u8fc7\u7ed8\u5236\u6563\u70b9\u56fe\u6216\u4f7f\u7528<code>patches.Circle<\/code>\u6765\u5b9e\u73b0\u5706\u5708\u7684\u7ed8\u5236\u3002PIL\u5219\u53ef\u4ee5\u901a\u8fc7<code>ImageDraw<\/code>\u6a21\u5757\u7684<code>ellipse()<\/code>\u65b9\u6cd5\u6765\u7ed8\u5236\u5706\u5f62\u3002\u6bcf\u79cd\u5e93\u90fd\u6709\u5176\u7279\u70b9\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u9879\u76ee\u9700\u6c42\u9009\u62e9\u9002\u5408\u7684\u5de5\u5177\u3002<\/p>\n<p><strong>\u5728\u7ed8\u5236\u5706\u5708\u65f6\uff0c\u5982\u4f55\u8c03\u6574\u989c\u8272\u548c\u900f\u660e\u5ea6\uff1f<\/strong><br \/>\u5728OpenCV\u4e2d\uff0c\u989c\u8272\u901a\u8fc7BGR\u683c\u5f0f\u6307\u5b9a\uff0c\u4f8b\u5982\u7ea2\u8272\u4e3a(0, 0, 255)\u3002\u900f\u660e\u5ea6\u7684\u5904\u7406\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u56fe\u50cf\u7684alpha\u901a\u9053\u6216\u4f7f\u7528<code>cv2.addWeighted()<\/code>\u51fd\u6570\u6765\u53e0\u52a0\u5e26\u6709\u900f\u660e\u5ea6\u7684\u5706\u5708\u56fe\u50cf\u3002\u5bf9\u4e8eMatplotlib\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e<code>alpha<\/code>\u53c2\u6570\u6765\u8c03\u6574\u900f\u660e\u5ea6\uff0c\u800c\u5728PIL\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>Image.new()<\/code>\u521b\u5efa\u5e26\u6709\u900f\u660e\u80cc\u666f\u7684\u56fe\u50cf\u6765\u7ed8\u5236\u5e26\u900f\u660e\u5ea6\u7684\u5706\u5708\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u5e93\u5728\u56fe\u50cf\u4e0a\u753b\u5708\u3002\u5e38\u7528\u7684\u5e93\u6709OpenCV\u3001PIL\uff08Pillow\uff09\u548cMatplotl [&hellip;]","protected":false},"author":3,"featured_media":1172146,"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\/1172135"}],"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=1172135"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1172135\/revisions"}],"predecessor-version":[{"id":1172152,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1172135\/revisions\/1172152"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1172146"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1172135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1172135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1172135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}