{"id":59,"date":"2024-05-22T19:58:33","date_gmt":"2024-05-22T11:58:33","guid":{"rendered":"http:\/\/www.anysets.tech\/?p=59"},"modified":"2025-07-24T16:28:08","modified_gmt":"2025-07-24T08:28:08","slug":"%e5%85%ab%e9%82%bb%e5%9f%9f%e5%b7%a1%e7%ba%bf","status":"publish","type":"post","link":"https:\/\/www.anysets.tech\/?p=59","title":{"rendered":"\u516b\u90bb\u57df\u5de1\u7ebf"},"content":{"rendered":"<p>\u539f\u5148\u7684\u516b\u90bb\u57df\u5df2\u7ecf\u5199\u597d\u4e86\uff0c\u6700\u8fd1\u5728\u5199\u53f3\u5706\u73af\u65f6\u53c8\u9047\u5230\u4e86\u516b\u90bb\u57df\uff0c\u4f46\u662f\u903b\u8f91\u4f3c\u4e4e\u6709\u4e9b\u6df7\u4e71\uff0c\u5728\u6b64\u518d\u6b21\u8bb0\u5f55\u4e0b\u516b\u90bb\u57df\u7684\u601d\u8def\u3002<\/p>\n<p>\u516b\u90bb\u57df\u9700\u8981\u5728\u4e00\u4e2a\u56fa\u5b9a\u8d77\u70b9\u5904\u4ee5\u4e00\u4e2a\u987a\u65f6\u9488\u6216\u8005\u9006\u65f6\u9488\u7684\u987a\u5e8f\u5bf9\u5468\u56f4\u7684\u70b9\u8fdb\u884c\u626b\u63cf\u3002\u5728\u6211\u7684\u7a0b\u5e8f\u4e2d\uff0c\u5982\u679c\u5728\u626b\u63cf\u7684\u8fc7\u7a0b\u4e2d\u53d1\u73b0\u4e00\u4e2a\u767d\u70b9\u7a81\u53d8\u4e3a\u9ed1\u70b9\uff0c\u5219\u8bf4\u660e\u627e\u5230\u4e86\u65b0\u7684\u9ed1\u7ebf\u3002\u6b64\u65f6\u8bb0\u5f55\u4e0b\u8fd9\u4e2a\u9ed1\u70b9\u7684\u4f4d\u7f6e\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u4e0b\u4e00\u4e2a\u8d77\u70b9\uff0c\u5982\u6b64\u5f80\u590d\uff0c\u76f4\u5230\u722c\u51fa\u5b8c\u6574\u7684\u8fb9\u754c\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u5728\u722c\u53d6\u8d5b\u9053\u65f6\u7684\u516b\u90bb\u57df\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-cpp\">\/\/\u8bb0\u5f55\u5de6\u8fb9\u754c\u7684\u6570\u636e\nint32_t border_location_left[border_length][2];  \/\/\u8bb0\u5f55\u8fb9\u754c\u4f4d\u7f6e\nint32_t border_count_left = 0;\nint32_t growth_direction_left[border_length];  \/\/\u8bb0\u5f55\u751f\u957f\u65b9\u5411\nint32_t growth_count_left = 0;\n\/\/\u8bb0\u5f55\u53f3\u8fb9\u754c\u7684\u6570\u636e\nint32_t border_location_right[border_length][2];  \/\/\u8bb0\u5f55\u8fb9\u754c\u4f4d\u7f6e\nint32_t border_count_right = 0;\nint32_t growth_direction_right[border_length];  \/\/\u8bb0\u5f55\u751f\u957f\u65b9\u5411\nint32_t growth_count_right = 0;\nvoid neighborSearch()\n{\n    memset(border_location_left, 0, sizeof(border_location_left));\n    memset(border_location_right, 0, sizeof(border_location_right));\n\n    int32_t neighbor_left[9][2] = {{-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {-1, 1}};\n    int32_t neighbor_right[9][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}};\n    border_count_left = 1;\n    growth_count_left = 1;\n    border_count_right = 1;\n    growth_count_right = 1;\n    \/\/\u628a\u8d77\u70b9\u52a0\u8fdb\u53bb\n    border_location_left[0][0] = start_point_l[0];\n    border_location_left[0][1] = start_point_l[1];\n    border_location_right[0][0] = start_point_r[0];\n    border_location_right[0][1] = start_point_r[1];\n    for (int j = 0; j &lt; border_length-1; j++)\n    {\n        \/\/\u5de6\u8fb9\u754c\u90e8\u5206\n        \/*\n            [2]  [1]  [0\/8]\n\n            [3]  [ ]  [7]\n\n            [4]  [5]  [6]\n        *\/\n        \/\/ printf(&quot;%d\\n&quot;, j);\n        for (int i = 0; i &lt; 8; i++)\n        {\n            if (bin_image[start_point_l[0] + neighbor_left[i][0]][start_point_l[1] + neighbor_left[i][1]] == 255 &amp;&amp; bin_image[start_point_l[0] + neighbor_left[i+1][0]][start_point_l[1] + neighbor_left[i+1][1]] == 0)\n            {\n                \/\/ printf(&quot;h=%d\\n&quot;, bin_image[start_point_l[0] + neighbor_left[i][0]][start_point_l[1] + neighbor_left[i][1]]);\n                \/\/ printf(&quot;h=%d\\n&quot;, bin_image[start_point_l[0] + neighbor_left[i+1][0]][start_point_l[1] + neighbor_left[i+1][1]]);\n                growth_direction_left[growth_count_left] = i;\n                growth_count_left++;\n                start_point_l[0] = start_point_l[0] + neighbor_left[i+1][0];\n                start_point_l[1] = start_point_l[1] + neighbor_left[i+1][1];\n                border_location_left[border_count_left][0] = start_point_l[0];\n                border_location_left[border_count_left][1] = start_point_l[1];\n                border_count_left++;\n                \/\/ printf(&quot;New Left Start Point: %d, %d\\n&quot;, start_point_l[0], start_point_l[1]);\n                \/\/ printf(&quot;finished\\n&quot;);\n                \/\/ printf(&quot;%d\\n&quot;, j);\n                break;\n            }\n        }\n        \/\/\u53f3\u8fb9\u754c\u90e8\u5206\n        \/*\n            [0\/8]  [1]  [2]\n\n            [7]  [ ]  [3]\n\n            [6]  [5]  [4]\n        *\/\n        for (int i = 0; i &lt; 8; i++)\n        {\n            if (bin_image[start_point_r[0] + neighbor_right[i][0]][start_point_r[1] + neighbor_right[i][1]] == 255  &amp;&amp; (bin_image[start_point_r[0] + neighbor_right[i+1][0]][start_point_r[1] + neighbor_right[i+1][1]] == 0 || bin_image[start_point_r[0] + neighbor_right[i+1][0]][start_point_r[1] + neighbor_right[i+1][1]] == 151))\n            {\n                growth_direction_right[growth_count_right] = i;\n                growth_count_right++;\n\n                border_location_right[border_count_right][0] = start_point_r[0] + neighbor_right[i+1][0];\n                border_location_right[border_count_right][1] = start_point_r[1] + neighbor_right[i+1][1];\n                \/\/ bin_image[start_point_r[0] + neighbor_right[i+1][0]][start_point_r[1] + neighbor_right[i+1][1]] = 151;\n                start_point_r[0] = start_point_r[0] + neighbor_right[i+1][0];\n                start_point_r[1] = start_point_r[1] + neighbor_right[i+1][1];\n                border_count_right++;\n                break;\n            }\n        }\n        \/\/\u5f53\u4e24\u7ebf\u4ea4\u6c47\u65f6\u505c\u6b62\u641c\u7ebf\n        if ((j != 0 &amp;&amp; j != border_length-1) &amp;&amp; \n        ((border_location_left[j][0] == border_location_right[j][0] &amp;&amp; border_location_left[j][1] == border_location_right[j][1])\n        || (border_location_left[j+1][0] == border_location_right[j-1][0] &amp;&amp; border_location_left[j+1][1] == border_location_right[j-1][1])\n        || (border_location_left[j-1][0] == border_location_right[j+1][0] &amp;&amp; border_location_left[j-1][1] == border_location_right[j+1][1])))\n        {\n            break;\n        }\n    }\n}<\/code><\/pre>\n<p>\u5728\u53f3\u5706\u73af\u7684\u516b\u90bb\u57df\u4e2d\uff0c\u4e0d\u9700\u8981\u8bb0\u5f55\u4e0b\u6bcf\u4e00\u4e2a\u9ed1\u70b9\u7684\u4f4d\u7f6e\uff0c\u56e0\u4e3a\u6211\u4eec\u53ea\u9700\u8981\u5706\u73af\u6700\u5de6\u4fa7\u70b9\u7684\u4f4d\u7f6e\u3002<\/p>\n<p>\u4e0e\u4e0a\u9762\u76f8\u540c\uff0c\u6bcf\u4e00\u4e2a\u8d77\u70b9\u6211\u4eec\u90fd\u9700\u8981\u81f3\u591a\u626b\u63cf\u516b\u6b21\uff0c\u628a\u5468\u56f4\u70b9\u90fd\u626b\u63cf\u4e00\u904d\u4ee5\u68c0\u67e5\u7a81\u53d8\u3002\u5982\u679c\u626b\u63cf\u5230\u7a81\u53d8\u70b9\uff0c\u76f4\u63a5\u9000\u51fa\u5f53\u524d\u7684\u5faa\u73af\uff0c\u8bb0\u5f55\u5e76\u5f00\u59cb\u4e0b\u4e00\u6b21\u5faa\u73af\u3002\u6bcf\u6b21\u5faa\u73af\u7ed3\u675f\u540e\u68c0\u67e5\u722c\u53d6\u5230\u7684\u70b9\u662f\u5426\u5728\u539f\u8d77\u70b9\u7684\u53f3\u4fa7\uff0c\u5982\u679c\u662f\uff0c\u5219\u9000\u51fa\u5faa\u73af\u3002<\/p>\n<p>\u51fa\u95ee\u9898\u7684\u539f\u56e0\u4e5f\u627e\u51fa\u6765\u4e86\uff0c\u6211\u5c06\u4e00\u90e8\u5206\u7684\u70b9\u6807\u8bb0\u4e3a\u4e86152\uff0c\u800c\u6211\u5728\u627e\u516b\u90bb\u57df\u65f6\u7684\u6761\u4ef6\u4e3a\u4ece255\u52300\uff0c\u8fd9\u4f7f\u7a0b\u5e8f\u5728\u627e\u516b\u90bb\u57df\u65f6\u5982\u679c\u9047\u5230\u4e86\u88ab\u6211\u6807\u8bb0\u4e3a152\u7684\u70b9\uff0c\u7a0b\u5e8f\u5c06\u4e00\u76f4\u5728\u90a3\u91cc\u5faa\u73af\uff0c\u5c06\u6807\u8bb0\u89e3\u9664\u540e\u6062\u590d\u4e86\u6b63\u5e38\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u5148\u7684\u516b\u90bb\u57df\u5df2\u7ecf\u5199\u597d\u4e86\uff0c\u6700\u8fd1\u5728\u5199\u53f3\u5706\u73af\u65f6\u53c8\u9047\u5230\u4e86\u516b\u90bb\u57df\uff0c\u4f46\u662f\u903b\u8f91\u4f3c\u4e4e\u6709\u4e9b\u6df7\u4e71\uff0c\u5728\u6b64\u518d\u6b21\u8bb0\u5f55\u4e0b\u516b\u90bb\u57df\u7684\u601d\u8def\u3002 \u516b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-59","post","type-post","status-publish","format-standard","hentry","category-8"],"_links":{"self":[{"href":"https:\/\/www.anysets.tech\/index.php?rest_route=\/wp\/v2\/posts\/59","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.anysets.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.anysets.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.anysets.tech\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.anysets.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=59"}],"version-history":[{"count":4,"href":"https:\/\/www.anysets.tech\/index.php?rest_route=\/wp\/v2\/posts\/59\/revisions"}],"predecessor-version":[{"id":63,"href":"https:\/\/www.anysets.tech\/index.php?rest_route=\/wp\/v2\/posts\/59\/revisions\/63"}],"wp:attachment":[{"href":"https:\/\/www.anysets.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anysets.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anysets.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}