{"id":191,"date":"2020-08-03T11:59:54","date_gmt":"2020-08-03T03:59:54","guid":{"rendered":"https:\/\/www.guger.top\/?p=191"},"modified":"2020-08-03T12:08:04","modified_gmt":"2020-08-03T04:08:04","slug":"makefile%e5%ad%a6%e4%b9%a0%ef%bc%88%e4%ba%8c%ef%bc%89opencv%e7%bc%96%e8%af%91","status":"publish","type":"post","link":"https:\/\/www.guger.top\/index.php\/2020\/08\/03\/makefile%e5%ad%a6%e4%b9%a0%ef%bc%88%e4%ba%8c%ef%bc%89opencv%e7%bc%96%e8%af%91\/","title":{"rendered":"Makefile\u5b66\u4e60\uff08\u4e8c\uff09opencv\u7f16\u8bd1"},"content":{"rendered":"<p>\u4e4b\u524d\u5148\u8bd5\u4e86\u8bd5\u6700\u7b80\u5355\u7684Makefile\u73af\u5883\u914d\u7f6e\uff0c\u63a5\u4e0b\u6765\u5c31\u8981\u589e\u52a0oepncv\u540e\u6765\u7f16\u8bd1\u7b80\u5355\u7684\u5de5\u7a0b\u8bd5\u8bd5\u4e86\u3002<br \/>\n\u4e00\u3001\u7f16\u8bd1opencv \u5148\u4f7f\u7528cmake\u76f4\u63a5\u8fdb\u884c\u7f16\u8bd1\uff0c\u6ce8\u610f\u9009\u62e9\u76f8\u5173\u73af\u5883\u65b9\u4fbf\u751f\u6210\u76f8\u5173\u914d\u7f6e\u6587\u4ef6\u3002<br \/>\n\u6700\u540e\u6211\u7684\u751f\u6210\u73af\u5883\u5728\/usr\/local\/lib64\u4e0b\u3002\u7136\u540e\u5728pkgconfig\u6587\u4ef6\u5939\u4e0b\uff0c\u6709\u4e2aopencv.pc\u7684\u6587\u4ef6\uff0c\u8fd9\u4e2a\u6587\u4ef6\u53ef\u4ee5\u901a\u8fc7pkg-config\u8fd9\u4e2a\u5de5\u5177\u8fdb\u884c\u65b9\u4fbf\u7684\u914d\u7f6e\u3002<br \/>\n<img decoding=\"async\" title=\"image.png\" src=\"https:\/\/cache.image.guger.top\/2020\/08\/03\/2607d50d4a02f.png\" alt=\"image.png\" \/><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">vim \/etc\/profile\r\nexport PKG_CONFIG_PATH=\"\/usr\/local\/lib64\/pkgconfig:$PKG_CONFIG_PATH\"\r\n<\/pre>\n<p>\u6ce8\u610f\uff0c\u8fd9\u4e2a\u5730\u65b9\u7684\u7b49\u53f7\u4e24\u8fb9\u4e0d\u80fd\u6709\u7a7a\u683c\uff0c\u5730\u5740\u4e0d\u5305\u542b\u6587\u4ef6\u3002\u7136\u540e\u65ad\u5f00\u8fde\u63a5\u91cd\u65b0\u8fde\u63a5\u4e0a\u5373\u53ef\u3002<\/p>\n<p>\u5148\u5199\u4e2a\u7b80\u5355\u7684\u8f6c\u7070\u5ea6\u7684\u7a0b\u5e8f<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">#include &lt;stdio.h&gt;\r\n#include \"opencv2\/opencv.hpp\"\r\n#include \"opencv2\/imgproc\/imgproc.hpp\"\r\n#include \"opencv2\/imgproc\/types_c.h\"\r\nusing namespace cv;\r\n\r\n\/\/\u5c06\u56fe\u7247\u7070\u5ea6\u5316\u5e76\u4fdd\u5b58 \r\nint main()\r\n{\r\n    Mat image;\r\n    image = imread(\".\/img.jpg\");\r\n    if(!image.data)\r\n    {\r\n        printf(\"No image data \\n\");\r\n        return -1;\r\n    }else{\r\n        printf(\"read the image!\\n\");\r\n    }\r\n    Mat dst;\r\n    cvtColor(image,dst,CV_BGR2GRAY);\r\n    imwrite(\"dst.jpg\", dst);\r\n    printf(\"change success!\\n\");\r\n    return 0;\r\n}<\/pre>\n<p>\u56e0\u4e3a\u4f7f\u7528\u547d\u4ee4\u884c\uff0c\u6240\u4ee5\u5c31\u76f4\u63a5\u8f93\u5165\u8f93\u51fa\u56fe\u7247\u6d4b\u8bd5\u4e00\u4e0b\u3002<br \/>\n\u7136\u540e\u7f16\u5199Makefile\u6587\u4ef6<br \/>\n\u56e0\u4e3a\u662fc++\u6587\u4ef6\uff0c\u9700\u8981\u5f15\u7528g++\u7f16\u8bd1\u5668\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cc = g++\r\nincludes = test.o\r\n\r\nINCLUDE = $(shell pkg-config --cflags opencv)\r\nLIBS = $(shell pkg-config --libs opencv)\r\nOBJECTS =test.o\r\nSOURCE  =test.cpp\r\n\r\ntest:test.o\r\n    g++ -o test $(OBJECTS) -I $(INCLUDE) $(LIBS)\r\ntest.o : \r\n\r\n\r\nclean:\r\n    -rm $(OBJECTS) test\r\n\r\n<\/pre>\n<p>\u8fd9\u6837\u901a\u8fc7pkg-config\u5373\u53ef\u8fde\u63a5\u76f8\u5173\u5e93\u6587\u4ef6\u3002\u5e95\u4e0b\u7f16\u8bd1\u53c2\u7167<a href=\"https:\/\/www.guger.top\/index.php\/2020\/08\/03\/makefile%e7%9a%84%e5%ad%a6%e4%b9%a0\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u7b2c\u4e00\u7bc7<\/a>\u5373\u53ef\u3002<\/p>\n<p>\u7136\u540e\u8fd0\u884c\u6d4b\u8bd5\u4e00\u4e0b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cache.image.guger.top\/2020\/08\/03\/f5326bc4697b2.png\" alt=\"image.png\" title=\"image.png\" \/><br \/>\n\u6210\u529f\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u5148\u8bd5\u4e86\u8bd5\u6700\u7b80\u5355\u7684Makefile\u73af\u5883\u914d\u7f6e\uff0c\u63a5\u4e0b\u6765\u5c31\u8981\u589e\u52a0oepncv\u540e\u6765\u7f16\u8bd1\u7b80\u5355\u7684\u5de5\u7a0b\u8bd5\u8bd5\u4e86\u3002 \u4e00\u3001\u7f16\u8bd1opencv \u5148\u4f7f\u7528c &#8230;<\/p>\n","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":""},"categories":[32,3],"tags":[],"class_list":["post-191","post","type-post","status-publish","format-standard","hentry","category-linux","category-opencv"],"_links":{"self":[{"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/posts\/191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/comments?post=191"}],"version-history":[{"count":0,"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/posts\/191\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/media?parent=191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/categories?post=191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guger.top\/index.php\/wp-json\/wp\/v2\/tags?post=191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}