Trying to cycle through images on pi


#1

Hello,

I am trying to cycle through an array of 120 png images on the pi to create an animation, but when I run it, it is blank. The images are 1620 x 1080 at 72 dpi.

Here is my code:

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
	ofBackground(0, 0, 0);
	ofHideCursor();

	//Read image sequence from folder
	//1. Create object for reading folder contents
	ofDirectory dir;

	//2. Get the number of fikes in the folder data/paintings
	int n = dir.listDir("paintings");

	//3. set the array size to n
	seq.resize(n);

	//4. load images
	for (int i =0; i<n; i++) {
		//Getting i-th file name
		string fileName = dir.getPath(i);

		//load i-th image
		ofLoadImage(seq[i], fileName);
	} 
}

//--------------------------------------------------------------
void ofApp::update(){
	video.update();

}

//--------------------------------------------------------------
void ofApp::draw(){
	ofSetColor(255, 255, 255);
	//video.draw(0,0, 1920, 1080);
	
	//animate
	float time = ofGetElapsedTimef();
	int n = seq.size();
	float duration = n / 15.0;
	float pos = fmodf(time, duration);
	int i = int(pos/duration * n);
	ofEnableAlphaBlending();
	seq[i].draw(0,0, 1920, 1080);

}

#2

i don’t think you can load 120 images at that resolution in the raspberry pi. png is usually rgba which is 4 bytes * 1620 x 1080 = 6998400 ~= 6,67Mb x 120 = 800Mb. The whole system has 1Gb of which part would be used by the OS so even if there’ s nothing else running it’s probably just failing to load some of the textures.

Is seq a vector of ofImage or ofTexture? if ti’s ofImage then it’s using double that since ofImage loads the image in ram and then in video memory.

Try loading only one image to see if that works in case it’s something else and then loading incrementally more textures to see when it fails

You might need to do something with threads where you preload some images but not all and try to guess which image is going to be needed next and which are not needed anymore which if you are playing only forward should be relatively straightforward


#3

It’s a texture. I will try your suggestions. Do you think it would work better with ofximagethreader?


#4

yes any of the image sequence addons that preloads on a thread should do


#5

So I tested it one at a time and it loads five images fine, but after that goes blank. I will try ofxImageThreader next.


#6

I managed to get ofxThreadedImageLoader running, but only some of the images are loading. It flickers between black, white, and a few images. I posted about this issue here in the past, but didn’t receive any responses.

Here is my current code:


#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
	ofBackground(0, 0, 0);
	ofHideCursor();

	ofSetLogLevel(OF_LOG_VERBOSE);
	ofSetVerticalSync(true);
	images.resize(imgSize);
	for(int i = 0; i < imgSize; ++i) {
		loader.loadFromDisk(images[i], "MilkDrunk-" + ofToString(i) + ".png");
	}
}



//--------------------------------------------------------------
void ofApp::update(){
	//images[randomNr].update();

}

//--------------------------------------------------------------
void ofApp::draw(){
	//ofSetColor(255, 255, 255);
	
	int randomNr = ofRandom(imgSize);
	images[randomNr].draw(0,0, 1920, 1080);
}

#7

I have managed to get it working if it only uses 11 images. Is there a way to cycle through all 119 images?