0

I want to create a motion sensor. Basically, if the iphone camera detects motion, a command will happen. To create a motion sensor in the simplest way possible, I want to make the iphone take a picture every second. Then, I want the iphone to compare the newest picture with the picture that was taken before to see if they are the same. If the pictures are the same, nothing happens (because no motion was detected). If the pictures is different, then the command will happen (because motion was detected).

In essence, I need the iphone taking a picture every second and then compare the newest picture with the previous one to see if they are identical or not.

Any help would be appreciated, thank you

adolfosrs
  • 9,286
  • 5
  • 39
  • 67
Drizzle
  • 25
  • 8
  • Have you considered using the accelerometer to detect motion? – Imran Dec 28 '15 at 22:53
  • @Imran The iphone will not be moving so I cannot use the accelerometer to aid me here – Drizzle Dec 28 '15 at 22:59
  • Ok, I see, you want to detect moving object(s) in the field of view rather than detect that you are moving. – Imran Dec 28 '15 at 23:04
  • Surely you don't want to detect if they are the exact same or not. There is enough noise and slight variations that do not indicate movement that you want to have a bit of a margin. The most basic way to do this is to compute the difference between the two images (pixel by pixel, then average). You can then set a threshold to decide if the images are "different enough". But depending on the exact application, there may be lots of other ways of doing this. – jcaron Dec 28 '15 at 23:04
  • @jcaron That sounds like a good idea. What do you think the best way of doing this is using objective c? – Drizzle Dec 28 '15 at 23:17
  • The most naïve implementation (which would be a good baseline) would be to get the bitmap data of each and do the comparison yourself. You can also try drawing one image on top of the other in a graphics context and using an appropriate blend mode to compute the difference, but then you'll still have to compute the average. There's most certainly a way to do it with `CIFilter`s as well. Or you could even use a library like ImageMagick, openCV, etc. The topic is really way to broad to provide a detailed answer here. – jcaron Dec 28 '15 at 23:34

0 Answers0