Reputation: 436
So far I have followed this tutorial to install OpenCV in RaspberryPi for Python. It says simply to run:
sudo apt-get install libopencv-dev python-opencv
But I've looked around internet and I've found there are more libraries to install than that, as in these two similar tutorials:
1) http://denis.doublebuffer.net/lablog/2012/08/10/setting-everything-up-for-opencv-raspberry-pi/
2) http://eduardofv.com/read_post/185-Installing-OpenCV-on-the-Raspberry-Pi
Doubts about my incorrect installation of OpenCV are based on the delay in the visualisation of the sequence with this following simple code. It just gets the frames from the camera (RPi camera module) and shows them:
import cv2
cap = cv2.VideoCapture(0)
while True:
b,frame = cap.read()
cv2.imshow("frame", frame)
cv2.waitKey(1)
As I said above the visualization is flowing but delayed.
Upvotes: 3
Views: 12793
Reputation: 3709
If you're able to import it, then I would guess that you've installed it correctly. If you're in doubt, you can install it from the source, although it takes a while on the Raspi.
Try this code:
import cv2
import cv2.cv as cv
import numpy
class test():
def __init__(self):
cv.NamedWindow("w1", cv.CV_WINDOW_NORMAL)
self.capture = cv.CreateCameraCapture(-1)
self.vid()
def vid(self):
while True:
self.frame = cv.QueryFrame(self.capture)
aframe = numpy.asarray(self.frame[:,:])
cv2.imshow("w1", aframe)
c = cv.WaitKey(5)
if c == 110:
exit()
p = test()
Also, see the answer to this question (assuming you're using the Raspicam)
Upvotes: 2