OpenCV and Player store their image data in similar array structures.  The OpenCV Python interface documentation [1] has an example for PIL Image -> OpenCV that looks like a good jumping off point.  I’ve been successful in converting Player images to IplImages and back in C++, I don’t think it’s terribly different in Python.  It looks like you need to do something like:

 

from playerc import *

import cv

client = playerc_client(None, ‘localhost’, 6665)

cam= playerc_camera(client,0)

 

cv_im = cv.CreateImageHeader((cam.width,cam.height), cv.IPL_DEPTH_8U, cam.depth/8)

cv.SetData(cv_im, cam.image)

 

If you’re using color images, you might have to do a cvCvtColor(src, dest, CV_RGB2BGR), as the IplImage* structure inexplicably stores image data in BGR format.  I’m not a python expert, and I would be quite surprised if the above code runs, but I think I’ve captured the gist of the conversion.

 

Rich

 

[1] http://opencv.willowgarage.com/wiki/PythonInterface

 

From: Torbjörn Svangård [mailto:trptorbjorn@gmail.com]
Sent: Wednesday, March 24, 2010 11:12 AM
To: playerstage-users@lists.sourceforge.net
Subject: Re: [Playerstage-users] Playerstage-users Digest, Vol 46, Issue 31

 

Hi all and greetings to everyone involved in Player/Stage development and support!

Me and some fellow students are trying to get images from camera device on player using python. I would like to get the image into opencv IplImage format alternatively to PIL format. However all our attempts fail when trying to get data from cam.image
Can anyone point me in the right direction?
Ubuntu 9.10
Player v.3.0.1

import cv
from playerc import *

client = playerc_client(None, 'localhost', 6665)
cam = playerc_camera(client, 0)
print cam.width
print cam.height
print cam.image

----- Outputs -----------
640
480
<Swig Object of type 'uint8_t *' at 0x8e102d8>
-------------------

Same problem posted here, but i cant find any answers:
http://article.gmane.org/gmane.science.robotics.playerstage.user/8625/match=playerc_camera