Tracking and follow object

Hi!! i’m developing a project where i’d like to track an object and follow it with the gopigo, for example a tennis ball.

My mainly problem is that i don’t know how i could start. I’ve been reading a lot, and as far as i am concerned, i am forced to install OpenCV. What i want to ask you before i install it, is:

Do you know something alternative and easier which i could achieve the same results? If not, how can i start to face to track&follow an object project i mention?

Apart from that, could i put into my raspberry pi a 32 gb micro sd card in order to ensure that the installation of the OpenCV will fit inside my sd card?
Thanks a bunch !!!

Hey 71Davess,

Sounds like an awesome challenge! In our experience, OpenCV is your best way to go. It works really well with the Pi, and if you’re using a Pi2, you have a lot more procesing power to use.

I wrote a blog post about this a few weeks ago.

One of our contributors did a great writeup of using OpenCV to do object tracking and computer vision. The writeup is great, it really breaks it down to easier steps.

Let us know how it goes! If we can help with anything else, please let me know.

Hi John!

Thank you very much!! As soon as i get working something i’ll post here.

But one question, is there anything focused on the GoPiGo? I’ve seen that the writeup goes about BrickPi, and i’m not sure if i can use some examples of the BrickPi.

Anyway, i can guide myself with those examples, at least, i can take a look and uderstand the codes and , but if you know something focused on the GoPiGo, please let me know.

This is a part of my final degree project and i am a little bit lost with raspberry but I’ll follow the writeup and some articles i found. I’ll tell you how it goes!

Here you are a pic of my GoPiGo!
Thanks again!

And one more thing. Does your wheezy system OpenCV or do i need to install it once i have installed the wheezy on the Raspberrypi?

The SD card does not come with OpenCV installed and you would have to compile and install it yourself. The last time we did it for the B+, it was a multihour process, so it would take some time.

I second John, and really think that Pi2 is the right choice for OpenCV, but you should make sure that the steps you follow are for Pi2 only. There was a difference in the ARM architecture so I think the steps would be a bit different for Pi.

Also, do share your project with us when it’s done. We have an Instructables contest running too, so you can post your project there and you might end up winning some awesome goodies.


Thank you very much karan!
Now i’m going to install Open CV. I bought the model B+, and i will develop through it in spite of the fact that it should work better on the Pi2, but i have no time.

I bought a 32gb microSD card due to OpenCV didn’t fit on the 4gb card i bought from your page. Now i’m going to reinstall everything, including OpenCV and as soon as i have something i’ll let you know. Once i have the project done i’ll share it with everyone :slight_smile:

Once again, THANKS !!

Hey 71Davess,

due to OpenCV didn’t fit on the 4gb card i bought from your page.

Did you try expanding rootfs?

Yes i did, but it wasn’t enough. I bought an 32 gb micro Sd card and i have now installed OpenCV without problems.

Hello Everyone!! I’ve been working hard these two weeks!! And i have currently working openCV on my GoPiGo, but i have a little problem.

When i’m going to use your library “gopigo” and i’m going to import it in my code "from gopigo import * " in order to use the basic controlls as fwd(), stop(), etc. The compiler tells me the next:

(cv)pi@raspberrypi ~/Desktop $ python
"Traceback (most recent call last):
File “”, line 8, in <module>
from gopigo import *
ImportError: No module named gopigo"

so there is a problem i don’t understand. I use your examples and they all work, but when i’m going to import “*” from “gopigo” in other script, i get an error. I know that it’s a silly question, but i’m new in python and in all this world.

So, Could you please tell me how i could use your libraries to carry on with my project? I’ll be very grateful.

Any help is appreciated.

P.S.: As soon as i finished my project, i’ll share it with everyone, hoping you like it! And Here you are a pic of the error.

You should run in the Software/Python folder or just run

  • pip install gopigo
  • to install the GoPiGo library system wide.


    I have installed it, and now, the next is happening:

    I run your test scripts and they work if i write on putty:
    - sudo python
    but If i write just:
    - python
    I get the error:
    "from gopigo import *
    ImportError: No module named gopigo"
    But executing a script with the camera, if i do:
    - sudo python
    I get the error:
    "Traceback (most recent call last):
    File “”, line 2, in <module>
    from picamera.array import PiRGBArray
    ImportError: No module named picamera.array

    And if i do:
    Works perfectly, but i get again the error:
    “from gopigo import *
    ImportError: No module named gopigo”

    So i don’t know how to use both libraries in the same script. I can solve one problem, but then the another one appears. I am conscient that maybe is something related with the super user, or the folders i need to install the gopigo.

    I have a folder with opencv installed, do i need to install the gopigo inside this folder?

    Sorry for asking too much and these simple questions, but i’m a noob in that field, and are questions related with linux commands, users and directories, which i almost know nothing.

    Any help is appreciated.

    Thank you again and again and again!

    The GoPiGo does need I2C to communicate with the Raspberry Pi and I think that it needs super user access. You can try to copy paste the library in the same folder, but I’ll still recommend you to use sudo when running the code.


    I’ve done this, and i get one of the other errors :

    sudo python
    Traceback (most recent call last):
    File “”, line 2, in <module>
    from picamera.array import PiRGBArray
    ImportError: No module named picamera.array

    So what should i do now in order to avoid it?

    Thanks a bunch, seriously!

    I don’t want to hop over Karan on this, just throwing my two cents in here.

    Is this a picamera problem? Could you reinstall the picamera module?

    I can try it, but i’ve been testing things with the camera and i had no problem with it, though i needed to test everything with 5fps and a low resolution due to works really slow. I don’t know if this normal or if it can work faster.

    And do i need to install the picam in a specific folder? or wherever i want ?

    Thank you very much.

    I am not sure about the PiCam installation, but I think it won’t matter much where you install it because the libraries are installed system wide and should work.

    Now with regard to the low frame rate, that would be a problem with the original Pi. But you can try reducing the video resolution which should increase the frame rate.



    I have tried to install the PiCamera again and is still happening the same problem. I think it’s something related with the I2C you told me Karan. But i don’t know what’s happening, though i guess it’s something about the connection between the GoPiGo and the Raspberry.

    Here i send you the file i’ve programmed(in txt, so please change the extension to .py if try). If you could run this program on a GoPiGo Robot with OpenCV installed, and know what to do in order to work, i’ll be very very very grateful to all of you.

    So, any help is appreciated.
    Thank you and thank you again.

    Hi again,

    Well, i don’t know if it’s an achievement or not, but copying the folder Python from GoPiGo/Software/Python, installing there the “” and putting my programme on this location, i get the error showed on the picture above. If this is not a “next step” to solve the problem, please, let me know it and i’ll remove the Python folder from the opencv Folder.

    Thanks a bunch and excuse for my insistence.

    You should go ahead and install the pySerial library: pip install pyserial. Let us know if that helps.


    Hey! Thanks again Karan!

    It’s seems it works, this error doesn’t appears anymore, but now i get troubles with the next “import”:

    import smbus
    ImportError:No module named smbus

    So i did:
    sudo apt-get install python-smbus

    But the error is still appearing.
    So i delete the sentence “import smbus” just to try what would happen, and it seems that i’m going to have problems with all the “import”'s inside

    Later i tried to run your and i realize that i have the same problem i had with my
    “from gopigo import *
    ImportError: No module named gopigo”

    So in order to use your “”, i need to type:

    sudo python

    Is there any way to execute this without using sudo? I think it would solve the problem.

    If not, is any way to use opencv with sudo? I say that due to when i use sudo python insted of python, if i import in the script: “import cv2”, which is opencv, i get this other error:

    ImportError: No module named cv2

    So something related with permissions is happening here.

    Again, any help is appreciated.
    Thank you!