{"id":43430,"date":"2025-06-12T15:28:13","date_gmt":"2025-06-12T07:28:13","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/43430.html"},"modified":"2025-06-12T15:28:13","modified_gmt":"2025-06-12T07:28:13","slug":"python-opencv%ef%bc%88%e5%9b%be%e5%83%8f%e5%a4%84%e7%90%86-%e8%be%b9%e7%95%8c%e5%a1%ab%e5%85%85%e3%80%81%e5%9b%be%e5%83%8f%e8%9e%8d%e5%90%88%e3%80%81%e5%9b%be%e5%83%8f%e9%98%88","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/43430.html","title":{"rendered":"Python----OpenCV\uff08\u56fe\u50cf\u5904\u7406\u2014\u2014\u8fb9\u754c\u586b\u5145\u3001\u56fe\u50cf\u878d\u5408\u3001\u56fe\u50cf\u9608\u503c\u3001\u6df1\u62f7\u8d1d\u4e0e\u6d45\u62f7\u8d1d\uff09"},"content":{"rendered":"<p>Python&#8212;-\u8ba1\u7b97\u673a\u89c6\u89c9\u5904\u7406&#xff08;Opencv&#xff1a;\u56fe\u50cf\u65cb\u8f6c&#xff1a;\u63d2\u503c\u65b9\u6cd5&#xff0c;\u8fb9\u7f18\u586b\u5145\u65b9\u6cd5&#xff09;<\/p>\n<p>Python&#8212;-\u8ba1\u7b97\u673a\u89c6\u89c9\u5904\u7406&#xff08;Opencv&#xff1a;\u4e8c\u503c\u5316&#xff0c;\u9608\u503c\u6cd5&#xff0c;\u53cd\u9608\u503c\u6cd5&#xff0c;\u622a\u65ad\u9608\u503c\u6cd5&#xff0c;OTSU\u9608\u503c\u6cd5&#xff09;<\/p>\n<h2>\u4e00\u3001\u8fb9\u754c\u586b\u5145<\/h2>\n<h3>1.1\u3001\u4ec0\u4e48\u662f\u8fb9\u754c\u586b\u5145<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8fb9\u754c\u586b\u5145\u662f\u4e00\u79cd\u5728\u56fe\u50cf\u8fb9\u7f18\u6dfb\u52a0\u989d\u5916\u50cf\u7d20\u7684\u64cd\u4f5c\u3002\u8fd9\u4e9b\u989d\u5916\u7684\u50cf\u7d20\u7528\u4e8e\u5904\u7406\u56fe\u50cf\u5377\u79ef\u3001\u5e73\u6ed1 \u6216\u5176\u4ed6\u6d89\u53ca\u8fb9\u754c\u7684\u64cd\u4f5c&#xff0c;\u4ee5\u907f\u514d\u8fb9\u7f18\u6548\u5e94\u3002\u4f8b\u5982&#xff0c;\u5728\u8fdb\u884c\u5377\u79ef\u64cd\u4f5c\u65f6&#xff0c;\u5982\u679c\u4e0d\u8fdb\u884c\u8fb9\u754c\u586b \u5145&#xff0c;\u56fe\u50cf\u8fb9\u7f18\u7684\u50cf\u7d20\u5c06\u4f1a\u7f3a\u5c11\u5468\u56f4\u7684\u50cf\u7d20\u4fe1\u606f&#xff0c;\u4ece\u800c\u5bfc\u81f4\u7ed3\u679c\u56fe\u50cf\u8fb9\u7f18\u6a21\u7cca\u6216\u5931\u771f\u3002<\/p>\n<h3>1.2\u3001\u8fb9\u754c\u586b\u5145\u65b9\u6cd5<\/h3>\n<p>\u539f\u56fe<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"250\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250612072807-684a81871181c.png\" width=\"166\" \/><\/p>\n<\/p>\n<p>BORDER_CONSTANT \u5e38\u6570\u586b\u5145<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u4f7f\u7528\u5e38\u6570\u586b\u5145&#xff0c;\u901a\u5e38\u662f\u9ed1\u8272&#xff08;\u503c\u4e3a0&#xff09;\u3002<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"250\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250612072807-684a818737568.png\" width=\"178\" \/><\/p>\n<p>BORDER_REPLICATE \u590d\u5236\u8fb9\u754c\u50cf\u7d20<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8fd9\u79cd\u65b9\u5f0f\u4f1a\u5c06\u56fe\u50cf\u7684\u8fb9\u754c\u50cf\u7d20\u590d\u5236\u5230\u56fe\u50cf\u7684\u8fb9\u754c\u5916\u90e8&#xff0c;\u4ea7\u751f\u7c7b\u4f3c\u8fb9\u7f18\u5ef6\u4f38\u7684\u6548\u679c\u3002<\/p>\n<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"250\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250612072807-684a8187ad977.png\" width=\"178\" \/><\/p>\n<p>BORDER_REFLECT \u53cd\u5c04\u8fb9\u754c\u50cf\u7d20<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8fd9\u79cd\u65b9\u5f0f\u5c06\u56fe\u50cf\u7684\u8fb9\u754c\u50cf\u7d20\u53cd\u5c04\u5230\u5916\u90e8&#xff0c;\u53cd\u5c04\u65f6\u4e0d\u5305\u62ec\u539f\u8fb9\u754c\u50cf\u7d20\u3002\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u8fb9\u754c\u7684\u50cf\u7d20 \u4f1a\u53cd\u8f6c&#xff08;\u955c\u50cf\u53cd\u5c04&#xff09;\u5230\u5916\u90e8&#xff0c;\u4f46\u539f\u672c\u7684\u8fb9\u754c\u50cf\u7d20\u4e0d\u518d\u91cd\u590d\u3002<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"250\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250612072808-684a81883b483.png\" width=\"178\" \/><\/p>\n<\/p>\n<p>BORDER_REFLECT_101\u53cd\u5c04\u8fb9\u754c\u50cf\u7d20<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8fd9\u79cd\u65b9\u5f0f\u7c7b\u4f3c\u4e8e BORDER_REFLECT &#xff0c;\u4f46\u662f\u5b83\u53cd\u5c04\u7684\u8303\u56f4\u4f1a\u6392\u9664\u539f\u56fe\u50cf\u7684\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u50cf\u7d20\u3002<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"250\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250612072808-684a8188d2e0e.png\" width=\"178\" \/><\/p>\n<p>BORDER_WRAP<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u73af\u7ed5\u586b\u5145\u65b9\u5f0f\u4f1a\u5c06\u56fe\u50cf\u7684\u8fb9\u754c\u50cf\u7d20\u201c\u73af\u7ed5\u201d\u5230\u53e6\u4e00\u4fa7\u3002\u5373&#xff0c;\u56fe\u50cf\u7684\u5de6\u8fb9\u4f1a\u88ab\u53f3\u8fb9\u7684\u50cf\u7d20\u586b\u5145&#xff0c; \u56fe\u50cf\u7684\u4e0a\u8fb9\u4f1a\u88ab\u4e0b\u8fb9\u7684\u50cf\u7d20\u586b\u5145&#xff0c;\u50cf\u662f\u5728\u56fe\u50cf\u7684\u56db\u4e2a\u8fb9\u7f18\u4e4b\u95f4\u201c\u8fde\u63a5\u201d\u8d77\u6765\u3002<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"250\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250612072809-684a81897a496.png\" width=\"178\" \/><\/p>\n<p>import cv2<\/p>\n<p># \u8bfb\u53d6\u56fe\u50cf<br \/>\n# cv2.imread() \u51fd\u6570\u7528\u4e8e\u4ece\u6307\u5b9a\u8def\u5f84\u52a0\u8f7d\u4e00\u5f20\u56fe\u7247\u5230\u5185\u5b58\u4e2d\u3002<br \/>\n# &#039;.\/images\/nezha.png&#039; \u662f\u56fe\u7247\u7684\u6587\u4ef6\u8def\u5f84\u3002<br \/>\nimg1 &#061; cv2.imread(&#039;.\/images\/nezha.png&#039;)<\/p>\n<p># \u5b9a\u4e49\u8fb9\u754c\u7684\u539a\u5ea6<br \/>\n# t, b, l, r \u5206\u522b\u4ee3\u8868\u56fe\u50cf\u7684 \u4e0a (top)\u3001\u4e0b (bottom)\u3001\u5de6 (left)\u3001\u53f3 (right) \u56db\u4e2a\u65b9\u5411\u8981\u6dfb\u52a0\u7684\u8fb9\u754c\u50cf\u7d20\u6570\u91cf\u3002<br \/>\n# \u8fd9\u91cc\u56db\u4e2a\u65b9\u5411\u90fd\u8bbe\u7f6e\u4e3a 50 \u50cf\u7d20\u3002<br \/>\nt, b, l, r &#061; (50, 50, 50, 50)<\/p>\n<p># \u4f7f\u7528 cv2.copyMakeBorder \u51fd\u6570\u6dfb\u52a0\u8fb9\u754c<br \/>\n# img1: \u539f\u59cb\u56fe\u50cf\u3002<br \/>\n# t, b, l, r: \u5b9a\u4e49\u7684\u8fb9\u754c\u539a\u5ea6\u3002<br \/>\n# cv2.BORDER_WRAP: \u8fb9\u754c\u586b\u5145\u6a21\u5f0f\u3002<br \/>\n# BORDER_WRAP \u6a21\u5f0f\u901a\u8fc7\u91cd\u590d\u56fe\u50cf\u672c\u8eab\u6765\u586b\u5145\u8fb9\u754c\u3002\u5b83\u4f1a\u5c06\u56fe\u50cf\u7684\u53e6\u4e00\u4fa7\u50cf\u7d20\u201c\u5305\u88f9\u201d\u5230\u8fb9\u754c\u4e0a&#xff0c;<br \/>\n# \u5c31\u50cf\u56fe\u50cf\u5185\u5bb9\u662f\u5468\u671f\u6027\u91cd\u590d\u7684\u4e00\u6837\u3002<br \/>\nimg2 &#061; cv2.copyMakeBorder(img1, t, b, l, r, cv2.BORDER_WRAP)<\/p>\n<p># \u663e\u793a\u6dfb\u52a0\u8fb9\u754c\u540e\u7684\u56fe\u50cf<br \/>\n# cv2.imshow() \u51fd\u6570\u7528\u4e8e\u5728\u7a97\u53e3\u4e2d\u663e\u793a\u56fe\u50cf\u3002<br \/>\n# &#039;images2&#039; \u662f\u663e\u793a\u7a97\u53e3\u7684\u540d\u79f0\u3002<br \/>\ncv2.imshow(&#039;images2&#039;, img2)<\/p>\n<p># \u7b49\u5f85\u6309\u952e<br \/>\n# cv2.waitKey(0) \u8868\u793a\u7a0b\u5e8f\u5c06\u65e0\u9650\u671f\u7b49\u5f85\u7528\u6237\u7684\u6309\u952e\u8f93\u5165\u3002<br \/>\n# \u53ea\u6709\u5f53\u7528\u6237\u6309\u4e0b\u4efb\u610f\u952e\u65f6&#xff0c;\u7a0b\u5e8f\u624d\u4f1a\u7ee7\u7eed\u6267\u884c\u540e\u7eed\u4ee3\u7801&#xff08;\u4f8b\u5982\u5173\u95ed\u7a97\u53e3&#xff09;\u3002<br \/>\ncv2.waitKey(0)<\/p>\n<p># \u9500\u6bc1\u6240\u6709OpenCV\u521b\u5efa\u7684\u7a97\u53e3<br \/>\n# cv2.destroyAllWindows() \u51fd\u6570\u7528\u4e8e\u5173\u95ed\u6240\u6709\u7531OpenCV\u521b\u5efa\u7684\u7a97\u53e3\u3002<br \/>\ncv2.destroyAllWindows() <\/p>\n<h3>1.3\u3001copyMakeBorder\u51fd\u6570<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0cv2.copymakeBorder0 \u662f OpenCV \u4e2d\u7528\u6765\u7ed9\u56fe\u50cf\u6dfb\u52a0\u8fb9\u754c\u7684\u51fd\u6570&#xff0c;\u5e38\u7528\u4e8e\u5bf9\u56fe\u50cf\u8fdb\u884c\u6269\u5c55\u5904\u7406\u652f\u6301\u4e0d\u540c\u7684\u8fb9\u754c\u586b\u5145\u65b9\u5f0f\u3002\u4f60\u53ef\u4ee5\u7528\u5b83\u6765\u5728\u56fe\u50cf\u5468\u56f4\u6dfb\u52a0\u7a7a\u767d(\u5e38\u7528\u4e8e\u5377\u79ef\u64cd\u4f5c\u65f6)\u6216\u7279\u5b9a\u7684\u50cf\u7d20\u586b\u5145\u3002<\/p>\n<p>cv2.copyMakeBorder(src, top, bottom, left, right, borderType, value&#061;None) <\/p>\n<table>\n<tr>\u53c2\u6570\u540d\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>src<\/td>\n<td>\u8f93\u5165\u56fe\u50cf&#xff0c;\u53ef\u4ee5\u662f\u7070\u5ea6\u56fe\u50cf\u6216\u5f69\u8272\u56fe\u50cf&#xff08;numpy \u6570\u7ec4\u683c\u5f0f&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>top<\/td>\n<td>\u4e0a\u8fb9\u754c\u7684\u5bbd\u5ea6&#xff08;\u50cf\u7d20\u6570&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>bottom<\/td>\n<td>\u4e0b\u8fb9\u754c\u7684\u5bbd\u5ea6&#xff08;\u50cf\u7d20\u6570&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>left<\/td>\n<td>\u5de6\u8fb9\u7684\u5bbd\u5ea6&#xff08;\u50cf\u7d20\u6570&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>right<\/td>\n<td>\u53f3\u8fb9\u7684\u5bbd\u5ea6&#xff08;\u50cf\u7d20\u6570&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>borderType<\/td>\n<td>\u586b\u5145\u7c7b\u578b&#xff0c;\u51b3\u5b9a\u4e86\u8fb9\u754c\u5982\u4f55\u586b\u5145\u3002\u5e38\u7528\u9009\u9879\u5305\u62ec&#xff1a;<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>&#8211;\u00a0cv2.BORDER_CONSTANT&#xff1a;\u5e38\u6570\u586b\u5145\u3002<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>&#8211;\u00a0cv2.BORDER_REPLICATE&#xff1a;\u590d\u5236\u8fb9\u754c\u50cf\u7d20\u586b\u5145\u3002<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>&#8211;\u00a0cv2.BORDER_REFLECT&#xff1a;\u53cd\u5c04\u8fb9\u754c\u50cf\u7d20&#xff08;\u53cd\u5c04\u6a21\u5f0f&#xff0c;\u4e0d\u5305\u62ec\u539f\u8fb9\u754c\u50cf\u7d20&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>&#8211;\u00a0cv2.BORDER_REFLECT_101&#xff1a;\u7c7b\u4f3c\u00a0BORDER_REFLECT&#xff0c;\u4f46\u5bf9\u79f0\u53cd\u5c04\u4f1a\u5ffd\u7565\u7b2c\u4e00\u4e2a\u548c\u6700\u540e\u4e00\u4e2a\u50cf\u7d20\u3002<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>&#8211;\u00a0cv2.BORDER_WRAP&#xff1a;\u73af\u7ed5\u586b\u5145\u3002<\/td>\n<\/tr>\n<tr>\n<td>value<\/td>\n<td>\u5f53\u00a0borderType&#061;cv2.BORDER_CONSTANT\u00a0\u65f6&#xff0c;\u6307\u5b9a\u586b\u5145\u7684\u989c\u8272\u3002\u9ed8\u8ba4\u4e3a 0&#xff08;\u9ed1\u8272&#xff09;\u3002\u5982\u679c\u662f\u5f69\u8272\u56fe\u50cf&#xff0c;\u53ef\u4ee5\u8bbe\u7f6e\u4e3a\u4e09\u5143\u7ec4&#xff08;\u5982\u00a0[0, 0, 255]\u00a0\u8868\u793a\u7ea2\u8272\u586b\u5145&#xff09;\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u4e8c\u3001\u56fe\u50cf\u878d\u5408<\/h2>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u56fe\u50cf\u878d\u5408\u662f\u5c06\u591a\u5f20\u56fe\u50cf\u5408\u6210\u4e00\u5f20\u56fe\u50cf\u7684\u8fc7\u7a0b&#xff0c;\u4ee5\u4fbf\u83b7\u53d6\u66f4\u4e30\u5bcc\u7684\u4fe1\u606f\u6216\u66f4\u9ad8\u7684\u56fe\u50cf\u8d28\u91cf\u3002\u5728 \u4e0d\u540c\u7684\u5e94\u7528\u4e2d&#xff0c;\u56fe\u50cf\u878d\u5408\u7684\u76ee\u7684\u53ef\u80fd\u4e0d\u540c&#xff0c;\u5982\u589e\u5f3a\u56fe\u50cf\u7ec6\u8282\u3001\u51cf\u5c0f\u566a\u58f0\u3001\u63d0\u9ad8\u56fe\u50cf\u5206\u8fa8\u7387 \u7b49\u3002<\/p>\n<p>\u5e38\u89c1\u7684\u56fe\u50cf\u878d\u5408\u65b9\u6cd5&#xff1a;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u50cf\u7d20\u7ea7\u878d\u5408&#xff1a;\u76f4\u63a5\u5bf9\u4e24\u4e2a\u6216\u591a\u4e2a\u56fe\u50cf\u7684\u50cf\u7d20\u503c\u8fdb\u884c\u52a0\u6743\u5e73\u5747\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u591a\u5206\u8fa8\u7387\u878d\u5408&#xff1a;\u4f8b\u5982&#xff0c;\u4f7f\u7528\u5c0f\u6ce2\u53d8\u6362&#xff08;Wavelet Transform&#xff09;\u5c06\u56fe\u50cf\u5728\u4e0d\u540c\u5206\u8fa8\u7387\u4e0b\u8fdb\u884c\u878d\u5408&#xff0c;\u80fd\u4fdd\u7559\u66f4\u591a\u7684\u56fe\u50cf\u7ec6\u8282\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u7279\u5f81\u7ea7\u878d\u5408&#xff1a;\u63d0\u53d6\u56fe\u50cf\u7684\u7279\u5f81&#xff08;\u5982\u8fb9\u7f18\u3001\u7eb9\u7406\u7b49&#xff09;\u540e\u8fdb\u884c\u878d\u5408&#xff0c;\u800c\u975e\u76f4\u63a5\u5904\u7406\u50cf\u7d20\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"462\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250612072810-684a818a1af87.png\" width=\"1173\" \/><\/p>\n<p>import cv2<\/p>\n<p># \u8bfb\u53d6\u7b2c\u4e00\u5f20\u56fe\u50cf<br \/>\n# cv2.imread() \u51fd\u6570\u7528\u4e8e\u4ece\u6307\u5b9a\u8def\u5f84\u52a0\u8f7d\u4e00\u5f20\u56fe\u7247\u5230\u5185\u5b58\u4e2d\u3002<br \/>\n# &#039;apple.png&#039; \u662f\u7b2c\u4e00\u5f20\u56fe\u7247\u7684\u8def\u5f84\u3002<br \/>\nimg1 &#061; cv2.imread(&#039;.\/images\/apple.png&#039;)<\/p>\n<p># \u8bfb\u53d6\u7b2c\u4e8c\u5f20\u56fe\u50cf<br \/>\n# &#039;parrot.png&#039; \u662f\u7b2c\u4e8c\u5f20\u56fe\u7247\u7684\u8def\u5f84\u3002<br \/>\nimg2 &#061; cv2.imread(&#039;.\/images\/parrot.png&#039;)<\/p>\n<p># \u6253\u5370\u7b2c\u4e00\u5f20\u56fe\u50cf\u7684\u5c3a\u5bf8&#xff08;\u9ad8\u5ea6\u3001\u5bbd\u5ea6\u3001\u901a\u9053\u6570&#xff09;<br \/>\n# img.shape \u8fd4\u56de\u4e00\u4e2a\u5143\u7ec4&#xff0c;\u4f8b\u5982 (height, width, channels)\u3002<br \/>\nprint(img1.shape)<\/p>\n<p># \u6253\u5370\u7b2c\u4e8c\u5f20\u56fe\u50cf\u7684\u5c3a\u5bf8<br \/>\nprint(img2.shape)<\/p>\n<p># \u8c03\u6574\u7b2c\u4e00\u5f20\u56fe\u50cf\u7684\u5927\u5c0f<br \/>\n# cv2.resize() \u51fd\u6570\u7528\u4e8e\u6539\u53d8\u56fe\u50cf\u7684\u5c3a\u5bf8\u3002<br \/>\n# (261, 272) \u662f\u76ee\u6807\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u7684\u5143\u7ec4 (width, height)\u3002<br \/>\n# \u56fe\u50cf\u878d\u5408\u8981\u6c42\u53c2\u4e0e\u878d\u5408\u7684\u56fe\u50cf\u5c3a\u5bf8\u5fc5\u987b\u76f8\u540c&#xff0c;\u56e0\u6b64\u8fd9\u91cc\u5c06\u4e24\u5f20\u56fe\u90fd\u8c03\u6574\u4e3a\u76f8\u540c\u5927\u5c0f\u3002<br \/>\nimg1 &#061; cv2.resize(img1, (261, 272))<\/p>\n<p># \u8c03\u6574\u7b2c\u4e8c\u5f20\u56fe\u50cf\u7684\u5927\u5c0f<br \/>\nimg2 &#061; cv2.resize(img2, (261, 272))<\/p>\n<p># \u6267\u884c\u56fe\u50cf\u52a0\u6743\u878d\u5408<br \/>\n# cv2.addWeighted() \u51fd\u6570\u7528\u4e8e\u5b9e\u73b0\u4e24\u5f20\u56fe\u50cf\u7684\u7ebf\u6027\u6df7\u5408&#xff08;\u4e5f\u79f0\u4e3a\u56fe\u50cf\u878d\u5408\u6216\u900f\u660e\u5ea6\u6df7\u5408&#xff09;\u3002<br \/>\n# \u516c\u5f0f\u4e3a&#xff1a;dst &#061; \u03b1 * src1 &#043; \u03b2 * src2 &#043; \u03b3<br \/>\n# img1: \u7b2c\u4e00\u5f20\u8f93\u5165\u56fe\u50cf\u3002<br \/>\n# 0.5: \u7b2c\u4e00\u5f20\u56fe\u50cf\u7684\u6743\u91cd&#xff08;\u03b1&#xff09;\u3002<br \/>\n# img2: \u7b2c\u4e8c\u5f20\u8f93\u5165\u56fe\u50cf\u3002<br \/>\n# 0.5: \u7b2c\u4e8c\u5f20\u56fe\u50cf\u7684\u6743\u91cd&#xff08;\u03b2&#xff09;\u3002<br \/>\n# 0: \u4f3d\u9a6c\u503c&#xff08;\u03b3&#xff09;&#xff0c;\u4e00\u4e2a\u52a0\u5230\u7ed3\u679c\u4e0a\u7684\u6807\u91cf\u3002\u8fd9\u91cc\u8bbe\u7f6e\u4e3a0&#xff0c;\u8868\u793a\u4e0d\u989d\u5916\u589e\u52a0\u4eae\u5ea6\u3002<br \/>\n# \u7531\u4e8e\u4e24\u5f20\u56fe\u50cf\u7684\u6743\u91cd\u90fd\u662f0.5&#xff0c;\u8fd9\u610f\u5473\u7740\u5b83\u4eec\u5c06\u4ee550%\u7684\u900f\u660e\u5ea6\u76f8\u4e92\u53e0\u52a0&#xff0c;\u5f62\u6210\u4e00\u4e2a\u534a\u900f\u660e\u7684\u6548\u679c\u3002<br \/>\nimg3 &#061; cv2.addWeighted(img1, 0.5, img2, 0.5, 0)<\/p>\n<p># \u663e\u793a\u7b2c\u4e00\u5f20\u539f\u59cb\u56fe\u50cf&#xff08;\u8c03\u6574\u5927\u5c0f\u540e&#xff09;<br \/>\n# &#039;images1&#039; \u662f\u7a97\u53e3\u7684\u540d\u79f0\u3002<br \/>\ncv2.imshow(&#039;images1&#039;, img1)<\/p>\n<p># \u663e\u793a\u7b2c\u4e8c\u5f20\u539f\u59cb\u56fe\u50cf&#xff08;\u8c03\u6574\u5927\u5c0f\u540e&#xff09;<br \/>\n# &#039;images2&#039; \u662f\u7a97\u53e3\u7684\u540d\u79f0\u3002<br \/>\ncv2.imshow(&#039;images2&#039;, img2)<\/p>\n<p># \u663e\u793a\u878d\u5408\u540e\u7684\u56fe\u50cf<br \/>\n# &#039;images3&#039; \u662f\u7a97\u53e3\u7684\u540d\u79f0\u3002<br \/>\ncv2.imshow(&#039;images3&#039;, img3)<\/p>\n<p># \u7b49\u5f85\u6309\u952e<br \/>\n# cv2.waitKey(0) \u8868\u793a\u7a0b\u5e8f\u5c06\u65e0\u9650\u671f\u7b49\u5f85\u7528\u6237\u7684\u6309\u952e\u8f93\u5165\u3002<br \/>\n# \u53ea\u6709\u5f53\u7528\u6237\u6309\u4e0b\u4efb\u610f\u952e\u65f6&#xff0c;\u7a0b\u5e8f\u624d\u4f1a\u7ee7\u7eed\u6267\u884c\u540e\u7eed\u4ee3\u7801&#xff08;\u4f8b\u5982\u5173\u95ed\u7a97\u53e3&#xff09;\u3002<br \/>\ncv2.waitKey(0)<\/p>\n<p># \u9500\u6bc1\u6240\u6709OpenCV\u521b\u5efa\u7684\u7a97\u53e3<br \/>\n# cv2.destroyAllWindows() \u51fd\u6570\u7528\u4e8e\u5173\u95ed\u6240\u6709\u7531OpenCV\u521b\u5efa\u7684\u7a97\u53e3\u3002<br \/>\ncv2.destroyAllWindows() <\/p>\n<p>addWeighted\u51fd\u6570<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0addweighted \u662f OpenCV \u4e2d\u7528\u4e8e\u56fe\u50cf\u52a0\u6743\u878d\u5408\u7684\u4e00\u4e2a\u51fd\u6570&#xff0c;\u5e7f\u6cdb\u7528\u4e8e\u50cf\u7d20\u7ea7\u56fe\u50cf\u878d\u5408\u3002\u5b83\u901a\u8fc7\u5bf9\u4e24\u5f20\u56fe\u50cf\u8fdb\u884c\u52a0\u6743\u6c42\u548c&#xff0c;\u4ea7\u751f\u4e00\u5f20\u65b0\u7684\u56fe\u50cf\u3002\u8fd9\u5bf9\u4e8e\u5b9e\u73b0\u56fe\u50cf\u7684\u878d\u5408\u3001\u8fc7\u6e21\u6548\u679c\u3001\u6216\u8005\u56fe\u50cf\u589e\u5f3a\u7b49\u4efb\u52a1\u975e\u5e38\u6709\u7528\u3002<\/p>\n<p>cv2.addWeighted(src1, alpha, src2, beta, gamma) <\/p>\n<table>\n<tr>\u53c2\u6570\u540d\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>src1<\/td>\n<td>\u7b2c\u4e00\u5f20\u8f93\u5165\u56fe\u50cf\u3002<\/td>\n<\/tr>\n<tr>\n<td>alpha<\/td>\n<td>\u7b2c\u4e00\u5f20\u56fe\u50cf\u7684\u6743\u91cd&#xff0c;\u63a7\u5236\u7b2c\u4e00\u5f20\u56fe\u50cf\u5bf9\u6700\u7ec8\u878d\u5408\u56fe\u50cf\u7684\u8d21\u732e\u5ea6\u3002<\/td>\n<\/tr>\n<tr>\n<td>src2<\/td>\n<td>\u7b2c\u4e8c\u5f20\u8f93\u5165\u56fe\u50cf\u3002<\/td>\n<\/tr>\n<tr>\n<td>beta<\/td>\n<td>\u7b2c\u4e8c\u5f20\u56fe\u50cf\u7684\u6743\u91cd&#xff0c;\u63a7\u5236\u7b2c\u4e8c\u5f20\u56fe\u50cf\u5bf9\u6700\u7ec8\u878d\u5408\u56fe\u50cf\u7684\u8d21\u732e\u5ea6\u3002<\/td>\n<\/tr>\n<tr>\n<td>gamma<\/td>\n<td>\u53ef\u9009\u7684\u504f\u79fb\u91cf&#xff0c;\u901a\u5e38\u7528\u4e8e\u56fe\u50cf\u4eae\u5ea6\u7684\u8c03\u6574&#xff08;\u4f8b\u5982\u5bf9\u878d\u5408\u56fe\u50cf\u8fdb\u884c\u4eae\u5ea6\u589e\u52a0\u6216\u51cf\u5c11&#xff09;\u3002\u9ed8\u8ba4\u503c\u4e3a 0\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u4e09\u3001\u56fe\u50cf\u9608\u503c<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"547\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250612072810-684a818a87aed.png\" width=\"1102\" \/><\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5728OpenCV\u4e2d&#xff0c;\u56fe\u50cf\u9608\u503c\u64cd\u4f5c\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u56fe\u50cf\u5904\u7406\u6280\u672f&#xff0c;\u53ef\u4ee5\u5c06\u56fe\u50cf\u7684\u50cf\u7d20\u503c\u6839\u636e\u8bbe\u5b9a\u7684 \u9608\u503c\u8fdb\u884c\u5206\u7c7b&#xff0c;\u901a\u5e38\u662f\u5c06\u56fe\u50cf\u5206\u4e3a\u524d\u666f\u548c\u80cc\u666f\u3002<\/p>\n<p>ret, dst &#061; cv2.threshold(src, thresh, maxval, type) <\/p>\n<table>\n<tr>\u53c2\u6570\u540d\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>ret<\/td>\n<td>True\u00a0\u6216\u00a0False&#xff0c;\u8868\u793a\u662f\u5426\u6210\u529f\u8bfb\u53d6\u56fe\u7247\u3002<\/td>\n<\/tr>\n<tr>\n<td>dst<\/td>\n<td>\u8f93\u51fa\u7684\u4e8c\u503c\u5316\u56fe\u50cf\u3002<\/td>\n<\/tr>\n<tr>\n<td>src<\/td>\n<td>\u8f93\u5165\u56fe\u50cf&#xff08;\u4ec5\u652f\u6301\u5355\u901a\u9053&#xff0c;\u901a\u5e38\u4e3a\u7070\u5ea6\u56fe&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>thresh<\/td>\n<td>\u9608\u503c&#xff08;0-255 \u4e4b\u95f4\u7684\u503c&#xff0c;\u5982 127&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>maxval<\/td>\n<td>\u5f53\u50cf\u7d20\u503c\u8d85\u8fc7&#xff08;\u6216\u4f4e\u4e8e&#xff09;\u9608\u503c\u65f6\u8d4b\u4e88\u7684\u503c&#xff08;\u5177\u4f53\u884c\u4e3a\u7531\u00a0type\u00a0\u51b3\u5b9a&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>type<\/td>\n<td>\u4e8c\u503c\u5316\u64cd\u4f5c\u7c7b\u578b&#xff0c;\u5171 5 \u79cd&#xff08;\u89c1\u4e0b\u65b9\u8be6\u7ec6\u5bf9\u6bd4&#xff09;\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table>\n<tr>\u9608\u503c\u7c7b\u578b&#xff08;type&#xff09;\u5927\u4e8e\u9608\u503c\u50cf\u7d20\u7684\u5904\u7406\u5c0f\u4e8e\u6216\u7b49\u4e8e\u9608\u503c\u50cf\u7d20\u7684\u5904\u7406\u7ed3\u679c\u56fe\u50cf\u63cf\u8ff0<\/tr>\n<tbody>\n<tr>\n<td>cv2.THRESH_BINARY<\/td>\n<td>\u8bbe\u4e3a\u00a0maxval&#xff08;\u5982 255&#xff09;<\/td>\n<td>\u8bbe\u4e3a 0<\/td>\n<td>\u4eae\u533a\u767d\u8272&#xff0c;\u6697\u533a\u9ed1\u8272<\/td>\n<\/tr>\n<tr>\n<td>cv2.THRESH_BINARY_INV<\/td>\n<td>\u8bbe\u4e3a 0<\/td>\n<td>\u8bbe\u4e3a\u00a0maxval&#xff08;\u5982 255&#xff09;<\/td>\n<td>\u4eae\u533a\u9ed1\u8272&#xff0c;\u6697\u533a\u767d\u8272<\/td>\n<\/tr>\n<tr>\n<td>cv2.THRESH_TRUNC<\/td>\n<td>\u622a\u65ad\u4e3a\u00a0thresh\u00a0\u503c<\/td>\n<td>\u4fdd\u6301\u539f\u503c<\/td>\n<td>\u4eae\u533a\u88ab\u622a\u65ad\u81f3\u9608\u503c&#xff0c;\u6697\u533a\u4e0d\u53d8<\/td>\n<\/tr>\n<tr>\n<td>cv2.THRESH_TOZERO<\/td>\n<td>\u4fdd\u6301\u539f\u503c<\/td>\n<td>\u8bbe\u4e3a 0<\/td>\n<td>\u4eae\u533a\u4e0d\u53d8&#xff0c;\u6697\u533a\u9ed1\u8272<\/td>\n<\/tr>\n<tr>\n<td>cv2.THRESH_TOZERO_INV<\/td>\n<td>\u8bbe\u4e3a 0<\/td>\n<td>\u4fdd\u6301\u539f\u503c<\/td>\n<td>\u4eae\u533a\u9ed1\u8272&#xff0c;\u6697\u533a\u4e0d\u53d8<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>import cv2<br \/>\nimport numpy as np<br \/>\nimport matplotlib.pyplot as plt<br \/>\n# \u8bfb\u53d6\u56fe\u7247<br \/>\nimg &#061; cv2.imread(&#034;..\/images\/ROI.png&#034;)<\/p>\n<p># \u8f6c\u6362\u4e3a\u7070\u5ea6\u56fe<br \/>\ngray_img &#061; cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)<\/p>\n<p>ret,thresh1 &#061; cv2.threshold(gray_img,127,255,cv2.THRESH_BINARY )<br \/>\nret,thresh2 &#061; cv2.threshold(gray_img,127,255,cv2.THRESH_BINARY_INV  )<br \/>\nret,thresh3 &#061; cv2.threshold(gray_img,127,255,cv2.THRESH_TRUNC  )<br \/>\nret,thresh4 &#061; cv2.threshold(gray_img,127,255,cv2.THRESH_TOZERO  )<br \/>\nret,thresh5 &#061; cv2.threshold(gray_img,127,255,cv2.THRESH_TOZERO_INV  )<\/p>\n<p>titles &#061; [&#034;Original Image&#034;,&#034;BINARY&#034;,&#034;BINARY_INV&#034;,&#034;TRUNC&#034;,&#034;TOZERO&#034;,&#034;TOZERO_INV&#034;]<br \/>\nimages &#061; [img, thresh1, thresh2, thresh3, thresh4, thresh5]<br \/>\n# \u904d\u5386\u57286\u5f20\u56fe\u7247\u4e0a matplotilb<br \/>\nfor i in range(6):<br \/>\n    plt.subplot(2,3,i&#043;1),plt.imshow(images[i],&#039;gray&#039;)<br \/>\n    plt.title(titles[i])<br \/>\n    plt.xticks([]),plt.yticks([])<\/p>\n<p>plt.show()<\/p>\n<p>cv2.waitKey(5000)<br \/>\ncv2.destroyAllWindows() <\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"411\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250612072810-684a818adbdb1.png\" width=\"489\" \/><\/p>\n<h2>\u56db\u3001\u7ed3\u6784\u4f53Mat<\/h2>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"382\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250612072810-684a818aef14c.png\" width=\"582\" \/><\/p>\n<h3>4.1\u3001Mat \u7684\u57fa\u672c\u6982\u5ff5<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Mat \u662f OpenCV \u4e2d\u7528\u4e8e\u5b58\u50a8\u56fe\u50cf\u6570\u636e\u548c\u77e9\u9635\u6570\u636e\u7684\u4e3b\u8981\u6570\u636e\u7ed3\u6784\u3002\u5b83\u4ee3\u8868\u7740\u4e00\u4e2a n \u7ef4\u7684\u5bc6 \u96c6\u6570\u503c\u578b\u6570\u7ec4&#xff0c;\u88ab\u8bbe\u8ba1\u7528\u6765\u5b58\u50a8\u5b9e\u6570\u6216\u590d\u6570\u5143\u7d20&#xff0c;\u5e76\u4e14\u53ef\u4ee5\u5b58\u50a8\u5355\u901a\u9053\u6216\u591a\u901a\u9053\u7684\u6570\u636e\u3002 \u4e0e\u4f20\u7edf\u7684 IplImage \u7ed3\u6784\u4f53\u76f8\u6bd4&#xff0c;Mat \u5177\u6709\u81ea\u52a8\u5185\u5b58\u7ba1\u7406\u7684\u4f18\u52bf&#xff0c;\u80fd\u6709\u6548\u907f\u514d\u5185\u5b58\u6cc4\u6f0f&#xff0c;\u4f7f \u7528\u8d77\u6765\u66f4\u52a0\u65b9\u4fbf\u548c\u5b89\u5168\u3002<\/p>\n<h3>4.2\u3001Mat \u7684\u7ec4\u6210\u90e8\u5206<\/h3>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0OpenCV \u7684 Mat \u6570\u636e\u7ed3\u6784\u53ef\u4ee5\u5206\u4e3a\u4ee5\u4e0b\u51e0\u4e2a\u4e3b\u8981\u90e8\u5206&#xff1a;<\/p>\n<table>\n<tr>\u5b57\u6bb5\u540d\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>dims<\/td>\n<td>\u56fe\u50cf\u7684\u7ef4\u5ea6&#xff08;\u5982 2D \u56fe\u50cf\u7684\u00a0dims&#061;2&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>rows<\/td>\n<td>\u56fe\u50cf\u7684\u884c\u6570&#xff08;\u9ad8\u5ea6&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>cols<\/td>\n<td>\u56fe\u50cf\u7684\u5217\u6570&#xff08;\u5bbd\u5ea6&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>depth<\/td>\n<td>\u50cf\u7d20\u7684\u4f4d\u6df1&#xff08;\u5b58\u50a8\u683c\u5f0f&#xff09;&#xff0c;\u4f8b\u5982\u00a0CV_8U&#xff08;8\u4f4d\u65e0\u7b26\u53f7\u6574\u6570&#xff09;\u3001CV_32F&#xff08;32\u4f4d\u6d6e\u70b9\u6570&#xff09;\u7b49\u3002<\/td>\n<\/tr>\n<tr>\n<td>channels<\/td>\n<td>\u56fe\u50cf\u7684\u901a\u9053\u6570&#xff08;\u5982 RGB\/BGR \u56fe\u50cf\u4e3a 3&#xff0c;\u7070\u5ea6\u56fe\u4e3a 1&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>size<\/td>\n<td>\u77e9\u9635\u7684\u5927\u5c0f&#xff08;\u683c\u5f0f\u4e3a\u00a0(rows, cols)&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>type<\/td>\n<td>\u6570\u636e\u7c7b\u578b\u4e0e\u901a\u9053\u7684\u7ec4\u5408&#xff08;\u5982\u00a0CV_8UC3\u00a0\u8868\u793a 8\u4f4d\u65e0\u7b26\u53f7\u6574\u6570 &#043; 3\u901a\u9053&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>data<\/td>\n<td>\u5b9e\u9645\u5b58\u50a8\u7684\u50cf\u7d20\u6570\u636e&#xff08;\u901a\u5e38\u662f\u5185\u5b58\u6307\u9488\u6216\u6570\u7ec4&#xff09;\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>import cv2<br \/>\nimg &#061; cv2.imread(&#034;..\/images\/ROI.png&#034;)<\/p>\n<p>print(&#034;rows&#034;,img.shape[0]) #\u9ad8\u5ea6rows 578<br \/>\nprint(&#034;cols&#034;,img.shape[1]) #\u5bbd\u5ea6cols 398<br \/>\nprint(&#034;channels&#034;,img.shape[2]) #\u901a\u9053\u6570channels 3<br \/>\nprint(&#034;cols&#034;,img.dtype) #\u6570\u636e\u7c7b\u578bcols uint8 <\/p>\n<h2>\u4e94\u3001\u6df1\u62f7\u8d1d\u4e0e\u6d45\u62f7\u8d1d<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"493\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250612072811-684a818b0be2e.png\" width=\"994\" \/><\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5728 Python \u4e2d&#xff0c;\u6df1\u62f7\u8d1d&#xff08;Deep Copy&#xff09;\u548c\u6d45\u62f7\u8d1d&#xff08;Shallow Copy&#xff09;\u662f\u4e24\u79cd\u4e0d\u540c\u7684\u5bf9\u8c61\u590d\u5236 \u65b9\u5f0f&#xff0c;\u4e3b\u8981\u533a\u522b\u5728\u4e8e\u662f\u5426\u590d\u5236\u4e86\u5bf9\u8c61\u4e2d\u7684\u5d4c\u5957\u5bf9\u8c61\u3002<\/p>\n<table>\n<tbody>\n<tr>\n<td>\u6df1\u62f7\u8d1d<\/td>\n<td>\u6d45\u62f7\u8d1d<\/td>\n<\/tr>\n<tr>\n<td>img.copy()<\/td>\n<td>\u6b63\u5e38\u590d\u5236<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>import cv2<br \/>\n# \u52a0\u8f7d\u56fe\u7247<br \/>\nimg &#061; cv2.imread(&#034;..\/images\/ROI.png&#034;)<\/p>\n<p># \u6d45\u62f7\u8d1d<br \/>\nimg2 &#061; img<br \/>\n# \u6df1\u62f7\u8d1d<br \/>\nimg3 &#061; img.copy()<\/p>\n<p># \u4fee\u6539img2<br \/>\nimg[10:100,10:100] &#061; [0, 0, 255]<\/p>\n<p>cv2.imshow(&#039;img&#039;, img)<br \/>\ncv2.imshow(&#039;img2&#039;, img2)<br \/>\ncv2.imshow(&#039;img3&#039;, img3)<\/p>\n<p>cv2.waitKey(0)<br \/>\ncv2.destroyAllWindows() <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"912\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250612072811-684a818b2feca.png\" width=\"1787\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb931\u6b21\uff0c\u70b9\u8d5e15\u6b21\uff0c\u6536\u85cf12\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86OpenCV\u5728\u56fe\u50cf\u5904\u7406\u4e2d\u7684\u51e0\u4e2a\u5173\u952e\u6280\u672f\uff1a\u8fb9\u754c\u586b\u5145\uff08\u5305\u62ec\u5e38\u6570\u586b\u5145\u3001\u590d\u5236\u586b\u5145\u3001\u53cd\u5c04\u586b\u5145\u548c\u73af\u7ed5\u586b\u5145\u65b9\u6cd5\uff09\u3001\u56fe\u50cf\u878d\u5408\uff08\u4f7f\u7528addWeighted\u51fd\u6570\u5b9e\u73b0\u52a0\u6743\u878d\u5408\uff09\u3001\u56fe\u50cf\u9608\u503c\u5904\u7406\uff085\u79cd\u4e8c\u503c\u5316\u65b9\u6cd5\uff09\u3001Mat\u6570\u636e\u7ed3\u6784\u7684\u57fa\u672c\u6982\u5ff5\u53ca\u5176\u5c5e\u6027\uff0c\u4ee5\u53ca\u6df1\u62f7\u8d1d\u4e0e\u6d45\u62f7\u8d1d\u7684\u533a\u522b\u3002\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528cv2.copyMakeBorder\u5b9e\u73b0\u8fb9\u754c\u586b\u5145\u3001\u7528cv2.addWeighted\u8fdb\u884c\u56fe\u50cf\u878d\u5408\uff0c\u5e76\u5c55\u793a\u4e86\u4e0d\u540c\u9608\u503c\u5904\u7406\u7684\u6548\u679c\u3002\u6587\u4e2d\u8fd8\u8be6\u7ec6\u89e3\u6790\u4e86Mat\u7ed3\u6784\u7684\u7ec4\u6210\u90e8\u5206\u548cPython\u4e2d\u6df1\/\u6d45\u62f7\u8d1d\u5728\u56fe\u50cf\u5904\u7406\u4e2d\u7684\u5e94\u7528\u5dee\u5f02\u3002<\/p>\n","protected":false},"author":2,"featured_media":43418,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1460,81,50,3829,523],"topic":[],"class_list":["post-43430","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-opencv","tag-python","tag-50","tag-3829","tag-523"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python-OpenCV\uff08\u56fe\u50cf\u5904\u7406\u2014\u2014\u8fb9\u754c\u586b\u5145\u3001\u56fe\u50cf\u878d\u5408\u3001\u56fe\u50cf\u9608\u503c\u3001\u6df1\u62f7\u8d1d\u4e0e\u6d45\u62f7\u8d1d\uff09 - \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\/43430.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python-OpenCV\uff08\u56fe\u50cf\u5904\u7406\u2014\u2014\u8fb9\u754c\u586b\u5145\u3001\u56fe\u50cf\u878d\u5408\u3001\u56fe\u50cf\u9608\u503c\u3001\u6df1\u62f7\u8d1d\u4e0e\u6d45\u62f7\u8d1d\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb931\u6b21\uff0c\u70b9\u8d5e15\u6b21\uff0c\u6536\u85cf12\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86OpenCV\u5728\u56fe\u50cf\u5904\u7406\u4e2d\u7684\u51e0\u4e2a\u5173\u952e\u6280\u672f\uff1a\u8fb9\u754c\u586b\u5145\uff08\u5305\u62ec\u5e38\u6570\u586b\u5145\u3001\u590d\u5236\u586b\u5145\u3001\u53cd\u5c04\u586b\u5145\u548c\u73af\u7ed5\u586b\u5145\u65b9\u6cd5\uff09\u3001\u56fe\u50cf\u878d\u5408\uff08\u4f7f\u7528addWeighted\u51fd\u6570\u5b9e\u73b0\u52a0\u6743\u878d\u5408\uff09\u3001\u56fe\u50cf\u9608\u503c\u5904\u7406\uff085\u79cd\u4e8c\u503c\u5316\u65b9\u6cd5\uff09\u3001Mat\u6570\u636e\u7ed3\u6784\u7684\u57fa\u672c\u6982\u5ff5\u53ca\u5176\u5c5e\u6027\uff0c\u4ee5\u53ca\u6df1\u62f7\u8d1d\u4e0e\u6d45\u62f7\u8d1d\u7684\u533a\u522b\u3002\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528cv2.copyMakeBorder\u5b9e\u73b0\u8fb9\u754c\u586b\u5145\u3001\u7528cv2.addWeighted\u8fdb\u884c\u56fe\u50cf\u878d\u5408\uff0c\u5e76\u5c55\u793a\u4e86\u4e0d\u540c\u9608\u503c\u5904\u7406\u7684\u6548\u679c\u3002\u6587\u4e2d\u8fd8\u8be6\u7ec6\u89e3\u6790\u4e86Mat\u7ed3\u6784\u7684\u7ec4\u6210\u90e8\u5206\u548cPython\u4e2d\u6df1\/\u6d45\u62f7\u8d1d\u5728\u56fe\u50cf\u5904\u7406\u4e2d\u7684\u5e94\u7528\u5dee\u5f02\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/43430.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-06-12T07:28:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250612072807-684a81871181c.png\" \/>\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\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/43430.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/43430.html\",\"name\":\"Python-OpenCV\uff08\u56fe\u50cf\u5904\u7406\u2014\u2014\u8fb9\u754c\u586b\u5145\u3001\u56fe\u50cf\u878d\u5408\u3001\u56fe\u50cf\u9608\u503c\u3001\u6df1\u62f7\u8d1d\u4e0e\u6d45\u62f7\u8d1d\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-06-12T07:28:13+00:00\",\"dateModified\":\"2025-06-12T07:28:13+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/43430.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/43430.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/43430.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python----OpenCV\uff08\u56fe\u50cf\u5904\u7406\u2014\u2014\u8fb9\u754c\u586b\u5145\u3001\u56fe\u50cf\u878d\u5408\u3001\u56fe\u50cf\u9608\u503c\u3001\u6df1\u62f7\u8d1d\u4e0e\u6d45\u62f7\u8d1d\uff09\"}]},{\"@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-OpenCV\uff08\u56fe\u50cf\u5904\u7406\u2014\u2014\u8fb9\u754c\u586b\u5145\u3001\u56fe\u50cf\u878d\u5408\u3001\u56fe\u50cf\u9608\u503c\u3001\u6df1\u62f7\u8d1d\u4e0e\u6d45\u62f7\u8d1d\uff09 - \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\/43430.html","og_locale":"zh_CN","og_type":"article","og_title":"Python-OpenCV\uff08\u56fe\u50cf\u5904\u7406\u2014\u2014\u8fb9\u754c\u586b\u5145\u3001\u56fe\u50cf\u878d\u5408\u3001\u56fe\u50cf\u9608\u503c\u3001\u6df1\u62f7\u8d1d\u4e0e\u6d45\u62f7\u8d1d\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb931\u6b21\uff0c\u70b9\u8d5e15\u6b21\uff0c\u6536\u85cf12\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86OpenCV\u5728\u56fe\u50cf\u5904\u7406\u4e2d\u7684\u51e0\u4e2a\u5173\u952e\u6280\u672f\uff1a\u8fb9\u754c\u586b\u5145\uff08\u5305\u62ec\u5e38\u6570\u586b\u5145\u3001\u590d\u5236\u586b\u5145\u3001\u53cd\u5c04\u586b\u5145\u548c\u73af\u7ed5\u586b\u5145\u65b9\u6cd5\uff09\u3001\u56fe\u50cf\u878d\u5408\uff08\u4f7f\u7528addWeighted\u51fd\u6570\u5b9e\u73b0\u52a0\u6743\u878d\u5408\uff09\u3001\u56fe\u50cf\u9608\u503c\u5904\u7406\uff085\u79cd\u4e8c\u503c\u5316\u65b9\u6cd5\uff09\u3001Mat\u6570\u636e\u7ed3\u6784\u7684\u57fa\u672c\u6982\u5ff5\u53ca\u5176\u5c5e\u6027\uff0c\u4ee5\u53ca\u6df1\u62f7\u8d1d\u4e0e\u6d45\u62f7\u8d1d\u7684\u533a\u522b\u3002\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u6f14\u793a\u4e86\u5982\u4f55\u4f7f\u7528cv2.copyMakeBorder\u5b9e\u73b0\u8fb9\u754c\u586b\u5145\u3001\u7528cv2.addWeighted\u8fdb\u884c\u56fe\u50cf\u878d\u5408\uff0c\u5e76\u5c55\u793a\u4e86\u4e0d\u540c\u9608\u503c\u5904\u7406\u7684\u6548\u679c\u3002\u6587\u4e2d\u8fd8\u8be6\u7ec6\u89e3\u6790\u4e86Mat\u7ed3\u6784\u7684\u7ec4\u6210\u90e8\u5206\u548cPython\u4e2d\u6df1\/\u6d45\u62f7\u8d1d\u5728\u56fe\u50cf\u5904\u7406\u4e2d\u7684\u5e94\u7528\u5dee\u5f02\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/43430.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-06-12T07:28:13+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250612072807-684a81871181c.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/43430.html","url":"https:\/\/www.wsisp.com\/helps\/43430.html","name":"Python-OpenCV\uff08\u56fe\u50cf\u5904\u7406\u2014\u2014\u8fb9\u754c\u586b\u5145\u3001\u56fe\u50cf\u878d\u5408\u3001\u56fe\u50cf\u9608\u503c\u3001\u6df1\u62f7\u8d1d\u4e0e\u6d45\u62f7\u8d1d\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-06-12T07:28:13+00:00","dateModified":"2025-06-12T07:28:13+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/43430.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/43430.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/43430.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python----OpenCV\uff08\u56fe\u50cf\u5904\u7406\u2014\u2014\u8fb9\u754c\u586b\u5145\u3001\u56fe\u50cf\u878d\u5408\u3001\u56fe\u50cf\u9608\u503c\u3001\u6df1\u62f7\u8d1d\u4e0e\u6d45\u62f7\u8d1d\uff09"}]},{"@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\/43430","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=43430"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/43430\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/43418"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=43430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=43430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=43430"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=43430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}