RGBImage Issues

Has anyone else had an issue trying to create an RGBImage from a file? When using this code:

RGBImage* image = new RGBImage("testPattern.jpg")

I always got the error “RGBImage not declared”. All of the includes are right, and WindRiver can give me the tooltips for the constructor when I hover my mouse over it. Trying to manually include the file led to some more errors though.

I ended up getting it to work by creating my own RGBImage using the nivision stuff though.

This code will be running on the robot when it runs - don’t know if that’s obvious or not – and as such, ‘testPattern.jpg’ must be on the robot and must be in the ‘current working directory’ of the running program. If you’re feeling confident that all this makes sense so far, I would suggest that you try doing a little test to ensure that the file is really “there” by opening the file and reading the first 4 bytes of the file or something…if the following all checks out then I’d ask … how are you creating this testPattern.jpg file? Could it have been saved in a different format than .jpg by a writing function? I seem to recall a situation last year where files we were writing wound up being BMP format instead of JPG due to a saving issue.


FILE* fp = fopen("testPattern.jpg", "rb");
if (fp) {
  unsigned char test[10];
  int read;

  read = fread(test, 1, 4, fp);
  if (read != 4) {
    printf("Did not read 4 bytes. Error.
");
  }
  else {
    printf("SUCCESS. File at least exists.
");
  }
}
else {
  printf("File not found.
");
}

This is a compile-time error, yes? I place this code in my compiler and it works…
Oh. You’re missing a semicolon.
Try


RGBImage* image = new RGBImage("testPattern.jpg");

Instead.

BTW, if you read and display the first 16 bytes instead of the first 4 bytes, you will see a 4-byte signature at offset 6 that will tell you if the file is a JPG or not. I believe JPG files have something like “Exif” or “JFIF” at offset 6 whereas BMP files have “BM” as the first 2 bytes of the file. There may be some other valid signatures, but you get a pretty good idea on what format the file is.