{"id":221280,"date":"2021-07-02T09:45:45","date_gmt":"2021-07-02T01:45:45","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=221280"},"modified":"2021-06-25T09:46:52","modified_gmt":"2021-06-25T01:46:52","slug":"opencv-separable-filtering","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/opencv-separable-filtering.html","title":{"rendered":"\u8be6\u7ec6\u4ecb\u7ecdOpenCV\u5b9e\u73b0\u53ef\u5206\u79bb\u6ee4\u6ce2"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4e3a\u5927\u5bb6\u8be6\u7ec6\u4ecb\u7ecd\u4e86OpenCV\u5b9e\u73b0\u53ef\u5206\u79bb\u6ee4\u6ce2\uff0c\u6587\u4e2d\u793a\u4f8b\u4ee3\u7801\u4ecb\u7ecd\u7684\u975e\u5e38\u8be6\u7ec6\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u611f\u5174\u8da3\u7684\u5c0f\u4f19\u4f34\u4eec\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u81ea\u5b9a\u4e49\u6ee4\u6ce2<\/strong><\/div>\n

\u65e0\u8bba\u662f\u56fe\u50cf\u5377\u79ef\u8fd8\u662f\u6ee4\u6ce2\uff0c\u5728\u539f\u56fe\u50cf\u4e0a\u79fb\u52a8\u6ee4\u6ce2\u5668\u7684\u8fc7\u7a0b\u4e2d\u6bcf\u4e00\u6b21\u7684\u8ba1\u7b97\u7ed3\u679c\u90fd\u4e0d\u4f1a\u5f71\u54cd\u5230\u540e\u9762\u8fc7\u7a0b\u7684\u8ba1\u7b97\u7ed3\u679c\uff0c\u56e0\u6b64\u56fe\u50cf\u6ee4\u6ce2\u662f\u4e00\u4e2a\u5e76\u884c\u7684\u7b97\u6cd5\uff0c\u5728\u53ef\u4ee5\u63d0\u4f9b\u5e76\u884c\u8ba1\u7b97\u7684\u5904\u7406\u5668\u4e2d\u53ef\u4ee5\u6781\u5927\u7684\u52a0\u5feb\u56fe\u50cf\u6ee4\u6ce2\u7684\u5904\u7406\u901f\u5ea6\u3002<\/p>\n

\u56fe\u50cf\u6ee4\u6ce2\u8fd8\u5177\u6709\u53ef\u5206\u79bb\u6027<\/strong><\/div>\n

\u5148\u5bf9X\uff08Y\uff09\u65b9\u5411\u6ee4\u6ce2\uff0c\u518d\u5bf9Y\uff08X\uff09\u65b9\u5411\u6ee4\u6ce2\u7684\u7ed3\u679c\u4e0e\u5c06\u4e24\u4e2a\u65b9\u5411\u7684\u6ee4\u6ce2\u5668\u8054\u5408\u540e\u6574\u4f53\u6ee4\u6ce2\u7684\u7ed3\u679c\u76f8\u540c\u3002\u4e24\u4e2a\u65b9\u5411\u7684\u6ee4\u6ce2\u5668\u7684\u8054\u5408\u5c31\u662f\u5c06\u4e24\u4e2a\u65b9\u5411\u7684\u6ee4\u6ce2\u5668\u76f8\u4e58\uff0c\u5f97\u5230\u4e00\u4e2a\u77e9\u5f62\u7684\u6ee4\u6ce2\u5668<\/p>\n

\"\"<\/p>\n

\r\nvoid filter2D( InputArray src, OutputArray dst, int ddepth,\r\n                            InputArray kernel, Point anchor = Point(-1,-1),\r\n                            double delta = 0, int borderType = BORDER_DEFAULT );\r\n<\/pre>\n
    \n
  • src\uff1a\u5f85\u6ee4\u6ce2\u56fe\u50cf<\/li>\n
  • dst\uff1a\u8f93\u51fa\u56fe\u50cf\uff0c\u4e0e\u8f93\u5165\u56fe\u50cfsrc\u5177\u6709\u76f8\u540c\u7684\u5c3a\u5bf8\u3001\u901a\u9053\u6570\u548c\u6570\u636e\u7c7b\u578b\u3002<\/li>\n
  • ddepth\uff1a\u8f93\u51fa\u56fe\u50cf\u7684\u6570\u636e\u7c7b\u578b\uff08\u6df1\u5ea6\uff09\uff0c\u6839\u636e\u8f93\u5165\u56fe\u50cf\u7684\u6570\u636e\u7c7b\u578b\u4e0d\u540c\u62e5\u6709\u4e0d\u540c\u7684\u53d6\u503c\u8303\u56f4\uff0c\u5177\u4f53\u7684\u53d6\u503c\u8303\u56f4\u5728\u88685-1\u7ed9\u51fa\uff0c\u5f53\u8d4b\u503c\u4e3a-1\u65f6\uff0c\u8f93\u51fa\u56fe\u50cf\u7684\u6570\u636e\u7c7b\u578b\u81ea\u52a8\u9009\u62e9\u3002<\/li>\n
  • kernel\uff1a\u6ee4\u6ce2\u5668\u3002<\/li>\n
  • anchor\uff1a\u5185\u6838\u7684\u57fa\u51c6\u70b9(\u951a\u70b9)\uff0c\u5176\u9ed8\u8ba4\u503c\u4e3a(-1,-1)\u4ee3\u8868\u5185\u6838\u57fa\u51c6\u70b9\u4f4d\u4e8ekernel\u7684\u4e2d\u5fc3\u4f4d\u7f6e\u3002\u57fa\u51c6\u70b9\u5373\u5377\u79ef\u6838\u4e2d\u4e0e\u8fdb\u884c\u5904\u7406\u7684\u50cf\u7d20\u70b9\u91cd\u5408\u7684\u70b9\uff0c\u5176\u4f4d\u7f6e\u5fc5\u987b\u5728\u5377\u79ef\u6838\u7684\u5185\u90e8\u3002<\/li>\n
  • delta\uff1a\u504f\u503c\uff0c\u5728\u8ba1\u7b97\u7ed3\u679c\u4e2d\u52a0\u4e0a\u504f\u503c\u3002<\/li>\n
  • borderType\uff1a\u50cf\u7d20\u5916\u63a8\u6cd5\u9009\u62e9\u6807\u5fd7\uff0c\u53d6\u503c\u8303\u56f4\u5728\u88683-5\u4e2d\u7ed9\u51fa\u3002\u9ed8\u8ba4\u53c2\u6570\u4e3aBORDER_DEFAULT\uff0c\u8868\u793a\u4e0d\u5305\u542b\u8fb9\u754c\u503c\u5012\u5e8f\u586b\u5145\u3002<\/li>\n<\/ul>\n
    \r\nvoid sepFilter2D( InputArray src, OutputArray dst, int ddepth,\r\n                               InputArray kernelX, InputArray kernelY,\r\n                               Point anchor = Point(-1,-1),\r\n                               double delta = 0, int borderType = BORDER_DEFAULT );\r\n<\/pre>\n
      \n
    • src\uff1a\u5f85\u6ee4\u6ce2\u56fe\u50cf<\/li>\n
    • dst\uff1a\u8f93\u51fa\u56fe\u50cf\uff0c\u4e0e\u8f93\u5165\u56fe\u50cfsrc\u5177\u6709\u76f8\u540c\u7684\u5c3a\u5bf8\u3001\u901a\u9053\u6570\u548c\u6570\u636e\u7c7b\u578b\u3002<\/li>\n
    • ddepth\uff1a\u8f93\u51fa\u56fe\u50cf\u7684\u6570\u636e\u7c7b\u578b\uff08\u6df1\u5ea6\uff09\uff0c\u6839\u636e\u8f93\u5165\u56fe\u50cf\u7684\u6570\u636e\u7c7b\u578b\u4e0d\u540c\u62e5\u6709\u4e0d\u540c\u7684\u53d6\u503c\u8303\u56f4\uff0c\u5177\u4f53\u7684\u53d6\u503c\u8303\u56f4\u5728\u88685-1\u7ed9\u51fa\uff0c\u5f53\u8d4b\u503c\u4e3a-1\u65f6\uff0c\u8f93\u51fa\u56fe\u50cf\u7684\u6570\u636e\u7c7b\u578b\u81ea\u52a8\u9009\u62e9\u3002<\/li>\n
    • kernelX\uff1aX\u65b9\u5411\u7684\u6ee4\u6ce2\u5668\uff0c<\/li>\n
    • kernelY\uff1aY\u65b9\u5411\u7684\u6ee4\u6ce2\u5668\u3002<\/li>\n
    • anchor\uff1a\u5185\u6838\u7684\u57fa\u51c6\u70b9(\u951a\u70b9)\uff0c\u5176\u9ed8\u8ba4\u503c\u4e3a(-1,-1)\u4ee3\u8868\u5185\u6838\u57fa\u51c6\u70b9\u4f4d\u4e8ekernel\u7684\u4e2d\u5fc3\u4f4d\u7f6e\u3002\u57fa\u51c6\u70b9\u5373\u5377\u79ef\u6838\u4e2d\u4e0e\u8fdb\u884c\u5904\u7406\u7684\u50cf\u7d20\u70b9\u91cd\u5408\u7684\u70b9\uff0c\u5176\u4f4d\u7f6e\u5fc5\u987b\u5728\u5377\u79ef\u6838\u7684\u5185\u90e8\u3002<\/li>\n
    • delta\uff1a\u504f\u503c\uff0c\u5728\u8ba1\u7b97\u7ed3\u679c\u4e2d\u52a0\u4e0a\u504f\u503c\u3002<\/li>\n
    • borderType\uff1a\u50cf\u7d20\u5916\u63a8\u6cd5\u9009\u62e9\u6807\u5fd7\uff0c\u53d6\u503c\u8303\u56f4\u5728\u88683-5\u4e2d\u7ed9\u51fa\u3002\u9ed8\u8ba4\u53c2\u6570\u4e3aBORDER_DEFAULT\uff0c\u8868\u793a\u4e0d\u5305\u542b\u8fb9\u754c\u503c\u5012\u5e8f\u586b\u5145\u3002<\/li>\n<\/ul>\n
      \u7b80\u5355\u793a\u4f8b<\/strong><\/div>\n
      \r\n\/\/\r\n\/\/ Created by smallflyfly on 2021\/6\/15.\r\n\/\/\r\n  \r\n#include \"opencv2\/highgui.hpp\"\r\n#include \"opencv2\/opencv.hpp\"\r\n  \r\n#include \r\n  \r\nusing namespace std;\r\nusing namespace cv;\r\n  \r\nint main() {\r\n    float points[] = {\r\n            1, 2, 3, 4, 5,\r\n            6, 7, 8, 9, 10,\r\n            11, 12, 13, 14, 15,\r\n            16, 17, 18, 19, 20,\r\n            21, 22, 23, 24, 25\r\n    };\r\n    Mat data(5, 5, CV_32FC1, points);\r\n  \r\n    \/\/ \u9a8c\u8bc1\u9ad8\u65af\u6ee4\u6ce2\u5668\u53ef\u5206\u79bb\r\n    Mat gaussX = getGaussianKernel(3, 1);\r\n    cout << gaussX << endl;\r\n    Mat gaussDstData, gaussDataXY;\r\n    GaussianBlur(data, gaussDstData, Size(3, 3), 1, 1, BORDER_CONSTANT);\r\n    sepFilter2D(data, gaussDataXY, -1, gaussX, gaussX, Point(-1, -1), 0, BORDER_CONSTANT);\r\n    cout << gaussDstData << endl;\r\n    cout << gaussDataXY << endl;\r\n    cout << \"######################################\" << endl;\r\n  \r\n    \/\/ Y\u65b9\u5411\u4e0a\u6ee4\u6ce2\r\n    Mat a = (Mat_(3, 1) << -1, 3, -1);\r\n    \/\/ X\u65b9\u5411\u4e0a\u6ee4\u6ce2\r\n    Mat b = a.reshape(1, 1);\r\n    \/\/ XY\u8054\u5408\u6ee4\u6ce2\r\n    Mat ab = a * b;\r\n    Mat dataX, dataY, dataXY1, dataXY2, dataSepXY;\r\n    filter2D(data, dataX, -1, b);\r\n    filter2D(dataX, dataXY1, -1, a);\r\n    filter2D(data, dataXY2, -1, ab);\r\n    sepFilter2D(data, dataSepXY, -1, a, b);\r\n  \r\n    \/\/ \u9a8c\u8bc1\u7ed3\u679c\r\n    cout << dataXY1 << endl;\r\n    cout << dataXY2 << endl;\r\n    cout << dataSepXY << endl;\r\n  \r\n    Mat im = imread(\"test.jpg\");\r\n    resize(im, im, Size(0, 0), 0.5, 0.5);\r\n  \r\n    Mat imX, imY, imXY, imSepXY;\r\n    filter2D(im, imX, -1, b);\r\n    filter2D(imX, imXY, -1, a);\r\n    sepFilter2D(im, imSepXY, -1, a, b);\r\n  \r\n    imshow(\"imXY\", imXY);\r\n    imshow(\"imSepXY\", imSepXY);\r\n  \r\n    waitKey(0);\r\n    destroyAllWindows();\r\n  \r\n    return 0;\r\n  \r\n}\r\n<\/float><\/iostream><\/pre>\n","protected":false},"excerpt":{"rendered":"

      \u65e0\u8bba\u662f\u56fe\u50cf\u5377\u79ef\u8fd8\u662f\u6ee4\u6ce2\uff0c\u5728\u539f\u56fe\u50cf\u4e0a\u79fb\u52a8\u6ee4\u6ce2\u5668\u7684\u8fc7\u7a0b\u4e2d\u6bcf\u4e00\u6b21\u7684\u8ba1\u7b97\u7ed3\u679c\u90fd\u4e0d\u4f1a\u5f71\u54cd\u5230\u540e\u9762\u8fc7\u7a0b\u7684\u8ba1\u7b97\u7ed3\u679c\uff0c\u56e0\u6b64\u56fe\u50cf\u6ee4 […]<\/p>\n","protected":false},"author":362,"featured_media":221282,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-221280","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/221280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/362"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=221280"}],"version-history":[{"count":1,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/221280\/revisions"}],"predecessor-version":[{"id":221283,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/221280\/revisions\/221283"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/221282"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=221280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=221280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=221280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}