3

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.

1 Answer 1

2

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)

Sign up to request clarification or add additional context in comments.

4 Comments

Yes, I've already read that discussion and indeed I've set it in that manner. Your code works in real time. Thanks! Two questions: Therefore to speed up I have always to convert the output of cv.QueryFrame() in an array, right? What is the main difference between cv2.VideoCapture (or cv.CaptureFromCAM) and cv.CreateCameraCapture?
There is a big problem: changing the resolution by cv.SetCaptureProperty introduces the delay again. So it works in real-time only for small resolution. Can I do anything for it?
Might be worth it to try overclocking the device and see if it improves performance
I do not think is a CPU problem (RPi has 700MHz) since commands like raspistill or raspivid work in real-time with the highest resolution. Therefore I wonder, if this is a simple acquisition and visualisation by OpenCV and it is not in real-time, what could happen if I begin a processing? Lags added to lags ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.