/normxcorr/trunk

To get this branch, use:
bzr branch http://suren.me/webbzr/normxcorr/trunk

« back to all changes in this revision

Viewing changes to dict_hw/matlab/normxcorr_hw.cu

  • Committer: Suren A. Chilingaryan
  • Date: 2009-12-15 20:10:31 UTC
  • Revision ID: csa@dside.dyndns.org-20091215201031-tx1m0yw1r5owbnzg
Optimization mode 5 for matlab: image loading in C code

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
#include "normxcorr_hw_msg.h"
9
9
 
 
10
#define MAX_FILE_NAME 2048
10
11
 
11
12
#define USE_UNDOCUMENTED
12
13
//#define VALIDATE_LSUM
25
26
#endif /* VALIDATE_PEAK */
26
27
    ACTION_SET_POINTS = 12,
27
28
    ACTION_COMPUTE = 13,
28
 
    ACTION_GET_POINTS = 14,
 
29
    ACTION_GET_POINTS = 14
29
30
} TAction;
30
31
 
31
32
 
76
77
 
77
78
    DICTContext ps;
78
79
    TAction action;
 
80
    int class_id;
79
81
 
80
82
    int iprop;
81
83
    
88
90
#endif /* VALIDATE_LSUM */
89
91
 
90
92
    const mxArray *x, *y;
 
93
    
 
94
    int length;
 
95
    mxChar *chars;
 
96
    char name[MAX_FILE_NAME+1];
91
97
 
92
98
    if (!nrhs) {
93
99
        reportMessage("Initializing normxcorr_hw instance");
155
161
 
156
162
        input = prhs[2];
157
163
 
158
 
        if (mxGetNumberOfDimensions(input) != 2) {
159
 
            reportError("Invalid dimensionality of base matrix, 2D matrix is expected");
160
 
            return;
161
 
        }
162
 
        
163
 
        if (mxGetClassID(input) != mxUINT8_CLASS) {
164
 
            reportError("Invalid type of image data, should be 8bit integers");
165
 
            return;
166
 
        }
167
 
        
168
 
        if ((mxGetN(input) != width)||(mxGetM(input) != height)) {
169
 
            reportError("Invalid size of image (%ix%i), but (%ix%i) is expected", mxGetN(input), mxGetM(input), width, height);
170
 
            return;
171
 
        }
172
 
 
173
 
        dictLoadImage(ps, (unsigned char*)mxGetData(input));
174
 
         break;
 
164
        class_id = mxGetClassID(input);
 
165
        switch (class_id) {
 
166
            case mxUINT8_CLASS:
 
167
                if (mxGetNumberOfDimensions(input) != 2) {
 
168
                    reportError("Invalid dimensionality of base matrix, 2D matrix is expected");
 
169
                    return;
 
170
                }
 
171
        
 
172
                if ((mxGetN(input) != width)||(mxGetM(input) != height)) {
 
173
                    reportError("Invalid size of image (%ix%i), but (%ix%i) is expected", mxGetN(input), mxGetM(input), width, height);
 
174
                    return;
 
175
                }
 
176
 
 
177
                dictLoadImage(ps, (unsigned char*)mxGetData(input));
 
178
            break;
 
179
            case mxCHAR_CLASS:
 
180
                if ((mxGetNumberOfDimensions(input) != 2)&&(mxGetM(input) != 1)) {
 
181
                    reportError("Only a single string is supported");
 
182
                    return;
 
183
                }
 
184
 
 
185
                length = mxGetN(input);
 
186
                chars = mxGetChars(input);
 
187
                
 
188
                if (length > MAX_FILE_NAME) {
 
189
                    reportError("File name is too long, limit is %i", MAX_FILE_NAME);
 
190
                    return;
 
191
                }
 
192
                
 
193
                for (int i = 0; i < length; i++) {
 
194
                    if (chars[i] > 255) {
 
195
                        reportError("Unicode file names are not supported yet");
 
196
                        return;
 
197
                    }
 
198
                    name[i] = chars[i];
 
199
                }
 
200
                name[length] = 0;
 
201
 
 
202
                err = dictLoadImageFile(ps, name);
 
203
                if (err) {
 
204
                    reportError("Failed to load image: %s", name);
 
205
                    return;
 
206
                }
 
207
            break;
 
208
            default:
 
209
                reportError("Invalid type of image data, should be 8bit integers");
 
210
                return;
 
211
        }
 
212
     break;
175
213
     case ACTION_COMPUTE_BASE:
176
214
        if (nrhs != 3) {
177
215
            reportError("ComputeBase action expects 1 argument, but %i is passed", nrhs - 2);
179
217
        }
180
218
 
181
219
        base = prhs[2];
182
 
    
183
 
        if (mxGetNumberOfDimensions(base) != 2) {
184
 
            reportError("Invalid dimensionality of base matrix, 2D matrix is expected");
185
 
            return;
186
 
        }
187
 
 
188
 
        if (mxGetClassID(base) != mxUINT8_CLASS) {
189
 
            reportError("Invalid matrix. The data type (%s) is not supported", mxGetClassName(base));
190
 
            return;
191
 
        }
192
 
 
193
 
        width = mxGetN(base);
194
 
        height = mxGetM(base);
195
 
        
196
 
        dictLoadTemplateImage(ps, (unsigned char*)mxGetData(base), width, height);
 
220
        
 
221
        class_id = mxGetClassID(base);
 
222
        
 
223
        switch (class_id) {
 
224
            case mxUINT8_CLASS:
 
225
                if (mxGetNumberOfDimensions(base) != 2) {
 
226
                    reportError("Invalid dimensionality of base matrix, 2D matrix is expected");
 
227
                    return;
 
228
                }
 
229
                
 
230
                width = mxGetN(base);
 
231
                height = mxGetM(base);
 
232
        
 
233
                dictLoadTemplateImage(ps, (unsigned char*)mxGetData(base), width, height);
 
234
            break;
 
235
            case mxCHAR_CLASS:
 
236
                if ((mxGetNumberOfDimensions(base) != 2)&&(mxGetM(base) != 1)) {
 
237
                    reportError("Only a single string is supported");
 
238
                    return;
 
239
                }
 
240
 
 
241
                length = mxGetN(base);
 
242
                chars = mxGetChars(base);
 
243
                
 
244
                if (length > MAX_FILE_NAME) {
 
245
                    reportError("File name is too long, limit is %i", MAX_FILE_NAME);
 
246
                    return;
 
247
                }
 
248
                
 
249
                for (int i = 0; i < length; i++) {
 
250
                    if (chars[i] > 255) {
 
251
                        reportError("Unicode file names are not supported yet");
 
252
                        return;
 
253
                    }
 
254
                    name[i] = chars[i];
 
255
                }
 
256
                name[length] = 0;
 
257
 
 
258
                err = dictLoadTemplateImageFile(ps, name);
 
259
                if (err) {
 
260
                    reportError("Failed to load image: %s", name);
 
261
                    return;
 
262
                }
 
263
            break;
 
264
            default:
 
265
                reportError("Invalid matrix. The data type (%s) is not supported", mxGetClassName(base));
 
266
                return;
 
267
        }
197
268
     break;
198
269
     case ACTION_SET_BASE_POINTS:
199
270
        if (nrhs != 4) {