Click here to Skip to main content
15,901,965 members
Home / Discussions / C#
   

C#

 
Questionproblem using C# and Action Script3 api Pin
hsoft_project24-Jul-12 0:55
hsoft_project24-Jul-12 0:55 
AnswerRe: problem using C# and Action Script3 api Pin
fjdiewornncalwe24-Jul-12 3:44
professionalfjdiewornncalwe24-Jul-12 3:44 
Questionhow to create xml menu Pin
yankoon23-Jul-12 23:01
yankoon23-Jul-12 23:01 
AnswerRe: how to create xml menu Pin
_Amy24-Jul-12 2:52
professional_Amy24-Jul-12 2:52 
QuestionHow to get the installed printers' name from remote server? Pin
royhpr23-Jul-12 22:03
royhpr23-Jul-12 22:03 
AnswerRe: How to get the installed printers' name from remote server? Pin
Eddy Vluggen24-Jul-12 0:16
professionalEddy Vluggen24-Jul-12 0:16 
AnswerRe: How to get the installed printers' name from remote server? Pin
Bernhard Hiller24-Jul-12 0:19
Bernhard Hiller24-Jul-12 0:19 
Questionwhat is recommended Pin
Tall joe23-Jul-12 20:34
Tall joe23-Jul-12 20:34 
AnswerRe: what is recommended Pin
OriginalGriff23-Jul-12 21:42
mveOriginalGriff23-Jul-12 21:42 
AnswerRe: what is recommended Pin
Keith Barrow24-Jul-12 1:56
professionalKeith Barrow24-Jul-12 1:56 
AnswerRe: what is recommended Pin
Abhinav S24-Jul-12 6:24
Abhinav S24-Jul-12 6:24 
Questionadd shortcut to recent start menu Pin
Jassim Rahma23-Jul-12 10:43
Jassim Rahma23-Jul-12 10:43 
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 

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.