Transforming captured co-ordinates into screen co-ordinates

后端 未结 6 1816
夕颜
夕颜 2020-12-04 22:35

I think this is probably a simple maths question but I have no idea what\'s going on right now.

I\'m capturing the positions of \"markers\" on a webcam and I have a

6条回答
  •  醉梦人生
    2020-12-04 23:28

    Since your input area isn't a rectangle of the same aspect-ratio as the screen, you'll have to apply some sort of transformation to do the mapping.

    What I would do is take the proportions of where the inner point is with respect to the outer sides and map that to the same proportions of the screen.

    To do this, calculate the amount of the free space above, below, to the left, and to the right of the inner point and use the ratio to find out where in the screen the point should be.

    alt text http://img230.imageshack.us/img230/5301/mapkg.png

    Once you have the measurements, place the inner point at:

    x = left / (left + right)
    y = above / (above + below)
    

    This way, no matter how skewed the webcam frame is, you can still map to the full regular rectangle on the screen.

提交回复
热议问题