{"id":1095925,"date":"2025-01-08T14:56:06","date_gmt":"2025-01-08T06:56:06","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1095925.html"},"modified":"2025-01-08T14:56:08","modified_gmt":"2025-01-08T06:56:08","slug":"%e5%a6%82%e4%bd%95%e6%89%93%e5%bc%80%e6%91%84%e5%83%8f%e5%a4%b4python%e4%b8%8eopencv-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1095925.html","title":{"rendered":"\u5982\u4f55\u6253\u5f00\u6444\u50cf\u5934python\u4e0eopencv"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24211347\/7d1816e4-e94a-4e91-90e2-005231c0788d.webp\" alt=\"\u5982\u4f55\u6253\u5f00\u6444\u50cf\u5934python\u4e0eopencv\" \/><\/p>\n<p><p> <strong>\u5982\u4f55\u6253\u5f00\u6444\u50cf\u5934Python\u4e0eOpenCV<\/strong><br \/>\u8981\u5728Python\u4e2d\u4f7f\u7528OpenCV\u6765\u6253\u5f00\u6444\u50cf\u5934\uff0c\u4f60\u9700\u8981\u5b89\u88c5OpenCV\u5e93\u5e76\u4f7f\u7528\u5b83\u63d0\u4f9b\u7684\u51fd\u6570\u6765\u83b7\u53d6\u548c\u5904\u7406\u6444\u50cf\u5934\u7684\u56fe\u50cf\u3002\u4e3b\u8981\u6b65\u9aa4\u5305\u62ec\uff1a\u5b89\u88c5OpenCV\u3001\u5bfc\u5165\u5e93\u3001\u4f7f\u7528VideoCapture\u7c7b\u6253\u5f00\u6444\u50cf\u5934\u3001\u8bfb\u53d6\u5e27\u5e76\u663e\u793a\u3002<strong>\u5b89\u88c5OpenCV\u3001\u5bfc\u5165\u5e93\u3001\u4f7f\u7528VideoCapture\u7c7b\u6253\u5f00\u6444\u50cf\u5934\u3001\u8bfb\u53d6\u5e27\u5e76\u663e\u793a<\/strong>\uff0c\u8fd9\u4e9b\u6b65\u9aa4\u53ef\u4ee5\u5e2e\u52a9\u4f60\u8fc5\u901f\u638c\u63e1\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528OpenCV\u64cd\u4f5c\u6444\u50cf\u5934\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u4f7f\u7528VideoCapture\u7c7b\u6253\u5f00\u6444\u50cf\u5934\uff0c\u5e76\u8bfb\u53d6\u548c\u663e\u793a\u5e27\u3002<\/p>\n<\/p>\n<p><h3>\u5b89\u88c5OpenCV<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u786e\u4fdd\u4f60\u7684Python\u73af\u5883\u4e2d\u5df2\u7ecf\u5b89\u88c5\u4e86OpenCV\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install opencv-python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5bfc\u5165\u5e93<\/h3>\n<\/p>\n<p><p>\u5728\u4f60\u7684Python\u811a\u672c\u4e2d\uff0c\u9996\u5148\u5bfc\u5165\u5fc5\u8981\u7684\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4f7f\u7528VideoCapture\u7c7b\u6253\u5f00\u6444\u50cf\u5934<\/h3>\n<\/p>\n<p><p>\u8981\u6253\u5f00\u6444\u50cf\u5934\uff0c\u4f60\u9700\u8981\u521b\u5efa\u4e00\u4e2aVideoCapture\u5bf9\u8c61\u3002\u8fd9\u4e2a\u5bf9\u8c61\u4f1a\u8fde\u63a5\u5230\u4f60\u7684\u6444\u50cf\u5934\uff0c\u5e76\u5141\u8bb8\u4f60\u4ece\u4e2d\u8bfb\u53d6\u89c6\u9891\u5e27\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">cap = cv2.VideoCapture(0)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u91cc\u7684\u53c2\u6570<code>0<\/code>\u8868\u793a\u4f60\u8981\u6253\u5f00\u9ed8\u8ba4\u7684\u6444\u50cf\u5934\u3002\u5982\u679c\u4f60\u6709\u591a\u4e2a\u6444\u50cf\u5934\uff0c\u53ef\u4ee5\u7528<code>1<\/code>\u3001<code>2<\/code>\u7b49\u6765\u9009\u62e9\u4e0d\u540c\u7684\u6444\u50cf\u5934\u3002<\/p>\n<\/p>\n<p><h3>\u8bfb\u53d6\u5e27\u5e76\u663e\u793a<\/h3>\n<\/p>\n<p><p>\u4e00\u65e6\u4f60\u6210\u529f\u6253\u5f00\u6444\u50cf\u5934\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u5faa\u73af\u6765\u4e0d\u65ad\u5730\u8bfb\u53d6\u548c\u663e\u793a\u89c6\u9891\u5e27\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">while True:<\/p>\n<p>    ret, frame = cap.read()<\/p>\n<p>    if not ret:<\/p>\n<p>        break<\/p>\n<p>    cv2.imshow(&#39;Camera&#39;, frame)<\/p>\n<p>    if cv2.w<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>tKey(1) &amp; 0xFF == ord(&#39;q&#39;):<\/p>\n<p>        break<\/p>\n<p>cap.release()<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4ee3\u7801\u4e2d\uff0c<code>cap.read()<\/code>\u8bfb\u53d6\u4e00\u5e27\u56fe\u50cf\uff0c<code>cv2.imshow<\/code>\u663e\u793a\u56fe\u50cf\uff0c<code>cv2.waitKey(1)<\/code>\u5728\u6bcf\u4e00\u5e27\u4e4b\u95f4\u7b49\u5f851\u6beb\u79d2\uff0c\u5982\u679c\u6309\u4e0b&#39;q&#39;\u952e\uff0c\u5faa\u73af\u5c06\u9000\u51fa\u3002<\/p>\n<\/p>\n<p><h3>\u8be6\u7ec6\u6b65\u9aa4\u89e3\u6790<\/h3>\n<\/p>\n<p><h4>\u4e00\u3001\u5b89\u88c5OpenCV<\/h4>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u4f60\u9700\u8981\u786e\u4fdd\u4f60\u7684Python\u73af\u5883\u4e2d\u5df2\u7ecf\u5b89\u88c5\u4e86OpenCV\u5e93\u3002OpenCV\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u8ba1\u7b97\u673a\u89c6\u89c9\u5e93\uff0c\u5e7f\u6cdb\u7528\u4e8e\u56fe\u50cf\u548c\u89c6\u9891\u5904\u7406\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\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><p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5b89\u88c5OpenCV\u7684\u57fa\u672c\u529f\u80fd\u3002\u5982\u679c\u4f60\u9700\u8981\u989d\u5916\u7684\u529f\u80fd\uff0c\u6bd4\u5982\u5bf9\u89c6\u9891\u7f16\u89e3\u7801\u7684\u652f\u6301\uff0c\u4f60\u53ef\u80fd\u8fd8\u9700\u8981\u5b89\u88c5<code>opencv-contrib-python<\/code>\u5e93\u3002<\/p>\n<\/p>\n<p><h4>\u4e8c\u3001\u5bfc\u5165\u5e93<\/h4>\n<\/p>\n<p><p>\u5728\u4f60\u7684Python\u811a\u672c\u4e2d\uff0c\u9996\u5148\u5bfc\u5165\u5fc5\u8981\u7684\u5e93\u3002\u5bf9\u4e8e\u672c\u6559\u7a0b\uff0c\u6211\u4eec\u53ea\u9700\u8981\u5bfc\u5165cv2\u5e93\uff0c\u8fd9\u662fOpenCV\u7684\u4e3b\u8981\u5e93\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import cv2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u4e09\u3001\u4f7f\u7528VideoCapture\u7c7b\u6253\u5f00\u6444\u50cf\u5934<\/h4>\n<\/p>\n<p><p>\u8981\u6253\u5f00\u6444\u50cf\u5934\uff0c\u4f60\u9700\u8981\u521b\u5efa\u4e00\u4e2aVideoCapture\u5bf9\u8c61\u3002\u8fd9\u4e2a\u5bf9\u8c61\u4f1a\u8fde\u63a5\u5230\u4f60\u7684\u6444\u50cf\u5934\uff0c\u5e76\u5141\u8bb8\u4f60\u4ece\u4e2d\u8bfb\u53d6\u89c6\u9891\u5e27\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">cap = cv2.VideoCapture(0)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u91cc\u7684\u53c2\u6570<code>0<\/code>\u8868\u793a\u4f60\u8981\u6253\u5f00\u9ed8\u8ba4\u7684\u6444\u50cf\u5934\u3002\u5982\u679c\u4f60\u6709\u591a\u4e2a\u6444\u50cf\u5934\uff0c\u53ef\u4ee5\u7528<code>1<\/code>\u3001<code>2<\/code>\u7b49\u6765\u9009\u62e9\u4e0d\u540c\u7684\u6444\u50cf\u5934\u3002<\/p>\n<\/p>\n<p><p>VideoCapture\u7c7b\u6709\u591a\u4e2a\u65b9\u6cd5\u6765\u63a7\u5236\u6444\u50cf\u5934\u7684\u884c\u4e3a\uff0c\u6bd4\u5982\u8bbe\u7f6e\u5206\u8fa8\u7387\u3001\u5e27\u7387\u7b49\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u6765\u6839\u636e\u4f60\u7684\u9700\u8981\u8c03\u6574\u6444\u50cf\u5934\u7684\u8bbe\u7f6e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)<\/p>\n<p>cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u56db\u3001\u8bfb\u53d6\u5e27\u5e76\u663e\u793a<\/h4>\n<\/p>\n<p><p>\u4e00\u65e6\u4f60\u6210\u529f\u6253\u5f00\u6444\u50cf\u5934\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u5faa\u73af\u6765\u4e0d\u65ad\u5730\u8bfb\u53d6\u548c\u663e\u793a\u89c6\u9891\u5e27\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">while True:<\/p>\n<p>    ret, frame = cap.read()<\/p>\n<p>    if not ret:<\/p>\n<p>        break<\/p>\n<p>    cv2.imshow(&#39;Camera&#39;, frame)<\/p>\n<p>    if cv2.waitKey(1) &amp; 0xFF == ord(&#39;q&#39;):<\/p>\n<p>        break<\/p>\n<p>cap.release()<\/p>\n<p>cv2.destroyAllWindows()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4ee3\u7801\u4e2d\uff0c<code>cap.read()<\/code>\u8bfb\u53d6\u4e00\u5e27\u56fe\u50cf\uff0c<code>cv2.imshow<\/code>\u663e\u793a\u56fe\u50cf\uff0c<code>cv2.waitKey(1)<\/code>\u5728\u6bcf\u4e00\u5e27\u4e4b\u95f4\u7b49\u5f851\u6beb\u79d2\uff0c\u5982\u679c\u6309\u4e0b&#39;q&#39;\u952e\uff0c\u5faa\u73af\u5c06\u9000\u51fa\u3002<\/p>\n<\/p>\n<p><h4>\u89e3\u91ca\u7ec6\u8282<\/h4>\n<\/p>\n<ol>\n<li>\n<p><strong>cap.read()<\/strong>: \u8fd9\u4e2a\u65b9\u6cd5\u4ece\u6444\u50cf\u5934\u8bfb\u53d6\u4e00\u5e27\u56fe\u50cf\u3002\u5b83\u8fd4\u56de\u4e24\u4e2a\u503c\uff0c<code>ret<\/code>\u548c<code>frame<\/code>\u3002<code>ret<\/code>\u662f\u4e00\u4e2a\u5e03\u5c14\u503c\uff0c\u8868\u793a\u662f\u5426\u6210\u529f\u8bfb\u53d6\u5e27\uff1b<code>frame<\/code>\u662f\u8bfb\u53d6\u7684\u56fe\u50cf\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>cv2.imshow()<\/strong>: \u8fd9\u4e2a\u65b9\u6cd5\u663e\u793a\u56fe\u50cf\u3002\u5b83\u6709\u4e24\u4e2a\u53c2\u6570\uff0c\u7b2c\u4e00\u4e2a\u662f\u7a97\u53e3\u7684\u540d\u5b57\uff0c\u7b2c\u4e8c\u4e2a\u662f\u8981\u663e\u793a\u7684\u56fe\u50cf\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>cv2.waitKey()<\/strong>: \u8fd9\u4e2a\u65b9\u6cd5\u7b49\u5f85\u7528\u6237\u6309\u952e\u3002\u5982\u679c\u5728\u7b49\u5f85\u65f6\u95f4\u5185\u6309\u4e0b&#39;q&#39;\u952e\uff0c\u5faa\u73af\u5c06\u9000\u51fa\u3002\u8fd9\u91cc\u7684<code>0xFF<\/code>\u662f\u4e00\u4e2a\u4f4d\u63a9\u7801\uff0c\u7528\u6765\u83b7\u53d6\u6309\u952e\u7684\u4f4e8\u4f4d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>cap.release()<\/strong>: \u8fd9\u4e2a\u65b9\u6cd5\u91ca\u653e\u6444\u50cf\u5934\u8d44\u6e90\u3002\u5728\u4e0d\u518d\u9700\u8981\u6444\u50cf\u5934\u65f6\u8c03\u7528\u8fd9\u4e2a\u65b9\u6cd5\u662f\u4e00\u4e2a\u597d\u4e60\u60ef\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>cv2.destroyAllWindows()<\/strong>: \u8fd9\u4e2a\u65b9\u6cd5\u5173\u95ed\u6240\u6709OpenCV\u7a97\u53e3\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u5e38\u89c1\u95ee\u9898<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528OpenCV\u6253\u5f00\u6444\u50cf\u5934\u65f6\uff0c\u4f60\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u65e0\u6cd5\u6253\u5f00\u6444\u50cf\u5934<\/strong>: \u5982\u679c\u65e0\u6cd5\u6253\u5f00\u6444\u50cf\u5934\uff0c\u8bf7\u68c0\u67e5\u6444\u50cf\u5934\u662f\u5426\u8fde\u63a5\u6b63\u786e\uff0c\u5e76\u786e\u4fdd\u5176\u4ed6\u5e94\u7528\u7a0b\u5e8f\u6ca1\u6709\u5360\u7528\u6444\u50cf\u5934\u8d44\u6e90\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u663e\u793a\u9ed1\u5c4f<\/strong>: \u5982\u679c\u663e\u793a\u9ed1\u5c4f\uff0c\u8bf7\u68c0\u67e5\u6444\u50cf\u5934\u7684\u5206\u8fa8\u7387\u8bbe\u7f6e\u662f\u5426\u6b63\u786e\uff0c\u5e76\u786e\u4fdd\u6444\u50cf\u5934\u652f\u6301\u5f53\u524d\u8bbe\u7f6e\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5ef6\u8fdf\u548c\u5361\u987f<\/strong>: \u5982\u679c\u89c6\u9891\u663e\u793a\u5ef6\u8fdf\u548c\u5361\u987f\uff0c\u8bf7\u5c1d\u8bd5\u964d\u4f4e\u5206\u8fa8\u7387\u6216\u589e\u52a0<code>cv2.waitKey()<\/code>\u7684\u7b49\u5f85\u65f6\u95f4\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u7ed3\u8bba<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u4f60\u5e94\u8be5\u80fd\u591f\u6210\u529f\u5728Python\u4e2d\u4f7f\u7528OpenCV\u6253\u5f00\u6444\u50cf\u5934\uff0c\u5e76\u8bfb\u53d6\u548c\u663e\u793a\u89c6\u9891\u5e27\u3002<strong>\u5b89\u88c5OpenCV\u3001\u5bfc\u5165\u5e93\u3001\u4f7f\u7528VideoCapture\u7c7b\u6253\u5f00\u6444\u50cf\u5934\u3001\u8bfb\u53d6\u5e27\u5e76\u663e\u793a<\/strong>\u662f\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u7684\u5173\u952e\u6b65\u9aa4\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002\u5982\u679c\u4f60\u6709\u4efb\u4f55\u95ee\u9898\u6216\u5efa\u8bae\uff0c\u8bf7\u968f\u65f6\u7559\u8a00\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528OpenCV\u6253\u5f00\u6444\u50cf\u5934\uff1f<\/strong><br \/>\u8981\u5728Python\u4e2d\u4f7f\u7528OpenCV\u6253\u5f00\u6444\u50cf\u5934\uff0c\u60a8\u9700\u8981\u9996\u5148\u5b89\u88c5OpenCV\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c<code>pip install opencv-python<\/code>\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6253\u5f00\u6444\u50cf\u5934\uff1a<\/p>\n<pre><code class=\"language-python\">import cv2\n\ncap = cv2.VideoCapture(0)  # 0\u8868\u793a\u9ed8\u8ba4\u6444\u50cf\u5934\nwhile True:\n    ret, frame = cap.read()\n    if not ret:\n        break\n    cv2.imshow(&#39;Camera&#39;, frame)\n    if cv2.waitKey(1) &amp; 0xFF == ord(&#39;q&#39;):\n        break\n\ncap.release()\ncv2.destroyAllWindows()\n<\/code><\/pre>\n<p>\u6b64\u6bb5\u4ee3\u7801\u5c06\u6253\u5f00\u6444\u50cf\u5934\u5e76\u663e\u793a\u5b9e\u65f6\u89c6\u9891\u6d41\uff0c\u6309\u4e0b\u201cq\u201d\u952e\u53ef\u4ee5\u9000\u51fa\u3002<\/p>\n<p><strong>\u5728\u4f7f\u7528OpenCV\u6253\u5f00\u6444\u50cf\u5934\u65f6\u9047\u5230\u9ed1\u5c4f\u600e\u4e48\u529e\uff1f<\/strong><br \/>\u9ed1\u5c4f\u95ee\u9898\u901a\u5e38\u7531\u591a\u4e2a\u56e0\u7d20\u5f15\u8d77\u3002\u786e\u4fdd\u6444\u50cf\u5934\u8fde\u63a5\u6b63\u5e38\uff0c\u5c1d\u8bd5\u66f4\u6362USB\u63a5\u53e3\u6216\u91cd\u542f\u8ba1\u7b97\u673a\u3002\u6709\u65f6\uff0c\u5176\u4ed6\u5e94\u7528\u7a0b\u5e8f\u53ef\u80fd\u5360\u7528\u6444\u50cf\u5934\u8d44\u6e90\uff0c\u5173\u95ed\u5176\u4ed6\u76f8\u5173\u5e94\u7528\u7a0b\u5e8f\u53ef\u80fd\u4f1a\u89e3\u51b3\u95ee\u9898\u3002\u6b64\u5916\uff0c\u68c0\u67e5\u6444\u50cf\u5934\u9a71\u52a8\u7a0b\u5e8f\u662f\u5426\u5df2\u66f4\u65b0\u4e5f\u662f\u4e2a\u4e0d\u9519\u7684\u4e3b\u610f\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u8c03\u6574\u6444\u50cf\u5934\u7684\u5206\u8fa8\u7387\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u4f7f\u7528<code>set()<\/code>\u65b9\u6cd5\u6765\u8c03\u6574\u6444\u50cf\u5934\u7684\u5206\u8fa8\u7387\u3002\u4ee5\u4e0b\u662f\u8bbe\u7f6e\u6444\u50cf\u5934\u5206\u8fa8\u7387\u7684\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-python\">cap = cv2.VideoCapture(0)\ncap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)  # \u8bbe\u7f6e\u5bbd\u5ea6\ncap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)  # \u8bbe\u7f6e\u9ad8\u5ea6\n<\/code><\/pre>\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u6444\u50cf\u5934\u7684\u5206\u8fa8\u7387\u88ab\u8c03\u6574\u4e3a1280&#215;720\u50cf\u7d20\u3002\u786e\u4fdd\u9009\u62e9\u7684\u5206\u8fa8\u7387\u88ab\u60a8\u7684\u6444\u50cf\u5934\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5982\u4f55\u6253\u5f00\u6444\u50cf\u5934Python\u4e0eOpenCV\u8981\u5728Python\u4e2d\u4f7f\u7528OpenCV\u6765\u6253\u5f00\u6444\u50cf\u5934\uff0c\u4f60\u9700\u8981\u5b89\u88c5OpenCV [&hellip;]","protected":false},"author":3,"featured_media":1095932,"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\/1095925"}],"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=1095925"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1095925\/revisions"}],"predecessor-version":[{"id":1095933,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1095925\/revisions\/1095933"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1095932"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1095925"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1095925"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1095925"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}