After reading an inspiration of the inspection of the connection between the connection pathway, the following code is listed as follows: // Lianlian Road Detection Algorithm
// # include
INT Main () {// Map Set Short Mapx = 6, MAPY = 5; // (To Improve) Horizontal Variation Short Map [5] [6] = {0, 0, 0, 0, 0, 0, 0, 1, 3, 2, 3, 0, 0, 2, 2, 1, 2, 0, 0, 1, 3, 1, 3, 0, 0, 0, 0, 0, 0, 0) ;
/ / Set the selected coordinate // (To improve) To detect whether the position is the same, the value is the same Short set1x = 4, set1y = 1, set2x = 2, set2y = 3;
// Process // Longitudinal Processing // Cache Initial // (To Improve) Cache Length Short Set1Bufy [6] [2] = {0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0}; Short set2bufy [6] [2] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
// Based on the cache set1bufy [0] [0] = set1x; set1bufy [0] [1] = set1Y; set2bufy [0] [0] = set2x; set2bufy [0] [1] = set2y; // longitudinal detection : Basic point 1 SHORT NBUFY = 1; for (short tmpy = set1y - 1; tmpy> = 0; --TMPY) {if (MAP [TMPY] [set1x] == 0) {set1bufy [nbufy] [0] = Set1x; set1bufy [nbufy] [1] = tmpy; nbufy;} else {breaf;}}}
// Longitudinal detection: base point 1 below for (short tmpy = set1y 1; tmpy // Longitudinal detection: base point 2 or more nbufy = 1; for (short tmpy = set2y - 1; tmpy> = 0; --TMPY) {IF (MAP [TMPY] [SET2X] == 0) {set2bufy [nbufy] [ 0] = set2x; set2bufy [nbufy] [1] = tmpy; nbufy;} else {breaf;}}} // Longitudinal detection: base point 2 below for (short tmpy = set2y 1; tmpy // debug // cout << "Enter x for 1" << ENDL; For (Short nchklink2 = 0;! (set2bufy [nchklink2] [0] == 0 && set2bufy [nchklink2] [1] == 0); nchklink2) {// debug // cout << "Enter x for 2 << endl; // Detection whether it is in the same horizontal axis IF (set1bufy [nchklink1] [1] == set2bufy [nchklink2] [1]) {// Since the coaxial point has been checked, the coaxial contrast acceleration check mark is true bshortpass = True; // debug // cout << "Enter x for 2-if" << Endl; // Calculate the interpolation distance short nstep = set1bufy [nchklink1] [0] - set2bufy [nchklink2] [0]; // Offset Short OPNUM; IF (NSTEP> 0) {OPNUM = -1; --NSTEP; } Else {opnum = 1; nstep; BCHKOK = TRUE; Short Tmpvy = set1bufy [nchklink1] [1]; for (short mstep = nstep; mstep! = 0; mstep = opnum) {// debug // cout << "Enter x for 3" << ENDL ; IF (MAP [Tmpvy] [set1bufy [nchklink1] [0] - mstep] == 0) {// Continue detection Next:} else {// pathway has an obstacle to connect BCHKOK = FALSE; BREAK;}} // If the passage is connected, connect information if (bchkok == true) {// cout << "Linked." << Endl; Printf ("% s", "linked / n"); return 0;}} else {/ / Judgment the coaxial contrast acceleration check mark to implement inspection acceleration IF (bshortpass == true) {// debug // cout << "Enter shortpass << ENDL; Break;}}}}} / / Longitudinal processing // Transverse processing // Cache initial // (To improve) The cache length should be able to set Short set1bufx [7] [2] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0}; Short set2bufx [7] [2] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // Based on the cache set1bufx [0] [0] = set1x; set1bufx [0] [1] = set1y; set2bufx [0] [0] = set2x; set2bufx [0] [1] = set2y; // lateral detection : Basic point 1 with left Short Nbufx = 1; for (short tmpx = set1x - 1; tmpx> = 0; --TMPX) {if (Map [set1y] [tmpx] == 0) {set1bufx [nbufx] [0] = TMPX; set1bufx [nbufx] [1] = set1y; nbufx;} else {breaf;}}} // Transverse detection: base point 1 with right for (short tmpx = set1x 1; tmpx // lateral detection: base point 2 with left nbufx = 1; for (short tmpx = set2x - 1; tmpx> = 0; --TMPX) {IF (Map [set2y] [tmpx] == 0) {set2bufx [nbufx] [0] = TMPX; set2bufx [nbufx] [1] = set2y; nbufx;} else {breaf;}} // Transverse detection: Base point 2 with right for (short tmpx = set2x 1; tmpx // debug // cout << "Enter x for 1" << ENDL; For (Short nchklink2 = 0;! (set2bufx [nchklink2] [0] == 0 && set2bufx [nchklink2] [1] == 0); nchklink2) {// debug // cout << "Enter x for 2 << endl; / / Detection whether it is in the same vertical axis IF (set1bufx [nchklink1] [0] == set2bufx [nchklink2] [0]) {// Since the coaxial point has been checked, the coaxial contrast acceleration check mark is true bshortpass = True; // debug // cout << "Enter x for 2-if" << Endl; // Calculate the interpolation distance short nstep = set1bufx [nchklink1] [1] - set2bufx [nchklink2] [1]; // Offset Short OPNUM; IF (NSTEP> 0) {OPNUM = -1; --NSTEP; } Else {opnum = 1; nstep; BCHKOK = TRUE; Short Tmpvx = set1bufx [nchklink1] [0]; for (short mstep = nstep; mstep! = 0; mstep = opnum) {// debug // cout << "Enter x for 3" << ENDL ; IF (MAP [set1bufx [nchklink1] [1] - mstep] [TMPVX] == 0) {// Continue detection Next Continue;} else {// pathway has obstacles unable to connect BCHKOK = FALSE; BREAK;}} // If the passage is connected, the communication information IF (bchkok == true) {// cout << "Linked." << endl; printf ("linked / n"); return 0;}} else {// judgment coaxial comparison Accelerate check mark to implement check Acceleration IF (bshortpass == true) {// debug // cout << "Enter shortpass" << ENDL; Break;}}}}} // lateral processing // Processing process / / If the path cannot be connected, it is displayed that the information IF (bchkok == false) {// cout << "unlinked." << Endl; Printf ("% s", "unlinked / n");} Return 0;}