├── main.cpp ├── matrix.h ├── model.txt ├── tracer.h ├── martix.cpp ├── similarity.h ├── tracer.cpp ├── ReadDataFile.h ├── similarity.cpp ├── threeD2twoD.h ├── lineTriangleInsect.cpp ├── LineTriangleIntersect.h ├── 3D Model-based Tracking Using Edge and Keypoint Features_1.pdf ├── occlusion clutter and illumination invariant object recognition.pdf ├── ReadDataFile.cpp └── threeD2twoD.cpp /main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fatherworld/CAD_TRACKER/HEAD/main.cpp -------------------------------------------------------------------------------- /matrix.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fatherworld/CAD_TRACKER/HEAD/matrix.h -------------------------------------------------------------------------------- /model.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fatherworld/CAD_TRACKER/HEAD/model.txt -------------------------------------------------------------------------------- /tracer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fatherworld/CAD_TRACKER/HEAD/tracer.h -------------------------------------------------------------------------------- /martix.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fatherworld/CAD_TRACKER/HEAD/martix.cpp -------------------------------------------------------------------------------- /similarity.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fatherworld/CAD_TRACKER/HEAD/similarity.h -------------------------------------------------------------------------------- /tracer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fatherworld/CAD_TRACKER/HEAD/tracer.cpp -------------------------------------------------------------------------------- /ReadDataFile.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fatherworld/CAD_TRACKER/HEAD/ReadDataFile.h -------------------------------------------------------------------------------- /similarity.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fatherworld/CAD_TRACKER/HEAD/similarity.cpp -------------------------------------------------------------------------------- /threeD2twoD.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fatherworld/CAD_TRACKER/HEAD/threeD2twoD.h -------------------------------------------------------------------------------- /lineTriangleInsect.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fatherworld/CAD_TRACKER/HEAD/lineTriangleInsect.cpp -------------------------------------------------------------------------------- /LineTriangleIntersect.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fatherworld/CAD_TRACKER/HEAD/LineTriangleIntersect.h -------------------------------------------------------------------------------- /3D Model-based Tracking Using Edge and Keypoint Features_1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fatherworld/CAD_TRACKER/HEAD/3D Model-based Tracking Using Edge and Keypoint Features_1.pdf -------------------------------------------------------------------------------- /occlusion clutter and illumination invariant object recognition.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fatherworld/CAD_TRACKER/HEAD/occlusion clutter and illumination invariant object recognition.pdf -------------------------------------------------------------------------------- /ReadDataFile.cpp: -------------------------------------------------------------------------------- 1 | #include "ReadDataFile.h" 2 | #pragma warning(disable:4996) 3 | int ReadTestData(ForMatrix* OutForMartix) 4 | { 5 | int ret = 0; 6 | if (!OutForMartix) 7 | { 8 | ret = -1; 9 | return ret; 10 | } 11 | FILE* fp; 12 | fp = fopen("E:\\model.txt", "rb"); 13 | int i = 0; 14 | if (!fp) 15 | { 16 | ret = -2; 17 | return ret; 18 | } 19 | fseek(fp, 0, SEEK_END); 20 | long byte_struct = ftell(fp); 21 | fseek(fp, 0, SEEK_SET); 22 | int sizeofStruct = sizeof(ForMatrix); 23 | printf("num of Struct is %d", byte_struct / sizeofStruct); 24 | 25 | ret = fread(OutForMartix, byte_struct, 1, fp); 26 | 27 | if (OutForMartix) 28 | { 29 | free(OutForMartix); 30 | OutForMartix = NULL; 31 | } 32 | return ret; 33 | } -------------------------------------------------------------------------------- /threeD2twoD.cpp: -------------------------------------------------------------------------------- 1 | #include "threeD2twoD.h" 2 | #include 3 | using namespace std; 4 | 5 | 6 | //此时的世界坐标系转换的时候只需要将世界坐标Xw和Yw除以Zw就可以了 7 | 8 | //三维坐标到二维坐标的转换 9 | int three2two(threespace worldCoords, MARTIX InternalRef, MARTIX OutRef, twospace* pixCoords, float scale) 10 | { 11 | int ret = 0; 12 | MARTIX tempWorldmartix; 13 | tempWorldmartix.cols = 1; 14 | tempWorldmartix.rows = 4; 15 | tempWorldmartix.martix = (float*)malloc(sizeof(float) * 4); 16 | tempWorldmartix.martix[0] = worldCoords.real_x; 17 | tempWorldmartix.martix[1] = worldCoords.real_y; 18 | tempWorldmartix.martix[2] = worldCoords.real_z; 19 | tempWorldmartix.martix[3] = 1; 20 | MARTIX* output_martix = (MARTIX*)malloc(sizeof(MARTIX)); 21 | output_martix->martix = (float*)malloc(sizeof(float)*output_martix->cols*output_martix->rows); 22 | ret= mul_maritx(InternalRef,OutRef,output_martix); 23 | if (!ret) 24 | { 25 | printf("矩阵相乘出错"); 26 | goto end; 27 | } 28 | ret = mul_maritx(*output_martix, tempWorldmartix, output_martix); 29 | if (!ret) 30 | { 31 | printf("矩阵相乘出错"); 32 | goto end; 33 | } 34 | pixCoords->real_x = output_martix->martix[0]; 35 | pixCoords->real_y = output_martix->martix[1 * output_martix->cols]; 36 | 37 | end: 38 | if (!tempWorldmartix.martix) 39 | { 40 | free(tempWorldmartix.martix); 41 | tempWorldmartix.martix = NULL; 42 | } 43 | 44 | if (!output_martix) 45 | { 46 | if (!output_martix->martix) 47 | { 48 | free(output_martix->martix); 49 | output_martix->martix = NULL; 50 | } 51 | free(output_martix); 52 | output_martix = NULL; 53 | } 54 | return ret; 55 | } 56 | 57 | 58 | //图像的灰度化 59 | int picTogray(unsigned char* intput_data, int width, int height, int channels,unsigned char* output_data) 60 | { 61 | int ret = 0; 62 | 63 | if (!intput_data) 64 | { 65 | ret = -1; 66 | printf("输入的图片信息不能为空"); 67 | return ret; 68 | } 69 | 70 | for (int i = 0; i < height; i++) 71 | { 72 | for (int j = 0; j < width; j++) 73 | { 74 | float gray = 0; 75 | for (int k = 0; k < channels; k++) 76 | { 77 | float left_num = 0.0; 78 | switch (k) 79 | { 80 | case 0: 81 | { 82 | left_num = 0.11; 83 | break; 84 | } 85 | case 1: 86 | { 87 | left_num = 0.59; 88 | break; 89 | } 90 | case 2: 91 | { 92 | left_num = 0.3; 93 | break; 94 | } 95 | default: 96 | left_num = 0.0; 97 | break; 98 | } 99 | gray += left_num*intput_data[i*width *channels + j * channels + k]; 100 | } 101 | output_data[i*width + j] =(int)gray; 102 | } 103 | } 104 | } 105 | 106 | 107 | //图像的归一化 108 | int grayHist(unsigned char* intput_data, int width, int height, float* output_data) 109 | { 110 | int ret = 0; 111 | if (!intput_data) 112 | { 113 | ret = -1; 114 | printf("输入的图片不能为空"); 115 | return ret; 116 | } 117 | for (int i = 0; i < height; i++) 118 | { 119 | for (int j = 0; j < width; j++) 120 | output_data[i*width + j] = (float)((int)intput_data[i*width + j]/ 255.0); 121 | } 122 | return ret; 123 | } 124 | 125 | 126 | //梯度计算结果 127 | int gaussianFilter(float* input_data, int width, int height, float* gradientResult) 128 | { 129 | int ret = 0; 130 | if (!input_data || !gradientResult) 131 | { 132 | ret = -1; 133 | printf("输入或者输出不能为空"); 134 | return ret; 135 | } 136 | 137 | MARTIX Convolve3x; 138 | 139 | //构造一个3*3索贝尔卷积 140 | Convolve3x.cols = 3; 141 | Convolve3x.rows = 3; 142 | Convolve3x.martix = (float*)malloc(sizeof(float) * 9); 143 | Convolve3x.martix[0] = -1.0; 144 | Convolve3x.martix[1] = 0.0; 145 | Convolve3x.martix[2] = 1.0; 146 | Convolve3x.martix[3] = -2.0; 147 | Convolve3x.martix[4] = 0.0; 148 | Convolve3x.martix[5] = 2.0; 149 | Convolve3x.martix[6] = -1.0; 150 | Convolve3x.martix[7] = 0.0; 151 | Convolve3x.martix[8] = 1.0; 152 | 153 | for (int i = 0; i < height; i++) 154 | { 155 | for (int j = 0; j < width; j++) 156 | { 157 | int prei = i - 1; 158 | int prej = j - 1; 159 | int nxti = i + 1; 160 | int nxtj = j + 1; 161 | 162 | if (i == 0 ) 163 | { 164 | prei = i + 1; 165 | nxti = i + 2; 166 | } 167 | if (i == height-1) 168 | { 169 | prei = i - 2; 170 | nxti = i - 1; 171 | } 172 | if (j == 0) 173 | { 174 | prej = j + 1; 175 | nxtj = j + 2; 176 | } 177 | if (j == width-1) 178 | { 179 | prej = j - 2; 180 | nxtj = j - 1; 181 | } 182 | 183 | 184 | //计算dx 185 | gradientResult[i*width*4 + j*4 + 0] =(Convolve3x.martix[0] * input_data[prei*width + prej] + Convolve3x.martix[1] * input_data[prei*width + j] + 186 | Convolve3x.martix[2] * input_data[prei*width + nxtj] + Convolve3x.martix[3] * input_data[i*width + prej] + Convolve3x.martix[4] * input_data[i*width + j] 187 | + Convolve3x.martix[5] * input_data[i*width + nxtj] + Convolve3x.martix[6] * input_data[nxti*width + prej] + Convolve3x.martix[7] * input_data[nxti*width + j] 188 | + Convolve3x.martix[8] * input_data[nxti*width + nxtj]); 189 | 190 | 191 | //计算dy 192 | gradientResult[i*width * 4 + j * 4 + 1] = (float)(Convolve3x.martix[0] * input_data[prei*width + prej] + Convolve3x.martix[3] * input_data[prei*width + j] + 193 | Convolve3x.martix[6] * input_data[prei*width + nxtj] + Convolve3x.martix[1] * input_data[i*width + prej] + Convolve3x.martix[4] * input_data[i*width + j] 194 | + Convolve3x.martix[7] * input_data[i*width + nxtj] + Convolve3x.martix[2] * input_data[nxti*width + prej] + Convolve3x.martix[5] * input_data[nxti*width + j] 195 | + Convolve3x.martix[8] * input_data[nxti*width + nxtj]); 196 | 197 | 198 | //计算正切角 199 | gradientResult[i*width * 4 + j * 4 + 2] =(float)(atan2(gradientResult[i*width * 4 + j * 4 + 0], gradientResult[i*width * 4 + j * 4 + 1])); 200 | 201 | 202 | //计算模长 203 | gradientResult[i*width * 4 + j * 4 + 3] = (float)sqrt(gradientResult[i*width * 4 + j * 4 + 0] * gradientResult[i*width * 4 + j * 4 + 0] + gradientResult[i*width * 4 + j * 4 + 1] * gradientResult[i*width * 4 + j * 4 + 1]); 204 | 205 | if (gradientResult[i*width * 4 + j * 4 + 3] < 0.15) 206 | { 207 | gradientResult[i*width * 4 + j * 4 + 0] = 0; 208 | gradientResult[i*width * 4 + j * 4 + 1] = 0; 209 | gradientResult[i*width * 4 + j * 4 + 2] = 0; 210 | gradientResult[i*width * 4 + j * 4 + 3] = 0; 211 | } 212 | return ret; 213 | } 214 | } 215 | 216 | if (Convolve3x.martix) 217 | { 218 | free(Convolve3x.martix); 219 | Convolve3x.martix = NULL; 220 | } 221 | } 222 | 223 | 224 | 225 | 226 | 227 | --------------------------------------------------------------------------------