Results 1 to 5 of 5

Thread: math/algorithm to find a rectangle and a circle in a picture

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    132

    math/algorithm to find a rectangle and a circle in a picture

    im not sure i am posting on the correct forum but this is the only one i though suitable.

    i am trying to think of the best (fastest) way to search for a rectangle in a picture frame taken from a webcam . and also circle (seperatly)
    the "problem" is that the rectangle can be turned cw and ccw .

    and when i say "way" , i mean algorithm using math.
    and as for the webcam, i got all the code for it, so thats not what i will be talking about. i will talk about single frame of picture

    it is known that the efficiency with these things is as less pixel scanning and more math calculations , is faster , because pixel scanning takes much longer time and resources.

    so i came up with some idea and would like to hear your opinion and suggestions

    ok first rectangle - refer to first attached picture
    i have many colored points (pixels) which i will mention
    2 red ; 2 purple ; 4 blue ; 4 green ; and 4 yellow

    so my idea is like this
    to start with from the 2 red dots and go vertically up and down untill i meet a black dot (which is the rectangle) . this will give me the 4 blue dots (2 up and 2 down)
    from these 2 sets of dots i can calculate the y=ax+b (or also known as y=mx+n, same thing) which is the linear equation, of the upper and lower lines of the rectangle.
    so now i will have 2 equations of y=ax+b
    next i will do the same horizontally , start from the purple dots and horizontally left and right untill i meet a black dot (which is the rectangle). this will give me the 4 green dots (2 left and 2 right)
    from these 2 sets of dots i can caluclate the y=ax+b of the left and right lines of the rectangle.

    all this will give me total of 4 equations of y=ax+b, 1 for each line.
    now i can take 2 crossing lines equations and find the intercross dot which is the edge of the rectangle. i'll have to do it for each edge, total of 4 times.
    and done.

    the problem with this method, as i see it, is what if the rectangle will be turned too much , and the green or blue dots will not be found on the correct line. that will destroy everything for me.
    refer to the second picture attachment , look at the red arrow.
    if i will come upon this black dot it will mess up my y=ax+b for the right side line of the rectangle.



    now circle is easier
    refer to the 3rd picture attached

    i'll start with the purple dot
    and scan pixels vertically up and down untill i find a black pixel which is the circle its self. this will give me the 2 green dots and from that it will be easy to calculate the Y center of the circle (orange/brown dot)
    i'll do the same horizontally which will give me the 2 yellow dots and from that it will be easy to calculate the X center of the circle (orange/brown dot)
    combining the center X and the Y will give me the complete center point of the circle (black dot)

    then i can scan pixels from the center in the up direction ( or down or left right , doesn't matter) untill i meet the circle. this will give me the RADIUS.
    and done!

    now , if the circle is infact elliptical, then not big deal, in addition of scanning from the center up , i will have to scan from the center towards right (or left, doesnt matter) this will give me the SECOND RADIUS.


    the circle is easy, but the rectangle can be a problem.

    so ?
    what do you think?
    is this a good idea?
    do you think its possible to implement?
    do you have better ideas?

    any thoughts will be appreciated
    and thanks for reading this silly post
    Attached Images Attached Images    

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