Results 1 to 15 of 15

Thread: read image intensities [VB.NET2005]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    180

    read image intensities [VB.NET2005]

    I'm working on a program that will read from a webcam, and be able to find the "light" spots on it. It's going to be used in a multi-touch input program, where the field in the camera is basicly black (except for average noise) and when a finger is pressed down the camera now will see a bright white spot. So I guess my question is, when i load the image from the camera in to VB.NET, what is a good way to go about finding the location of this bright spot? I would like to have it running around 10-15 FPS so speed is a big issue. Anyone got an idea?

  2. #2
    Junior Member
    Join Date
    Jul 2007
    Posts
    17

    Cool Re: read image intensities [VB.NET2005]

    If you want to find a bright spot, or a dark spot for that matter, what you can do is read the average RGB values for each of the pixels in your image. You could use something like 'GetPixel()' and then AVG = (color.r + color.g + color.b) / 3. The closer the value 'AVG' is to 255, the 'whiter' that your pixel will be.

  3. #3
    Lively Member
    Join Date
    Jan 2007
    Posts
    95

    Re: read image intensities [VB.NET2005]

    hey MotoMan_Yz400, few days back i was also trying to do somwthing like that... i also like to know something about it...

    i did a search and got the webcam viewer: http://www.vbforums.com/showthread.php?p=2048466

    this class will help us to get the pictures in the picturebox... and after having the pictures we can get what capnyoaz said...

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    180

    Re: read image intensities [VB.NET2005]

    well my concern is speed. Even having a the web cam running at 320x240, thats still 76,800 pixels to read and setting up a FOR...NEXT loop would only yield a frame a second if i'm lucky. Can GetPixel() run through a memory load picture? In hopes to have it run faster? Like I said in my last post, I would like (if at all possible) 10 FPS.

  5. #5
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: read image intensities [VB.NET2005]

    GetPixel is pretty fast. Try the loop and see how it goes. Also, maybe you can use SetTimer to run the loop every 5 or so seconds.

  6. #6
    Junior Member
    Join Date
    Jul 2007
    Posts
    17

    Wink Re: read image intensities [VB.NET2005]

    GetPixel is slower than a dead turtle. If you really want to get some good speed, what you need is to access the memory directly and read it byte by byte. If you are familiar with the .Lockbits method that is the ticket. If not, check out this article, it should explain everything you need to know about it. If you still need more help, let me know and I will write a demo app for you.

    http://www.bobpowell.net/lockingbits.htm

    Good Luck!

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    180

    Re: read image intensities [VB.NET2005]

    capnyoaz your right, you can go grab a cup of coffee waiting for one frame to be analyzed. I ran a simple 2 layered FOR...Next loop and average 1.6sec per frame with an image 320x240. So thats 5/8ths of a frame per sec. I'm looking at something 16 times faster minimum. But i'll look into that, thanks capnyoaz.

  8. #8
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: read image intensities [VB.NET2005]

    Definately need LockBits and a Marshall copy. Since its VB you can't have a direct memory pointer.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    180

    Re: read image intensities [VB.NET2005]

    Well I have the LockBits running right and can return a memory pointer for the bitmap itself. However I cant get the Marshalling to function correctly. I'm stuck on actually retrieving the byte data from memory. I looked through the help files in my VB.NET Express and it didnt return much that pertains to what I'm doing. I also read a few tutorials on how to do it, but the sample code they give (supposed to be in Vb.Net) doesn't seem to work. Anyone tried this?

  10. #10
    Junior Member
    Join Date
    Jul 2007
    Posts
    17

    Question Re: read image intensities [VB.NET2005]

    Post some code and I will take a look at it for you. Are you getting specific errors, or is nothing happening?

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    180

    Re: read image intensities [VB.NET2005]

    No it's more like I never done this before. The code I do have, not sure if it's doing what i want, but it's atleast not throwing an error. As far as the marshalling, dont know even where to start. I'll have some code up later today.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    180

    Re: read image intensities [VB.NET2005]

    Ok I got some code working. It's based off someone else's code (if credits are needed I'll be more than glad to post them). For a simple analysation of the pixels averaged around 200-250FPS. But now I need to rack my brain on how to make the computer know were the center of the dots are!

  13. #13
    Junior Member
    Join Date
    Jul 2007
    Posts
    17

    Cool Re: read image intensities [VB.NET2005]

    That my friend is a very good question indeed. Image recognition is a tough subject, and I've only ever done a tiny bit, and it wasn't very sophisticated. Now I have no idea what your image looks like, but as a starting point I would recommend measuring the extremes of your 'dots'. You know, left, right, top and bottom. This will give you a rectangle, and then you can get the center from there. Of course, this may not work at all, so best of luck to you.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    180

    Re: read image intensities [VB.NET2005]

    Well below is my test image. I was thinking one of two ways to go about it. The first being as you said (alittle more "thinking" intensive on the computer) which would be good for a object interface. The second being (as you see those people doing those "dust in the wind" samples kinda like this http://www.youtube.com/watch?v=DQ-N2...elated&search= ) I'd just look for anything over a specified intensity and use those pixels for modification. I'll have a small sample of the latter posted up later today, if not tomm.

    Last edited by MotoMan_Yz400; Aug 2nd, 2007 at 12:05 PM.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Feb 2007
    Posts
    180

    Re: read image intensities [VB.NET2005]

    well i have the program working now. It uses a recursive method to locate each blob then records the min and max of each blob. I'm using the getpixel method, and it get about 1 FPS. Now going to re-write this code using the marshal class. should run it upward of 30-80fps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width