我一直在第301-304行收到此错误,我不太清楚为什么。我已经尝试将它作为unsigned char投射,但它似乎没有做任何事情。在此错误之前,我在第241行遇到了分段错误,因为它曾经是" unsigned char * c [pixels * 3]。新修复程序提出了我当前的编译错误。
Final.cc:301:18: error: invalid types ‘unsigned char[int]’ for array subscript
238 /*
239 APPLYING WEIGHT SUM FOR (NAME OF FUNCTION)
240 */
241 unsigned char* c = new unsigned char[pixels*3];
242 int sum1R = 0, sum1G = 0, sum1B = 0;
243 int sum2R = 0, sum2G = 0, sum2B = 0;
244 int weightsum = 9;
245cout << "test3" << endl;
246 for (int j = 0; j < columns; j++) {
247 for (int i = 0; i < lines; i++) {
248 int index = (i * lines + j) * 3;
249
250 for (int l = 0; l < wSize; l++) {
251 for (int k = 0; k < wSize; k++) {
252 int tempk = (k+j) - wHalf;
253 int templ = (l+i) - wHalf;
254 // making sure we are not out of bounds of the image
255 if((tempk > (columns - 1)) || (tempk < 0)){
256 tempk = j;
257 }
258 if((templ > (lines - 1)) || (templ < 0)){
259 templ = i;
260 }
261 int pos1 = (tempk*lines + 0) * 3;
262 int pos2 = (0 + templ) * 3;
263 int r1 = originalpixmap[pos1], g1 = originalpixmap[pos1+1], b1 = originalpixmap[pos1+2];
264 int r2 = originalpixmap[pos2], g2 = originalpixmap[pos2+1], b2 = originalpixmap[pos2+2];
265 sum1R += weight[tempk][templ]*pow((r1-r2),2);
266 sum1G += weight[tempk][templ]*pow((g1-g2),2);
267 sum1B += weight[tempk][templ]*pow((b1-b2),2);
268 }
269 }
270
271 int meanSumR = 0, meanSumG = 0, meanSumB = 0;
272 for(int l = 0; l < wSize; l++){
273 int templ = (l+i) - wHalf;
274 int pos = (0 + templ) * 3;
275 if((templ > (lines - 1)) || (templ < 0)){
276 templ = i;
277 }
278 int r = originalpixmap[pos], g = originalpixmap[pos+1], b = originalpixmap[pos+2];
279
280 meanSumR += r;
281 meanSumG += g;
282 meanSumB += b;
283 }
284
285 int meanR = meanSumR/wSize;
286 int meanG = meanSumG/wSize;
287 int meanB = meanSumB/wSize;
288 for(int l = 0; l < wSize; l++){
289 int templ = (l+i) - wHalf;
290 int pos = (0 + templ) * 3;
291 if((templ > (lines - 1)) || (templ < 0)){
292 templ = i;
293 }
294 int r = originalpixmap[pos], g = originalpixmap[pos+1], b = originalpixmap[pos+2];
295
296 sum2R += pow((r-meanR),2);
297 sum2G += pow((g-meanG),2);
298 sum2B += pow((b-meanB),2);
299 }
300
301 c[index][index] = ((pixels-1)/2)*((sum1R)/(weightsum*sum2R));
302 c[index+1][index+1] = ((pixels-1)/2)*((sum1G)/(weightsum*sum2G));
303 c[index+2][index+2] = ((pixels-1)/2)*((sum1B)/(weightsum*sum2B));
304 cout<< "C.r: " << c[index][index] <<" C.g: "<< c[index+1][index+1] <<" C.b: " << c[index+2][index+2];
305 }
306 }
307
308}
309