ofImage loadImage...

Hi, I’m trying to get the difference between two images (Actually frames, but baby steps…)

But I can’t for the life of me get my images to load.

Here is my code:

  
  
void App::setup(){  
	ofSetLogLevel(OF_LOG_VERBOSE);  
	bool load = diff1.loadImage("images/diff1.jpg");  
	if(!load){  
		printf("Could not load diff1");  
	}  
	diff2.loadImage("images/diff2.jpg");  
	unsigned char *pixels = diff1.getPixels();  
  
        // do we have any pixel values?!  
	for(int i = 0; i < diff1.getWidth() * diff1.getHeight(); i++){  
		printf("%c", pixels[i]);  
		if(i == 100){  
			break;  
		}  
	}  
}  
  
void App::draw(){  
	diff1.draw(0,0);  
	//diff2.draw(100, 0);  
}  
  

My directory structure is like so

  
  
DiffImage  
----data  
--------images  
------------diff1.jpg  
------------diff2.jpg  
----DiffImage.xcodeproj  
----libs  
--------fmodex  
--------freeimage  
--------openFrameworks  
------------graphics  
----------------ofImage.c  
--------etc...  
----source  
--------App.c  
--------etc...  
  

I put a cout into the, I think it was, ofToDataPath, which printed out the path “…/…/…/data/images/diff1.jpg”.

By my reckoning, this loadImage is getting called in libs/openframeworks/graphics, so the path should be OK. Is there something stupid I’m missing…

It’s getting compiled to an OS X app.

I’ve tried moving the images to bin/data/images, as per the image example. I’ve tried adding them to my xcode project and selecting the make folder references option.

greetings ! did you reorganize the OF folder?

DiffImage
----data
--------images
------------diff1.jpg
------------diff2.jpg
----DiffImage.xcodeproj
----libs
--------fmodex
--------freeimage
--------openFrameworks
------------graphics
----------------ofImage.c
--------etc…
----source
--------App.c
--------etc…

this doesn’t look right, to me… Can you post a screen shot of your setup? did you move the libs into the app folder?

OF comes as :

  
  
apps  
-- exampleApps  
------ imageLoader, etc  
libs  
addons  
  

the …/…/…/ is relative to the compiled app, not the library you are using… since an application in osx is running inside a package (right click any app and say “show package contents” to see what I mean) an application is actually bundled into a package, and the “executable” is three levels deeper. so we append …/…/…/data/ to mac paths

can you try to compile the imageLoader example that comes with OF? does it work for you? it should show you how images load in OF…

take care,
zach

Ahhh yes, relative to the bundle *Smacks head*.

I did move the lib into my projects director. It gel’s better to how I work. I also put all my xcode build products in a separate dir for easy cleanup. Once I’d got the app and the images together it all worked.

Thanks :slight_smile:

ok, you defintiely shouldn’t move anything like putting the libs in the application folder. we do all the linking relatively in our projects, and that would screw up the example apps we ship with.

in an xcode project, like “emptyExample” or “imageExample” they are including and linking to “…/…/…/libs/*”, if you start moving those libraries around, you are gaurenteed to have a rough time, either recreating the OF project to compile, or you may damage your OF install.

best is, just copy and example project, and keep at at the same “height” within the directory structure, and don’t change or move anything in libs. you’ll be happy !

take care,
zach

Ah yeah, I created my own xcode template which has all the correct paths for libraries, etc. I was thinking I might post it here but perhaps that would be discouraged :slight_smile:

yeah a whole lot harder !!!

I mean, cool that you are doing it, but in general, the OF folder is designed to be the same across machines so you can share both source and project files too !

take care,
zach