{"id":26,"date":"2023-11-07T22:42:14","date_gmt":"2023-11-07T14:42:14","guid":{"rendered":"https:\/\/www.rwr.ink\/?p=26"},"modified":"2023-11-08T23:18:21","modified_gmt":"2023-11-08T15:18:21","slug":"opencv-with-cuda%e7%bc%96%e8%af%91%e5%ae%9e%e6%88%98","status":"publish","type":"post","link":"https:\/\/www.rwr.ink\/index.php\/2023\/11\/07\/opencv-with-cuda%e7%bc%96%e8%af%91%e5%ae%9e%e6%88%98\/","title":{"rendered":"OpenCV with CUDA\u7f16\u8bd1\u5b9e\u6218"},"content":{"rendered":"<h4>\u73af\u5883\u8981\u6c42<\/h4>\n<pre><code class=\"language-json\">Windows 11 22H2\ncuda 12.2.0\ncuDNN 8.9.5\nvs 2022 \u4ee5\u53ca c++\u684c\u9762\u5f00\u53d1\u73af\u5883\npython 3.9\nopencv 4.8.0<\/code><\/pre>\n<h4>\u5b89\u88c5conda\u73af\u5883<\/h4>\n<pre><code># \u5b89\u88c5\u5305\nhttps:\/\/repo.anaconda.com\/archive\/Anaconda3-2023.09-0-Windows-x86_64.exe\n\n# \u5b89\u88c5\u5730\u5740\uff08\u53ef\u9009\uff09\nD:\\Program\\anaconda3\n\n# \u5b89\u88c5\u914d\u7f6e\uff08\u52fe\u9009\uff09\n1.Create start menu shortcuts (supported packages only).\n2.Register Anaconda3 as my default Python 3.X\n3.Clear the package cache upon completion\n\n# \u6ce8\u518cconda\uff08\u53ef\u9009\uff09\nconda init powershell<\/code><\/pre>\n<h5>\u5e38\u7528conda\u547d\u4ee4<\/h5>\n<pre><code># \u521b\u5efa\u540d\u4e3aopencv\u7684Python\u7248\u672c\u4e3a3.9\u7684\u73af\u5883\nconda create -n op python=3.9\n\n# \u67e5\u770bAnaconda\u4e0b\u7ba1\u7406\u7684\u6240\u6709Python\u73af\u5883\nconda info -e\n\n# \u6fc0\u6d3bpytorch\nconda activate op\n\n# \u9000\u51fa\u865a\u62df\u73af\u5883\nconda deactivate\n\n# \u5220\u9664opencv\u73af\u5883\uff1a\nconda remove --name op --all<\/code><\/pre>\n<h4>\u914d\u7f6eCmake\u73af\u5883<\/h4>\n<pre><code># https:\/\/cmake.org\/\n\n# \u4e0b\u8f7dgui\u7248&amp;\u5b89\u88c5\nhttps:\/\/github.com\/Kitware\/CMake\/releases\/download\/v3.28.0-rc3\/cmake-3.28.0-rc3-windows-x86_64.msi\n\n# \u65b0\u5efa\u6587\u4ef6\u5939\nmkdir opencv\ncd opencv\nmkdir build\n\n# \u4e0b\u8f7dopencv\nhttps:\/\/github.com\/opencv\/opencv\/archive\/refs\/tags\/4.8.0.zip\n\n# \u89e3\u538b\u81f3\u5f53\u524d\u76ee\u5f55\u540eclone opencv-contrib\ngit clone https:\/\/github.com\/opencv\/opencv_contrib.git\n\n# \u5b8c\u6210\u540e\u7684\u76ee\u5f55\u7ed3\u6784\n|--opencv\\\n|--opencv\\build\n|--opencv\\opencv-4.8.0\n|--opencv\\opencv_contrib-4.8.0\n\n# \u6253\u5f00camke\nsource_path = ..\\opencv\\opencv-4.8.0\nbuild_path = ..\\opencv\\opencv_contrib-4.8.0\n\n# Add Entry \u6dfb\u52a0Python\u73af\u5883\nPYTHON3_EXECUTABLE\\\nFILEPATH\\\n&quot;PATH TO YOUR PYTHON.EXE WHERE IN ANACONDA ENVIREMENT&quot;\n\n\u7b2c\u4e00\u6b21\u70b9\u51fbconfigure\u540e\uff0c\u5982\u679c\u6ca1\u6709error\u62a5\u9519\uff0c\u5219\n0.\u5f39\u51fa\u7684VS\u914d\u7f6e\u9009\u9879-VS17-x64\n1.\u52fe\u9009BUILD_opencv_world\u3001WITH_CUDA\u3001OPENCV_DNN_CUDA\n2.\u8bbe\u7f6eOPENCV_EXTRA_MODULES_PATH\u4e3a\\opencv\\opencv_contrib-4.8.0\\modules\n\n\u7b2c\u4e8c\u6b21\u70b9\u51fbconfigure\uff0c\u5982\u679c\u6ca1\u6709\u62a5\u9519\uff0c\u5219\n1.\u52fe\u9009FAST_MATH\u5b57\u6837\u9009\u9879\uff0c\u53bb\u9664\u6240\u6709TEST\u3001Java\u5b57\u6837\u9009\u9879\n2.\u6309\u9700\u6c42\u52fe\u9009ENABLE-NOFREE\u3001DNN-PERF\u3001BUILD-XX\u7b49\n3.\u68c0\u67e5\u662f\u5426\u52fe\u9009opencv-python3\n\n\u7b2c\u4e09\u6b21\u70b9\u51fbconfigure\uff0c\u5982\u679c\u6ca1\u6709\u62a5\u9519\uff0c\u5219\u70b9\u51fbGenerate\n\u82e5\u6ca1\u6709\u62a5\u9519\uff0c\u8fdb\u5165\u7f16\u8bd1\u9636\u6bb5<\/code><\/pre>\n<h4>VS\u7f16\u8bd1<\/h4>\n<pre><code class=\"language-shell\">1.\u70b9\u51fbOpen Project\n2.\u8bbe\u7f6e\u7f16\u8bd1\u5e73\u53f0\uff08Release\/Debug\u5747\u53ef\uff09\u548c x64, \u53f3\u952eALL_BUILD-\u751f\u6210\uff0c\u751f\u6210\u65f6\u95f4\u8f83\u957f\n3.\u751f\u6210\u6210\u529f\u540e\uff0c\u53f3\u952eINSTALL-\u4ec5\u7528\u4e8e\u9879\u76ee-\u4ec5\u751f\u6210INSTALL<\/code><\/pre>\n<h4>\u914d\u7f6emodules<\/h4>\n<pre><code class=\"language-shell\">\u5728\u7f16\u8bd1\u8f93\u51fa\u6587\u4ef6\u5939lib\\python3\\Release\u4e0b\u7684\n\\cv2.cp39-win_amd64.pyd\u590d\u5236\u5230anaconda3\\envs\\op\\Lib\\site-packages\\cv2\\python-3.9\n\\bin\\Release\u76ee\u5f55\u4e0b\u6240\u6709\u6587\u4ef6\u590d\u5236\u5230anaconda3\\envs\\op\\Lib\\site-packages<\/code><\/pre>\n<h4>\u6d4b\u8bd5\u7a0b\u5e8f<\/h4>\n<pre><code class=\"language-python\">import cv2\ncv2.cuda.printCudaDeviceInfo(0)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"OpenCV with CUDA\u7f16\u8bd1\u5b9e\u6218\uff0c\u4ecb\u7ecd\u4e86\u5728Windows\u73af\u5883\u4e0b\u4f7f\u7528CUDA\u7f16\u8bd1OpenCV\u7684\u6b65\u9aa4\u3002\u9996\u5148\u9700\u8981\u5b89\u88c5Anaconda\u548cCMake\uff0c\u5e76\u521b\u5efaPython\u73af\u5883\u3002\u7136\u540e\u4e0b\u8f7dOpenCV\u548cOpenCV-contri","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[1],"tags":[2,3],"class_list":["post-26","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-windows","tag-3"],"_links":{"self":[{"href":"https:\/\/www.rwr.ink\/index.php\/wp-json\/wp\/v2\/posts\/26","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rwr.ink\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rwr.ink\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rwr.ink\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rwr.ink\/index.php\/wp-json\/wp\/v2\/comments?post=26"}],"version-history":[{"count":3,"href":"https:\/\/www.rwr.ink\/index.php\/wp-json\/wp\/v2\/posts\/26\/revisions"}],"predecessor-version":[{"id":61,"href":"https:\/\/www.rwr.ink\/index.php\/wp-json\/wp\/v2\/posts\/26\/revisions\/61"}],"wp:attachment":[{"href":"https:\/\/www.rwr.ink\/index.php\/wp-json\/wp\/v2\/media?parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rwr.ink\/index.php\/wp-json\/wp\/v2\/categories?post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rwr.ink\/index.php\/wp-json\/wp\/v2\/tags?post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}