0

I'm getting this error:

Cannot initialize a variable of type 'unsigned char' with an rvalue of type 'unsigned char *'

when I'm trying to compile my code. I get the error at this line:

unsigned char imgdata = image.data(Glo_x[i][j],Glo_y[i][j]);

and the code in the loop is

unsigned char imgdata = image.data(Glo_x[i][j],Glo_y[i][j]);
int dataset = (int)(imgdata);
int sample_size = pow(filter_width,2);
double mean = mean + dataset/sample_size;
double variance = variance + (dataset - mean) * 2;
var = variance / sample_size; here

I'm really new at coding so please don't judge. The problem is that I want to take the pixel value in the image and use it to calculate the mean. But I have to make the value to an int and I don't know how to do it. Please tell if you don't understand the question.

cornstach
  • 31
  • 1
  • 1
  • 4
  • 1
    `Cannot initialize a variable of type 'unsigned char' with an rvalue of type 'unsigned char *'` Well it should probably be: `unsigned char *imgdata = image.data(Glo_x[i][j],Glo_y[i][j]);` Btw, what is `image`? Which library are you using? – DimChtz May 07 '18 at 14:25
  • Yes I tried that and then I hade to change the second row too which gave a lot of errors in the CImg library (don't know why) – cornstach May 07 '18 at 14:33
  • 3
    if `image.data` returns a `char*`, then you will want to put `*` in front of it. `unsigned char imgdata = *image.data(Glo_x[i][j],Glo_y[i][j]);` – Jim Rhodes May 07 '18 at 14:35
  • 1
    This `image.data(Glo_x[i][j],Glo_y[i][j])` will return a pointer to a pixel. – DimChtz May 07 '18 at 14:37
  • Ah, I understand what you mean! The problem is then how I can make it into an int? When I'm doing as my third line it doesn't work... – cornstach May 07 '18 at 15:09
  • 1
    So, you're trying to get the RGB value of a pixel using the CImg library? Is your question a duplicate of https://stackoverflow.com/questions/3291923/how-to-get-rgb-value-by-cimg ? – MartinVeronneau May 07 '18 at 15:29
  • @MartinVéronneau no, I want the gray-level value, in the range 0 to 255, of the pixel by using the CImg library. It's not a duplicate. – cornstach May 07 '18 at 16:05
  • Please provide a *"Minimal, Complete, Verifiable Example"* as required by Stack Overflow rules. It should start at the `#include` line and include all code. Thank you. – Mark Setchell May 07 '18 at 16:40
  • @cornstach Look at this comment in the same question : https://stackoverflow.com/questions/3291923/how-to-get-rgb-value-by-cimg#comment3439371_3292143 – MartinVeronneau May 07 '18 at 17:43
  • @MarkSetchell I cannot post the whole code since I'm doing this project to a federation and the code will be their property, I'm sorry. – cornstach May 07 '18 at 20:00
  • @MartinVéronneau ah, now I saw the comment, I will try that, thank you :) – cornstach May 07 '18 at 20:01

0 Answers0