3

My intension is to use raspberry Pi for tracking coloured object. I am using Python, OpenCV and Raspberry pi Camera Module.

Since OpenCV doesn’t work out of the Box with raspberryPi cam Module, I trying to use Mikerr’s PiVision Lib (https://github.com/mikerr/piVision/blob/master/colortrack.py)

In Mikerr’s lib he saves the image to disk and opens it with OpenCV to get the frame object which can be used for further processing i.e.

frame=cv.LoadImage(imagefile,cv.CV_LOAD_IMAGE_COLOR)

Dave Jones’ (author of python-picamera) has already written a lib to use the Picamera with Python and he has briefly explained it to use with OpenCV(http://picamera.readthedocs.org/en/release-1.6/recipes1.html#capturing-to-an-opencv-object).

So I want to retrieve the frame from Dave Jones’ lib and input it to Mikerr’s Lib like this

with picamera.Picamera() as camera:
    camera.resolution = (640, 480)
    camera.framerate = 24
    stream = io.BytesIO()

    while True:
        camera.capture(stream, format="jpeg", use_video_port=True)
        frame = np.fromstring(stream.getvalue(), dtype=np.uint8)
        stream.seek(0)
        frame = cv2.imdecode(frame, 1)

Do you this this is possible and will the frame I get both the code above be same (in terms of datatype)

Please can someone through some light on it? Also what type of Import we should use i.e. import cv2.cv as cv or import cv or import cv2

2
  • 1
    U may want to try this example from: opencv with motor
    – user19806
    Commented Aug 20, 2014 at 8:56
  • @Supra Thanks for finding this out. cv2.imdecode does return you the CV2 image. If you add this to answer i mark it so that other can benefit from it.
    – SD13
    Commented Aug 21, 2014 at 11:55

2 Answers 2

1

I am using Python, OpenCV and the pi Camera module to check (realtime) if there is a certain object present in the image.

I'm using in my Python code:

camera_index = 0
camera=cv2.Videocapture(camera_index)
camera.set(3,320)
...

and then further on:

def getCamFrame(camera):

    _,frame=camera.read()

and then you can start doing some operations on that image, e.g. convert to grayscale:

gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)

I can't give you the entire code as I can't to connect to that PI right now, but let me know if you need more pieces of that code or any other info.

1
  • thanks you for your Answer. This was quite old question but nice to see you answering that.
    – SD13
    Commented Jan 23, 2018 at 12:39
0

cv2.imdecode does return you the CV2 image.

2
  • Would you elaborate a little bit on that? Maybe include an example?
    – Bex
    Commented Mar 24, 2015 at 9:59
  • @Bex the code in the question is the example. Once we have the frame we can use it in OpenCV functions to perform blur or other operations. Is there anything particular you are looking for?
    – SD13
    Commented Mar 26, 2015 at 16:15

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.