Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
AnswerRe: add shortcut to recent start menu Pin
Richard Andrew x6423-Jul-12 11:19
professionalRichard Andrew x6423-Jul-12 11:19 
GeneralB Pin
Akshay_8823-Jul-12 3:51
Akshay_8823-Jul-12 3:51 
AnswerRe: Is there any mobile software to read the generated barcode? Pin
Richard MacCutchan23-Jul-12 5:11
mveRichard MacCutchan23-Jul-12 5:11 
AnswerNot exactly an answer but Pin
Ennis Ray Lynch, Jr.23-Jul-12 7:01
Ennis Ray Lynch, Jr.23-Jul-12 7:01 
QuestionWrite Data to Linux Pin
yuvachandra23-Jul-12 2:33
yuvachandra23-Jul-12 2:33 
AnswerRe: Write Data to Linux Pin
Eddy Vluggen23-Jul-12 2:45
professionalEddy Vluggen23-Jul-12 2:45 
AnswerRe: Write Data to Linux Pin
jschell23-Jul-12 5:22
jschell23-Jul-12 5:22 
GeneralArtefacts in parallel image processing Pin
Kangerm00se23-Jul-12 1:47
Kangerm00se23-Jul-12 1:47 
I capture images from a webcam, do some heavy processing on them, and then show the result. To keep the framerate high, i want to have the processing of different frames run in parallel.

So, I have a 'Producer', which captures the images and adds these to the 'inQueue'; also it takes an image from the 'outQueue' and displays it:
C#
public class Producer
{
    Capture capture;
    Queue<Image<Bgr, Byte>> inQueue;
    Queue<Image<Bgr, Byte>> outQueue;
    Object lockObject;
    Emgu.CV.UI.ImageBox screen;
    public int frameCounter = 0;

    public Producer(Emgu.CV.UI.ImageBox screen, Capture capture, Queue<Image<Bgr, Byte>> inQueue, Queue<Image<Bgr, Byte>> outQueue, Object lockObject)
    {
        this.screen = screen;
        this.capture = capture;
        this.inQueue = inQueue;
        this.outQueue = outQueue;
        this.lockObject = lockObject;
    }

    public void produce()
    {
        while (true)
        {
            lock (lockObject)
            {
                inQueue.Enqueue(capture.QueryFrame());

                if (inQueue.Count == 1)
                {
                    Monitor.PulseAll(lockObject);
                }
                if (outQueue.Count > 0)
                {
                    screen.Image = outQueue.Dequeue();
                }
            }
            frameCounter++;
        }
    }
}


There are different 'Consumers' who take an image from the inQueue, do some processing, and add them to the outQueue:
C#
public class Consumer
{
    Queue<Image<Bgr, Byte>> inQueue;
    Queue<Image<Bgr, Byte>> outQueue;
    Object lockObject;
    string name;

    Image<Bgr, Byte> image;

    public Consumer(Queue<Image<Bgr, Byte>> inQueue, Queue<Image<Bgr, Byte>> outQueue, Object lockObject, string name)
    {
        this.inQueue = inQueue;
        this.outQueue = outQueue;
        this.lockObject = lockObject;
        this.name = name;
    }

    public void consume()
    {
        while (true)
        {
            lock (lockObject)
            {
                if (inQueue.Count == 0)
                {
                    Monitor.Wait(lockObject);
                    continue;
                }
                image = inQueue.Dequeue();
            }

            // Do some heavy processing with the image

            lock (lockObject)
            {
                outQueue.Enqueue(image);
            }

        }
    }
}


Rest of the important code is this section:
C#
private void Form1_Load(object sender, EventArgs e)
{
    Consumer[] c = new Consumer[consumerCount];
    Thread[] t = new Thread[consumerCount];

    Object lockObj = new object();
    Queue<Image<Bgr, Byte>> inQueue = new Queue<Image<Bgr, Byte>>();
    Queue<Image<Bgr, Byte>> outQueue = new Queue<Image<Bgr, Byte>>();

    p = new Producer(screen1, capture, inQueue, outQueue, lockObj);

    for (int i = 0; i < consumerCount; i++)
    {
        c[i] = new Consumer(inQueue, outQueue, lockObj, "c_" + Convert.ToString(i));
    }
    for (int i = 0; i < consumerCount; i++)
    {
        t[i] = new Thread(c[i].consume);
        t[i].Start();
    }

    Thread pt = new Thread(p.produce);
    pt.Start();
}


The parallelisation actually works fine, I do get a linear speed increase with each added thread (up to a certain point of course). The problem is that I get artifacts in the output, even if running only one thread. The artifacts look like part of the picture is not in the right place.


Example of the artifact (this is without any processing to keep it clear, but the effect is the same)


Any ideas what causes this?
Thanks
AnswerRe: Artefacts in parallel image processing Pin
Luc Pattyn23-Jul-12 2:22
sitebuilderLuc Pattyn23-Jul-12 2:22 
GeneralRe: Artefacts in parallel image processing Pin
Kangerm00se23-Jul-12 2:49
Kangerm00se23-Jul-12 2:49 
AnswerRe: Artefacts in parallel image processing Pin
Luc Pattyn23-Jul-12 5:14
sitebuilderLuc Pattyn23-Jul-12 5:14 
GeneralRe: Artefacts in parallel image processing Pin
BobJanova23-Jul-12 4:39
BobJanova23-Jul-12 4:39 
QuestionWhat are the API's that are available for USB based barcode scanners in C#? Pin
Akshay_8822-Jul-12 23:14
Akshay_8822-Jul-12 23:14 
AnswerRe: What are the API's that are available for USB based barcode scanners in C#? Pin
glennPattonWork322-Jul-12 23:27
professionalglennPattonWork322-Jul-12 23:27 
GeneralRe: What are the API's that are available for USB based barcode scanners in C#? Pin
Akshay_8822-Jul-12 23:34
Akshay_8822-Jul-12 23:34 
GeneralRe: What are the API's that are available for USB based barcode scanners in C#? Pin
glennPattonWork322-Jul-12 23:47
professionalglennPattonWork322-Jul-12 23:47 
GeneralRe: What are the API's that are available for USB based barcode scanners in C#? Pin
Akshay_8822-Jul-12 23:53
Akshay_8822-Jul-12 23:53 
GeneralRe: What are the API's that are available for USB based barcode scanners in C#? Pin
glennPattonWork323-Jul-12 0:09
professionalglennPattonWork323-Jul-12 0:09 
GeneralRe: What are the API's that are available for USB based barcode scanners in C#? Pin
Akshay_8823-Jul-12 0:44
Akshay_8823-Jul-12 0:44 
QuestionRe: What are the API's that are available for USB based barcode scanners in C#? Pin
Eddy Vluggen22-Jul-12 23:53
professionalEddy Vluggen22-Jul-12 23:53 
AnswerRe: What are the API's that are available for USB based barcode scanners in C#? Pin
Akshay_8822-Jul-12 23:56
Akshay_8822-Jul-12 23:56 
AnswerRe: What are the API's that are available for USB based barcode scanners in C#? Pin
Akshay_8822-Jul-12 23:58
Akshay_8822-Jul-12 23:58 
GeneralRe: What are the API's that are available for USB based barcode scanners in C#? Pin
Eddy Vluggen23-Jul-12 0:06
professionalEddy Vluggen23-Jul-12 0:06 
GeneralRe: What are the API's that are available for USB based barcode scanners in C#? Pin
Akshay_8823-Jul-12 0:44
Akshay_8823-Jul-12 0:44 
GeneralRe: What are the API's that are available for USB based barcode scanners in C#? Pin
Dave Kreskowiak23-Jul-12 2:08
mveDave Kreskowiak23-Jul-12 2:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.