Hi all!

I'm developing software as part of my BSc. IT (Hons) course. The aim of the software is to determine the affective state (mood) of a person who is using the system based on facial expressions. In order to do this, the program pulls images from a webcam and processes them to determine the affective state displayed in that frame.

At the moment this process is really slow, taking on average 5 to 6 seconds to analyse a single image. I plan on optimizing this code to improve efficiency but I've been looking into possibly using multi-threading and/or parallel programming as well, so that i don't have to wait for the first image to be processed before I start on the next one.

At the moment, the program uses the background worker thread, as the affective state monitoring will work in the background while the person using the program will be participating in a flash game or something else running on the UI thread.

I've looked at parallel programming and understand the basics of how it works but I can't figure out exactly how to apply it to my program, within the background worker thread, so that it can also give feedback to the UI thread during and after analysis of each image.

If anyone could advise me on how to do this, give me a starting point or point me in the direction of a tutorial that will help me apply the concepts to this application, I would really appreciate it.


Parallelization can be complicated. Some things can't be parallelized, and it can be difficult to extract the parallelizable parts from existing sequential code. I can't offer anything too specific without knowing what your algorithm is, but since it's an image processing job, I imagine you at least might be able to find ways to parallelize the feature-detection bits--either in detecting independent features in multiple threads, or if you can subdivide the image and work on each piece independently, that could work, too. Beyond that, we'd have to get into the details of your computation, what's independent, and what has to be shared, and how one might extract useful processes and keep them communicating effectively.

There also might be ways to improve your algorithm's basic performance without trying to parallelize it, but that would require detailed examination of your application. Have you tried running a profiler to see where your code is spending most of its time? That might be very illuminating.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.