Jump to content

[SOLVED] Async class for Image Treatment


photo

Recommended Posts

Posted

Hi, I have a script function who do some image treatment for generate 3D model. The treatment are basic (INPUT) Image -> [ Grayscale + Prewitt + Sobel + Canny + FloodFill ] -> Mesh (OUTPUT), for the moment I work only on the Image treatment.

 

The basic call are inside a for loop (sequential) : 

	log.message("AL --> Begin on '%d' images\n\n", images.size());

	foreach (string img; images) {
	
		begin_time = clock();
		log.message("\tAL --> Start Generator on '%s' \n", img);
		Generator gen = new Generator(img);
		gen.exec();
		delete gen;	
		log.message("\tAL --> Generate image '%s' in %.4f seconds (%d ms)\n\n", img, (clock() - begin_time), (clock() - begin_time) * 1000);
	}

	log.message("AL --> END '%d' images in %.4f seconds (%d ms)\n\n", images.size(), (clock() - global_time), (clock() - global_time) * 1000);

I want make a version faster, using Async class for paralyze the call of generator, I try something like that : 

namespace AsyncGenerator {

	int num_tasks = 0;
	float global_time = 0.0f;

	void run(Generator gen) {
		gen.exec();
	}

	void end() {
		num_tasks--;
		if (num_tasks <= 0) {
			num_tasks = 0;
			log.message("AL --> END all images in %.4f seconds (%d ms)\n\n", (clock() - global_time), (clock() - global_time) * 1000);
		}
	}	
};
		Generator asyncs[0];
		Generator gens[0];

		log.message("AL --> Begin on '%d' images\n\n", images.size());
		
		AsyncGenerator::num_tasks = images.size();
		AsyncGenerator::global_time = clock();

		foreach (string img; images) {
			Async async = new Async();
			Generator gen = new Generator(img);
			gen.setFinishCallback("AsyncGenerator::end");
			async.run("AsyncGenerator::run",gen);
			asyncs.append(async);
			gens.append(gen);
		}

Seems work only for the second image not the first, I have crash with an depth of instance is not zero.

 

Interpreter::runFunction(): depth of instance is not zero
		Grayscale image '3065890104549_1_UK.png' in 0.0030 seconds (2 ms)
		Square image '3065890104549_1_UK.png' in 0.0115 seconds (11 ms)
		Grayscale image '3065890104549_1_UK.png' in 0.0057 seconds (5 ms)
		Blur image '3065890104549_1_UK.png' in 0.0416 seconds (41 ms)

Unigine fatal error
/Users/aliot/Actisku/engine/software/source/engine/interpreter/Interpreter.cpp:511: throw(): unhandled exception: Machine::run(): "int: 0" is not a user class
Shutdown

I am not sure to understand rightly the Async class. It's possible to do this kind of work on image with Async ??

Thanks 

 

Tony

 

 

 

 

 

 

Posted

Hi Ulf,

 

Thanks for the post you have right seems to be the trouble. 

 

Tony

×
×
  • Create New...