Click here to Skip to main content
15,886,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
Right now I have an IR LED, and IR Camera and a working code/program that enable me to view video capture using DirectShow.
So when I ran the program using the IR camera, I can see black background with a white bright spot where the IR LED is.

my capture function is as follow:
public void myCaptureVideo(int myCameraIndex)
        {
            int myHR = 0;
            IBaseFilter mySourceFilter = null;
            object source;
            try
            {
                GetInterfaces();
                myHR = this.myCaptureGraphBuilder.SetFiltergraph(this.myGraphBuilder);
                DsError.ThrowExceptionForHR(myHR);
                DsDevice device = capDevices[myCameraIndex];
                Guid myIID = typeof(IBaseFilter).GUID;
                
                device.Mon.BindToObject(null, null, ref myIID, out source);

                mySourceFilter = (IBaseFilter)source;

                myHR = this.myGraphBuilder.AddFilter(mySourceFilter, "Video Capture");
                DsError.ThrowExceptionForHR(myHR);
                myHR = this.myCaptureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, mySourceFilter, null, null);
                DsError.ThrowExceptionForHR(myHR);

                Marshal.ReleaseComObject(mySourceFilter);

                SetupVideoWindow();
                rot = new DsROTEntry(this.myGraphBuilder);
                myHR = this.myMediaControl.Run();
                DsError.ThrowExceptionForHR(myHR);

                this.currentState = myPlayState.myPlayRunning;
                
            }
            catch
            {
                MessageBox.Show("An unrecoverable error has occurred." + DsError.GetErrorText(myHR));
            }
        }


Right now I'm trying to figure out how to determine the x-y location/coordinate of the shown small white bright spot with respect to the video feed resolution. I mean which row and which column in the video feed.

if possible something like:
private bool find whitespot()
{
    int xLaser = 0;
    int yLaser = 0;
    for (int y = 0; y < 640; y++)
    {
        for (int x = 0; x < 480; x++)
        {
            if (imagebuffer[x, y] > 250)
            {
                xLaser = x;
                yLaser = y;
            }
        }
    }
}


I hope someone can help me with this
Posted

1 solution

It's not as easy as your code implies. Your code will give you the position of the last pixel it finds that is brighter than your threshold.

You'll have to define a bounding box for all of those pixels, then calculate the center of the box for the approximate position. This would also help you take into account the distance to the light source and it's shape. Since a source closer to the camera will appear larger than one farther away from the camera.

If you're looking at doing more than this, your task just got much more difficult. You can find an example here[^].
 
Share this answer
 
Comments
Manfred Rudolf Bihy 20-Jan-11 16:04pm    
Moved from OP's answer:

Thanks for the reply,
Though I understand what you mean, how do you exactly scan line by line a DirectShow video capture?

The way I see it, the algorithm should be something like this:
1. i need to scan line by line to detect a pixel that is brighter than threshold.
2. I would need to count the total surrounding pixel to ensure it is not a mistake
3. use something like Graphics Drawpolygon() to draw out the area
4. find center of polygon.

about the distance part, i don't need to know the distance since I can calculate from the led height. this is because, the IR led is attached to a ultrasonic sensor.so it save me a lot of trouble of deriving a series of equation etc.

but as for the first part, i don't have any idea at all in terms of how do i write the code.
Dave Kreskowiak 20-Jan-11 19:05pm    
I didn't say you needed to know the distance to the LED. I said the distance to the LED will make the apparent spot in the image larger or smaller as the distance is changed. Your algorithm will have to be designed to account for a larger or smaller spot to find in the image.

You don't have to scan line by line to find the "hot spot" in your image. I already gave you a link to a sample that does exactly what you're talking about.

On top of the article I already linked to, here's another one: http://www.codeproject.com/KB/audio-video/Motion_Detection.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900