Shop OBEX P1 Docs P2 Docs Learn Events
JPG Photo File Analysis Using Basic Stamp — Parallax Forums

JPG Photo File Analysis Using Basic Stamp

garyggaryg Posts: 420
edited 2012-10-10 16:12 in BASIC Stamp
Hi
Has anyone attempted to build a matrix from a JPG photo file using a Basic Stamp controller?
Resolution of the file could be pretty poor.
I would like to take a photo of an area of my yard.
Then after time has passed,
take another photo and compare it with the 1st photo to see if there are any differences.
Possibly aim my steering mechanism to point of the differences and
drive my platform to the difference point.

I realize I'm at this time being quite vague.
This is a new adventure and I'm needing a starting point.

I'm building a scarecrow type platform that will discourage rabbits, deer and ground hogs from eating my garden.
The prototype platform has been completed and is currently RC controlled.

I've used BS1 and BS2 controllers in the past and am willing to use Propeller or other microcontroller to accomplish this goal.

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-10-01 17:30
    You'll need a whole lot more memory and horsepower for that than what the BASIC Stamps can provide. I'm not even optimistic about the Propeller being able to handle decoding JPEGs for comparison purposes.

    That said, however, why not do the JPEG stuff on your PC and use a connected BASIC Stamp for controlling the pan, tilt, and zoom?

    -Phil
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-10-01 18:10
    JPEG images are divided up into small 8x8 blocks. Each block is encoded by performing a DCT (Discrete Cosine Transform) on it. This converts the 64 pixel values in a block into 64 transform coefficients that can be encoded more efficiently. One of the coefficients is called the "DC coefficient", and it is the average value of the 64 pixels in the block. It is fairly easy to extract the DC coefficient for each block and generate an image that has one-eight of the resolution horizontally and vertically. As an example, you could reconstruct an 80x60 image using the DC coefficients from a 640x480 image. I don't know how much memory a stamp has but you might be able to use this method to get a low-res version of the image.
  • ercoerco Posts: 20,256
    edited 2012-10-01 18:33
    Interesting idea. With some work, you could do something VERY low res (10x10 blocks or so), but somehow you'll have to compensate for varying light levels throughout the day as the sun moves.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-01 18:40
    There are a couple of different NTSC capture methods for the Propeller. I think using a cheap video camera (NTSC) would be easier for the Propeller to analyze than a JPG image.

    Post #4 of my index has some Propeller machine vision links.
  • garyggaryg Posts: 420
    edited 2012-10-01 19:49
    This sounds very familar to trying to decifer the HPGL codes to make my step motor CNC to plot correctly.
    I was successfully able to complete my CNC project, although it runs very slowly.

    Phil - What would be the max amount of Memory and Horsepower available for a project like this?
    I need to compare what is available to what I need.

    Erco - Where did you come up with the 10x10 blocks.
    I may very easily be able to use resolution of 10x10 blocks.

    Dave - Any suggestions on where to find a way to read the 8x8 blocks from the original file?
    This sounds somewhat possible to me.

    Duane - is NTSC the same thing that television uses to define the picture displayed?
    If I can somehow read a series of line scan numbers, I may be able to determine if something has changed.


    Thanks for all of your help so far.

    Any additional comments would be appreciated.

    Please understand that I'm trying to find a means to an end.
    I've printed your comments so far and will be attempting to find answers to this path.
    I've never gone down this road before.
    I've looked at Parallax PIR Sensor, but if it moves it will detect movement that doesn't exist.
    I've looked at Parallax X-band motion detector, but it seems like it will pretty much do what PIR Sensor does if
    the motion detector moves to scan an area.
    I've considered PING sensors, but I need to figure out how to make them see what they are talking about.

    That's what lead me to believe it may be more reliable to somehow interpret some type of photo image and compare
    it with a source image.


    Thanks again
    garyg
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-01 20:39
    garyg wrote: »
    Duane - is NTSC the same thing that television uses to define the picture displayed?
    If I can somehow read a series of line scan numbers, I may be able to determine if something has changed.

    This might work for your application.

    My experience with video capture was to use Hanno's method of capturing a black and white images from a NTSC camera (I think either a color or a b&w camera would work).

    Hanno only used four of the eight bits of from the ADC chip in the image he had transmitted to a PC. Since I was interested in displaying the captured image on a 12 x 10 LED array, I used 8-bits but only 120 pixels.

    I had an 120 byte buffer in the Props memory. My program would use whatever values were in these 120 byte to set the brightnss of the 120 LEDs.

    Here's my setup displaying what the small camera (held by my fingers in the top left of the photo) sees, on the LED array.

    attachment.php?attachmentid=80519&d=1303582009

    It may not be clear, but the word "HI" on the white board is being displayed on the array.

    In this example, I could save the 120 bytes from one capture and then compare it against a later capture. If the value (brightness level) of enough of the bytes in one section of the image changed beyond a predetermined threshold, this could be an indication of movement within the field of view of the camera.

    I used 120 pixels in this case because that was the size of my LED array. You might want to use more pixel or fewer pixels. I'd think this would require a lot of experimentation.

    Phil has developed several video capture methods for the Prop (including color capture). You might want to check out his techniques before deciding which method you want to try.
  • garyggaryg Posts: 420
    edited 2012-10-03 08:19
    Thanks for all of your opinions.
    The NTSC camera matrix sounds pretty interesting
    I also never really thought about using my PC to do the heavy lifting of photo analysis.

    In some manner, I could possibly use a stationary camera platform with PC attached.
    then activate my platform to travel to the photo difference area either by having the platform detach from the pc or
    by some wireless means, even if the wireless means is controlling my RC transmitter using servo motors operated by
    the PC.

    It may take quite a bit of my time over this winter to work this all out.
    I've purchased a couple of parallax sensors, compass and ping to help with direction and close range object measurements.
    and
    I will be starting to look at analyzing some photos.

    Thanks again
  • vaclav_salvaclav_sal Posts: 451
    edited 2012-10-10 16:12
    The major challenge in video analysis on any hardware is that low cost cameras as a system ( resolution, memory, frame capture speed, communication to host etc.) produce very noisy signal.
    Simple comparison of captured frames just does not work in the real world.
    FYI - check OpenCV ( OpenComputerVision ) discussion board to get a feel for video challenges.
Sign In or Register to comment.