Sayfalar

9 Ağustos 2017 Çarşamba

Python - OpenCV Hit The Ball - Top sektirmece :)


A mini "hit the ball" game was implemented by using OpenCV and numpy libraries of Python. If you want to move your head and do a few tricks with the ball :) while sitting at your home or office, you can download the .py files (codes) at the end of this page and run it.

Some details about the algorithm used in this mini-example; Firstly, RGB image is converted to gray scale and gray scale image is blurred with GaussianBlur function. Then each frame is subtracted with previous one and difference image is acquired.
gray = cv2.cvtColor(frame.copy(), cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (21, 21), 0)
frameDelta = cv2.absdiff(previous, gray)

Image differencing is used to determine changes between successive frames, and SIFT algorithm is applied to find the key points. Alternatively, you can use some other  background subtraction algorithms  like BackgroundSubtractorMOG or motion detection algorithms implemented in OpenCV.


kp = sift.detect(frameDelta,None)
cv2.drawKeypoints(frameDelta,kp,img)



Balls movement job is done with the class named Balls. This class includes methods drawadd_ballmove_balls and collision. I think the name of the methods gives enough hints to understand what they do. However, this example includes only one moving ball but if you want to add more, It is easy to implement/adapt with so less code change or addition. Click to download the .py files...

Hiç yorum yok:

Yorum Gönder