Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. diffucult: how can i measure velocity with a webcam?

diffucult: how can i measure velocity with a webcam?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiongraphicsperformance
13 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A andreas schaerer

    hy, i have a sample program, in which i can grab bitmaps or avis from any webcam. now, what im trying to do is to measure the velocity of movements, like lets say the movement of a hand. so when you shake your hand in front of the webcam, the program should put out a factor between 1-4 1 for slow and 4 for fast. i tryed several things, like comparing 2 bitmaps every 200ms, etc. but it all didnt worked . and also performance is a big issue. i compare the bitmap with bmpPicture.GetPixel(nW,nH) etc. so i need to compare every pixel. does anybody has an idea of how i can solve this problem? maby there is some code out there i can use, or a simpler approach? thanx a lot!

    B Offline
    B Offline
    bryce
    wrote on last edited by
    #3

    hmm you probably need to standardise the distance so you know that the hand is always i metre away from the camera say. Then you probably could figure out the "width" and "height" of the view from 1 metre. and then you can tell that 1 pixel at NxM res' corresponds to a set area. then it comes down to figuring out when and where the motion started and when and where it finishes. Sounds like a 3 year computer science project to me :) Bryce --- Publitor, making Pubmed easy. http://www.sohocode.com/publitor

    A 1 Reply Last reply
    0
    • 7 73Zeppelin

      I don't have code, but why don't you sample bands instead of the entire image? For example, if you had a 10 x 10 pixel image (using 10 here just to illustrate...) you could sample every 2 pixels and reduce by a factor of 2. (ie: 5 bands) Or, you could even sample every 5 bands and reduce by a factor of 5 (ie, you would have 2 samples - 10 /5 = 2...) Was that clear?? You could even be really elegant and sample as per a comb filter at the Nyquist frequency! John Theal Physicist at Large Got CAD? http://www.presenter3d.com[^]

      A Offline
      A Offline
      andreas schaerer
      wrote on last edited by
      #4

      hy,so you mean i should basically reduce the imagesize of the images i compare? but in the end i must compare pixels etc? i think youre right, maby even black/white pictures will do the job. what do you mean with "You could even be really elegant and sample as per a comb filter at the Nyquist frequency!" ? thanx, greez

      1 Reply Last reply
      0
      • B bryce

        hmm you probably need to standardise the distance so you know that the hand is always i metre away from the camera say. Then you probably could figure out the "width" and "height" of the view from 1 metre. and then you can tell that 1 pixel at NxM res' corresponds to a set area. then it comes down to figuring out when and where the motion started and when and where it finishes. Sounds like a 3 year computer science project to me :) Bryce --- Publitor, making Pubmed easy. http://www.sohocode.com/publitor

        A Offline
        A Offline
        andreas schaerer
        wrote on last edited by
        #5

        3 years,oh my gosh!? i thought i could do this in an afternoon:-) but im convinced there is an easy approach! and remember, all i want is relative velocity, not abolute. i just want to know if the hand moves slow or fast. so i was thinking about making every x ms a bitmap, and then compare them. lets say i wear a white t-shirt, and my hand is black. so when i move the hand up and down i could detect, how many light or dark pixels are in lets say 4 zones of the bitmap. so i could detect the position of the hand, and with that also the velocity. i think i could do this in 2 days, ;-) what do you think??

        B 1 Reply Last reply
        0
        • A andreas schaerer

          3 years,oh my gosh!? i thought i could do this in an afternoon:-) but im convinced there is an easy approach! and remember, all i want is relative velocity, not abolute. i just want to know if the hand moves slow or fast. so i was thinking about making every x ms a bitmap, and then compare them. lets say i wear a white t-shirt, and my hand is black. so when i move the hand up and down i could detect, how many light or dark pixels are in lets say 4 zones of the bitmap. so i could detect the position of the hand, and with that also the velocity. i think i could do this in 2 days, ;-) what do you think??

          B Offline
          B Offline
          berndg
          wrote on last edited by
          #6

          Comparing two bitmaps (or anything) is simple; just compute a CRC over both and you will know whether anything has changed or not. However, this is not the solution to your problem. You'd need to detect characteristic patterns (at least in case two subsequent images that are in fact different) in the first, try to locate the similar pattern in the second, measure the distance along X and Y axis, employ a second camera at a slightly different angle so that you can establish the distance along Z, know the time between the two pictures, and you're done. Oh, you will also have to recognize similar but distinct patterns: the hand might turn a little when being moved, the ball might rotate, the cloud changes shape. Not sure about the 3 years, but 1+: definitively. Enjoy! Bernd

          A 1 Reply Last reply
          0
          • B berndg

            Comparing two bitmaps (or anything) is simple; just compute a CRC over both and you will know whether anything has changed or not. However, this is not the solution to your problem. You'd need to detect characteristic patterns (at least in case two subsequent images that are in fact different) in the first, try to locate the similar pattern in the second, measure the distance along X and Y axis, employ a second camera at a slightly different angle so that you can establish the distance along Z, know the time between the two pictures, and you're done. Oh, you will also have to recognize similar but distinct patterns: the hand might turn a little when being moved, the ball might rotate, the cloud changes shape. Not sure about the 3 years, but 1+: definitively. Enjoy! Bernd

            A Offline
            A Offline
            andreas schaerer
            wrote on last edited by
            #7

            maby youre right! nevertheless ill try to do it in 3 days:-) could you maby explain me shortly what means to compute a CRC over both images? thanx

            B 2 Replies Last reply
            0
            • A andreas schaerer

              maby youre right! nevertheless ill try to do it in 3 days:-) could you maby explain me shortly what means to compute a CRC over both images? thanx

              B Offline
              B Offline
              berndg
              wrote on last edited by
              #8

              Oh - it means to compute a checksum over the images. This will be quicker than pixel-by-pixel comparison. It might even be faster (depending on your CPU power and bitmap size) to compress these images, and then to compute the checksum over the compressed data. CRC is the name for a family of standard checksum algorithms. Simply adding all bytes will not be good enough, you'd need something that produces a different signature (aka checksum) for different data. A simple addition won't do. Bernd

              A 1 Reply Last reply
              0
              • B berndg

                Oh - it means to compute a checksum over the images. This will be quicker than pixel-by-pixel comparison. It might even be faster (depending on your CPU power and bitmap size) to compress these images, and then to compute the checksum over the compressed data. CRC is the name for a family of standard checksum algorithms. Simply adding all bytes will not be good enough, you'd need something that produces a different signature (aka checksum) for different data. A simple addition won't do. Bernd

                A Offline
                A Offline
                andreas schaerer
                wrote on last edited by
                #9

                ah, ok, but i think that would be difficult, because every frame you capture is basically different, even if nothing moves, because of the signal/noise ratio..ok, thanx for your help!

                1 Reply Last reply
                0
                • A andreas schaerer

                  maby youre right! nevertheless ill try to do it in 3 days:-) could you maby explain me shortly what means to compute a CRC over both images? thanx

                  B Offline
                  B Offline
                  berndg
                  wrote on last edited by
                  #10

                  Andreas, You might want to read this - technologies like the Lempel Ziv Welch compression algorithm are designed to detect similarieties and reoccurring patterns. For example, you might have two subsequent shots A and B(bitmaps). You could reduce their complexity by reducing the color resolution to B/W, or 4 grayscales maybe. Then you could create bitmap C = A + B by simply appending the two, run it through LZW and see where signifficant reoccurring patters are. Next, you could rotate B by 90 degrees clockwise to B', create C' = A + B', and run this through LZW. This could give you a start, at least for verical and horicontal movement. Not sure. This is just brainstorming. Good luck, Bernd

                  1 Reply Last reply
                  0
                  • A andreas schaerer

                    hy, i have a sample program, in which i can grab bitmaps or avis from any webcam. now, what im trying to do is to measure the velocity of movements, like lets say the movement of a hand. so when you shake your hand in front of the webcam, the program should put out a factor between 1-4 1 for slow and 4 for fast. i tryed several things, like comparing 2 bitmaps every 200ms, etc. but it all didnt worked . and also performance is a big issue. i compare the bitmap with bmpPicture.GetPixel(nW,nH) etc. so i need to compare every pixel. does anybody has an idea of how i can solve this problem? maby there is some code out there i can use, or a simpler approach? thanx a lot!

                    A Offline
                    A Offline
                    Andrew Walker
                    wrote on last edited by
                    #11

                    You should check out OpenCv, which is an open source image processing library which has a whole branch associated with calculation of optical flow (it also has a built in feature tracker). The sample apps which come with it are helpful, and there is a yahoogroup if you get stuck. If performance is a big issue, you're probably going to need to use directshow to capture the images from the webcam. Check out the playcap sample in the DirectX SDK.


                    If you can keep you head when all about you Are losing theirs and blaming it on you; If you can dream - and not make dreams your master; If you can think - and not make thoughts you aim; Yours is the Earth and everything that's in it. Rudyard Kipling

                    S 1 Reply Last reply
                    0
                    • A Andrew Walker

                      You should check out OpenCv, which is an open source image processing library which has a whole branch associated with calculation of optical flow (it also has a built in feature tracker). The sample apps which come with it are helpful, and there is a yahoogroup if you get stuck. If performance is a big issue, you're probably going to need to use directshow to capture the images from the webcam. Check out the playcap sample in the DirectX SDK.


                      If you can keep you head when all about you Are losing theirs and blaming it on you; If you can dream - and not make dreams your master; If you can think - and not make thoughts you aim; Yours is the Earth and everything that's in it. Rudyard Kipling

                      S Offline
                      S Offline
                      schaereran gmx net
                      wrote on last edited by
                      #12

                      ok, thanx for the tip! what do you think about Vision SDK from MS? i tried several times to run any sample porgram, but i never could compile it, i always had errors!!!! greets

                      A 1 Reply Last reply
                      0
                      • S schaereran gmx net

                        ok, thanx for the tip! what do you think about Vision SDK from MS? i tried several times to run any sample porgram, but i never could compile it, i always had errors!!!! greets

                        A Offline
                        A Offline
                        Andrew Walker
                        wrote on last edited by
                        #13

                        If it's the SDK I'm thinking of (and from a very quick look at the Microsoft website, it is) it stinks. We had heaps of problems with it when we did a little work, and found that OpenCV with pure directshow was a much better solution. Even still it took a long time to get everything up and running properly, and we were learning it from scratch.


                        If you can keep you head when all about you Are losing theirs and blaming it on you; If you can dream - and not make dreams your master; If you can think - and not make thoughts you aim; Yours is the Earth and everything that's in it. Rudyard Kipling

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups