PanTilt facetracker.py ImportError: No module named 'cv2'


#1

I have the PanTilt servo setup and I am trying to run the facetracker.py but when run from within Python 3(IDLE) I get:
ImportError: No module named 'cv2’
I have run the commands
curl https://get.pimoroni.com/uptodate | bash
sudo apt-get install python-smbus python-opencv opencv-data
git clone https://github.com/pimoroni/PanTiltFacetracker -b AdafruitPWM

I have the PanTilt servo with the AdaFruit servo board for my Raspi ZeroW all wired up and the camera is attached and working so what am I missing?


#2

Hi there edjones,
Can you try running it in the Python 2 IDLE for me please? The repository version of OpenCV doesn’t include Python 3 bindings, which is probably the cause of your error.
If you’d really like to use Python 3 for any future OpenCV projects, I’d recommend removing your current version of OpenCV using sudo apt-get autoremove python-opencv and installing it again from https://github.com/milq/milq/blob/master/scripts/bash/install-opencv.sh by way of bash install-opencv.sh.
I’m just trying this out myself now, but be aware it could take some time to download and install all of the necessary packages.


#3

Hi, thanks for that. Running in IDLE 2 no longer shows that error! Now though I get “IOError: [Errno 121] Remote I/O error” after the line “/usr/local/lib/python2.7/dist-packages/Adafruit_PureIO/smbus.py line 236, in write_byte_data self._device.write(data)”

Maybe I have wired it wrong?


#4

Hmm, I’ve never run across that error before, but I doubt it has anything to do with your wiring skills (though it’s always worth a check ;) ). Perhaps just try installing sudo apt-get install libopencv-dev and try again; I didn’t notice it in your original installs.

Oh, and on a side note, be aware my Pi just started to overheat quite badly whilst installing OpenCV; unfortunately, I had to terminate it. Remember to take off your hat before you do anything demanding!


#5

I ran the “apt-get install” but still no dice but then I noticed that the green power light on the Adafruit servo board was not always lit and sometimes only slightly. This is very likely down to me just trying to push the pins into some polystyrene but was obviously not a good enough connection. Time for some soldering I think which is something I haven’t done before so could be interesting!

Incidentally which Pi are you using, do you think it will work on the Pi ZeroW?


#6

I’m personally using the Pi 3, however, I’m using Pimoroni’s own PanTilt hat, so I’m not too familiar with Adafruit’s board. As long as there is enough power for the servos to be driven I’m sure it’d work fine, just keep an eye on your under and over voltage warnings!


#7

After a bit of soldering, all is happy now! Thanks for the help! I didn’t realise there was a HAT version as well so I have just ordered that for the Pi2 I have sitting doing nothing but now I can give it a purpose. Everyone is happy!


#8

Great! And no problem. I hope your Pi2 enjoys the new attire. :)