{"id":43572,"date":"2024-10-05T22:42:38","date_gmt":"2024-10-05T14:42:38","guid":{"rendered":"https:\/\/server.hk\/cnblog\/43572\/"},"modified":"2024-10-05T22:42:39","modified_gmt":"2024-10-05T14:42:39","slug":"centos-6-5-%e4%b8%8a%e9%85%8d%e7%bd%ae-python-2-7-opencv-2-4-13","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/43572\/","title":{"rendered":"CentOS 6.5 \u4e0a\u914d\u7f6e Python 2.7 + OpenCV 2.4.13"},"content":{"rendered":"<h1 id=\"centos-6-5-%e4%b8%8a%e9%85%8d%e7%bd%ae-python-2-7-opencv-2-4-13-JHINkEFPmC\">CentOS 6.5 \u4e0a\u914d\u7f6e Python 2.7 + OpenCV 2.4.13<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u8a08\u7b97\u6a5f\u8996\u89ba\u9818\u57df\uff0cOpenCV\uff08Open Source Computer Vision Library\uff09\u662f\u4e00\u500b\u975e\u5e38\u6d41\u884c\u7684\u958b\u6e90\u5eab\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5716\u50cf\u8655\u7406\u548c\u8a08\u7b97\u6a5f\u8996\u89ba\u4efb\u52d9\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 CentOS 6.5 \u4e0a\u914d\u7f6e Python 2.7 \u548c OpenCV 2.4.13\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u5feb\u901f\u642d\u5efa\u958b\u767c\u74b0\u5883\u3002<\/p>\n<h2 id=\"%e7%92%b0%e5%a2%83%e6%ba%96%e5%82%99-JHINkEFPmC\">\u74b0\u5883\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u78ba\u4fdd\u4f60\u7684 CentOS 6.5 \u7cfb\u7d71\u5df2\u7d93\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u66f4\u65b0\uff1a<\/p>\n<pre><code>sudo yum update<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u5b89\u88dd\u5fc5\u8981\u7684\u4f9d\u8cf4\u5305\uff0c\u5305\u62ec\u958b\u767c\u5de5\u5177\u548c\u5eab\uff1a<\/p>\n<pre><code>sudo yum groupinstall \"Development Tools\"<\/code><\/pre>\n<pre><code>sudo yum install python-devel numpy<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e8%a3%9d-python-2-7-JHINkEFPmC\">\u5b89\u88dd Python 2.7<\/h2>\n<p>CentOS 6.5 \u9ed8\u8a8d\u5b89\u88dd\u7684 Python \u7248\u672c\u53ef\u80fd\u8f03\u820a\uff0c\u56e0\u6b64\u6211\u5011\u9700\u8981\u624b\u52d5\u5b89\u88dd Python 2.7\u3002\u53ef\u4ee5\u5f9e\u6e90\u78bc\u7de8\u8b6f\u5b89\u88dd\uff1a<\/p>\n<pre><code>wget https:\/\/www.python.org\/ftp\/python\/2.7.18\/Python-2.7.18.tgz\ntar -xzf Python-2.7.18.tgz\ncd Python-2.7.18\n.\/configure --enable-optimizations\nmake\nsudo make altinstall<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5 Python \u7248\u672c\uff1a<\/p>\n<pre><code>python2.7 -V<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e8%a3%9d-opencv-2-4-13-JHINkEFPmC\">\u5b89\u88dd OpenCV 2.4.13<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u5c07\u5b89\u88dd OpenCV 2.4.13\u3002\u9996\u5148\uff0c\u4e0b\u8f09 OpenCV \u7684\u6e90\u78bc\uff1a<\/p>\n<pre><code>wget https:\/\/github.com\/opencv\/opencv\/archive\/2.4.13.zip\nunzip 2.4.13.zip\ncd opencv-2.4.13<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u5275\u5efa\u4e00\u500b\u69cb\u5efa\u76ee\u9304\u4e26\u9032\u884c\u7de8\u8b6f\uff1a<\/p>\n<pre><code>mkdir build\ncd build\ncmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=\/usr\/local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_OPENGL=ON -D WITH_IPP=ON -D WITH_TIFF=ON -D WITH_JASPER=ON -D WITH_OPENEXR=ON -D BUILD_EXAMPLES=ON ..\nmake -j4\nsudo make install<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae-python-%e7%92%b0%e5%a2%83-JHINkEFPmC\">\u914d\u7f6e Python \u74b0\u5883<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u70ba\u4e86\u8b93 Python \u80fd\u5920\u4f7f\u7528 OpenCV\uff0c\u6211\u5011\u9700\u8981\u5c07 OpenCV \u7684 Python \u6a21\u7d44\u5b89\u88dd\u5230 Python \u7684 site-packages \u4e2d\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>cd \/usr\/local\/lib\/python2.7\/site-packages\nsudo ln -s \/usr\/local\/lib\/python2.7\/site-packages\/cv2.so cv2.so<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6e2c\u8a66 OpenCV \u662f\u5426\u5b89\u88dd\u6210\u529f\u3002\u53ef\u4ee5\u5728 Python \u4ea4\u4e92\u5f0f\u74b0\u5883\u4e2d\u904b\u884c\u4ee5\u4e0b\u4ee3\u78bc\uff1a<\/p>\n<pre><code>python2.7\nimport cv2\nprint(cv2.__version__)<\/code><\/pre>\n<p>\u5982\u679c\u986f\u793a\u7248\u672c\u865f 2.4.13\uff0c\u5247\u8868\u793a\u5b89\u88dd\u6210\u529f\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-JHINkEFPmC\">\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 CentOS 6.5 \u4e0a\u914d\u7f6e Python 2.7 \u548c OpenCV 2.4.13\u3002\u9019\u4e00\u904e\u7a0b\u6d89\u53ca\u5230\u5b89\u88dd\u5fc5\u8981\u7684\u4f9d\u8cf4\u5305\u3001\u7de8\u8b6f Python \u548c OpenCV\uff0c\u4ee5\u53ca\u914d\u7f6e Python \u74b0\u5883\u3002\u9019\u4e9b\u6b65\u9a5f\u5c07\u5e6b\u52a9\u958b\u767c\u8005\u5728\u8a08\u7b97\u6a5f\u8996\u89ba\u9818\u57df\u9032\u884c\u66f4\u6df1\u5165\u7684\u63a2\u7d22\u3002<\/p>\n<p>\u5982\u679c\u60a8\u9700\u8981\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u670d\u52d9\u4f86\u652f\u6301\u60a8\u7684\u958b\u767c\u5de5\u4f5c\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u9069\u5408\u4e0d\u540c\u9700\u6c42\u7684\u7528\u6236\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u9084\u662f\u5176\u4ed6\u5730\u5340\u7684\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u53ef\u9760\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to configure Python 2.7 and OpenCV 2.4.13 on CentOS 6.5 for efficient image processing and computer vision applications.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-43572","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43572","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=43572"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43572\/revisions"}],"predecessor-version":[{"id":43573,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43572\/revisions\/43573"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=43572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=43572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=43572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}