|
From: <jam...@us...> - 2009-07-17 23:50:56
|
Revision: 19151
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=19151&view=rev
Author: jamesbowman
Date: 2009-07-17 23:50:49 +0000 (Fri, 17 Jul 2009)
Log Message:
-----------
camera mode test
Modified Paths:
--------------
pkg/trunk/stacks/camera_drivers/dcam/src/python/dcam.cpp
pkg/trunk/vision/vision_tests/manifest.xml
pkg/trunk/vision/vision_tests/scripts/camera_hammer_1.py
Added Paths:
-----------
pkg/trunk/vision/vision_tests/scripts/
pkg/trunk/vision/vision_tests/scripts/loop.py
Removed Paths:
-------------
pkg/trunk/vision/vision_tests/src/
Modified: pkg/trunk/stacks/camera_drivers/dcam/src/python/dcam.cpp
===================================================================
--- pkg/trunk/stacks/camera_drivers/dcam/src/python/dcam.cpp 2009-07-17 23:37:00 UTC (rev 19150)
+++ pkg/trunk/stacks/camera_drivers/dcam/src/python/dcam.cpp 2009-07-17 23:50:49 UTC (rev 19151)
@@ -34,110 +34,41 @@
static void dcam_dealloc(PyObject *self)
{
+ // dcam::fini();
dcam_t *pc = (dcam_t*)self;
delete pc->dev;
PyObject_Del(self);
}
-#if 0
-static PyObject *dcam_repr(PyObject *self)
+static uint8_t *getdata(ImageData *id)
{
- dcam_t *cva = (dcam_t*)self;
- IplImage* ipl = (IplImage*)(cva->a);
- char str[1000];
- sprintf(str, "<dcam(");
- char *d = str + strlen(str);
- sprintf(d, "nChannels=%d ", ipl->nChannels);
- d += strlen(d);
- sprintf(d, "width=%d ", ipl->width);
- d += strlen(d);
- sprintf(d, "height=%d ", ipl->height);
- d += strlen(d);
- sprintf(d, "widthStep=%d ", ipl->widthStep);
- d += strlen(d);
- sprintf(d, ")>");
- return PyString_FromString(str);
+ // left window display, try rect, then raw
+ if (id->imRectColorType != COLOR_CODING_NONE)
+ return id->imRectColor;
+ else if (id->imRectType != COLOR_CODING_NONE)
+ return id->imRect;
+ else if (id->imColorType != COLOR_CODING_NONE)
+ return id->imColor;
+ else if (id->imType != COLOR_CODING_NONE)
+ return id->im;
+ else
+ return NULL;
}
-
-static PyObject *dcam_tostring(PyObject *self, PyObject *args)
+static size_t getdatasize(ImageData *id)
{
- IplImage *i;
- if (!convert_to_IplImage(self, &i, "self"))
- return NULL;
- if (i == NULL)
- return NULL;
- int bps;
- switch (i->depth) {
- case IPL_DEPTH_8U:
- case IPL_DEPTH_8S:
- bps = 1;
- break;
- case IPL_DEPTH_16U:
- case IPL_DEPTH_16S:
- bps = 2;
- break;
- case IPL_DEPTH_32S:
- case IPL_DEPTH_32F:
- bps = 4;
- break;
- case IPL_DEPTH_64F:
- bps = 8;
- break;
- default:
- bps = 0;
- assert(0);
- }
- int bpl = i->width * i->nChannels * bps;
- int l = bpl * i->height;
- char *s = new char[l];
- int y;
- for (y = 0; y < i->height; y++) {
- memcpy(s + y * bpl, i->imageData + y * i->widthStep, bpl);
- }
- return PyString_FromStringAndSize(s, l);
+ // left window display, try rect, then raw
+ if (id->imRectColorType != COLOR_CODING_NONE)
+ return id->imRectColorSize;
+ else if (id->imRectType != COLOR_CODING_NONE)
+ return id->imRectSize;
+ else if (id->imColorType != COLOR_CODING_NONE)
+ return id->imColorSize;
+ else if (id->imType != COLOR_CODING_NONE)
+ return id->imSize;
+ else
+ return 0;
}
-static PyObject *dcam_getnChannels(dcam_t *cva)
-{
- return PyInt_FromLong(((IplImage*)(cva->a))->nChannels);
-}
-static PyObject *dcam_getwidth(dcam_t *cva)
-{
- return PyInt_FromLong(((IplImage*)(cva->a))->width);
-}
-static PyObject *dcam_getheight(dcam_t *cva)
-{
- return PyInt_FromLong(((IplImage*)(cva->a))->height);
-}
-static PyObject *dcam_getdepth(dcam_t *cva)
-{
- return PyInt_FromLong(((IplImage*)(cva->a))->depth);
-}
-static PyObject *dcam_getorigin(dcam_t *cva)
-{
- return PyInt_FromLong(((IplImage*)(cva->a))->origin);
-}
-static void dcam_setorigin(dcam_t *cva, PyObject *v)
-{
- ((IplImage*)(cva->a))->origin = PyInt_AsLong(v);
-}
-
-static PyGetSetDef dcam_getseters[] = {
- {(char*)"nChannels", (getter)dcam_getnChannels, (setter)NULL, (char*)"nChannels", NULL},
- {(char*)"width", (getter)dcam_getwidth, (setter)NULL, (char*)"width", NULL},
- {(char*)"height", (getter)dcam_getheight, (setter)NULL, (char*)"height", NULL},
- {(char*)"depth", (getter)dcam_getdepth, (setter)NULL, (char*)"depth", NULL},
- {(char*)"origin", (getter)dcam_getorigin, (setter)dcam_setorigin, (char*)"origin", NULL},
- {NULL} /* Sentinel */
-};
-
-static PyMappingMethods dcam_as_map = {
- NULL,
- &cvarr_GetItem,
- &cvarr_SetItem,
-};
-#endif
-
static PyObject *dcam_getImage(PyObject *self, PyObject *args)
{
dcam_t *ps = (dcam_t*)self;
@@ -151,14 +82,19 @@
int w = stIm->imWidth;
int h = stIm->imHeight;
- assert(stIm->imLeft->imRect != NULL);
- assert(stIm->imRight->imRect != NULL);
+ uint8_t *Ld = NULL, *Rd = NULL; // left data, right data
+ Ld = getdata(stIm->imLeft);
+ Rd = getdata(stIm->imRight);
+
+ assert(Ld != NULL);
+ assert(Rd != NULL);
+
return Py_BuildValue("iiNN",
w,
h,
- PyBuffer_FromMemory(stIm->imLeft->imRect, w * h),
- PyBuffer_FromMemory(stIm->imRight->imRect, w * h));
+ PyBuffer_FromMemory(Ld, getdatasize(stIm->imLeft)),
+ PyBuffer_FromMemory(Rd, getdatasize(stIm->imRight)));
}
#if 0
printf("%p\n", stIm->imLeft->imRaw);
@@ -207,7 +143,13 @@
static PyObject *make_dcam(PyObject *self, PyObject *args)
{
dcam_t *ps = PyObject_NEW(dcam_t, &dcam_Type);
+ char *str_pmode;
+ if (!PyArg_ParseTuple(args, "s", &str_pmode))
+ return NULL;
+
+ dcam::init();
+
// This code copied from ost.cpp - it is the initialization sequence
// for the camera.
//
@@ -215,7 +157,17 @@
ps->dev = new dcam::StereoDcam(dcam::getGuid(devIndex));
ps->dev->setRangeMax(4.0); // in meters
ps->dev->setRangeMin(0.5); // in meters
- static videre_proc_mode_t pmode = PROC_MODE_RECTIFIED;
+ videre_proc_mode_t pmode = PROC_MODE_RECTIFIED;
+ if (strcmp(str_pmode, "rectified") == 0)
+ pmode = PROC_MODE_RECTIFIED;
+ else if (strcmp(str_pmode, "none") == 0)
+ pmode = PROC_MODE_NONE;
+ else if (strcmp(str_pmode, "test") == 0)
+ pmode = PROC_MODE_TEST;
+ else {
+ PyErr_SetString(PyExc_TypeError, "mode must be none/test/rectified ");
+ return NULL;
+ }
dc1394video_mode_t videoMode; // current video mode
dc1394framerate_t videoRate; // current video rate
videoMode = VIDERE_STEREO_640x480;
@@ -238,8 +190,6 @@
extern "C" void initdcam()
{
- dcam::init();
-
dcam_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
dcam_specials();
if (PyType_Ready(&dcam_Type) < 0)
Modified: pkg/trunk/vision/vision_tests/manifest.xml
===================================================================
--- pkg/trunk/vision/vision_tests/manifest.xml 2009-07-17 23:37:00 UTC (rev 19150)
+++ pkg/trunk/vision/vision_tests/manifest.xml 2009-07-17 23:50:49 UTC (rev 19151)
@@ -11,7 +11,11 @@
<depend package="rospy"/>
<depend package="sensor_msgs"/>
<depend package="robot_msgs"/>
+ <depend package="robot_actions"/>
+ <depend package="python_actions"/>
+ <depend package="tf"/>
<depend package="opencvpython"/>
+ <depend package="dcam"/>
<url>http://pr.willowgarage.com/wiki/vision_tests</url>
Property changes on: pkg/trunk/vision/vision_tests/scripts
___________________________________________________________________
Added: svn:mergeinfo
+
Modified: pkg/trunk/vision/vision_tests/scripts/camera_hammer_1.py
===================================================================
--- pkg/trunk/vision/vision_tests/src/camera_hammer_1.py 2009-07-17 20:15:00 UTC (rev 19131)
+++ pkg/trunk/vision/vision_tests/scripts/camera_hammer_1.py 2009-07-17 23:50:49 UTC (rev 19151)
@@ -43,13 +43,46 @@
import cv
import dcam
-self.dc = dcam.dcam()
+def runTest(mode):
+ print mode
+ dc = dcam.dcam(mode)
+ paramstr = dc.retParameters()
-paramstr = self.dc.retParameters()
+ for i in range(50):
+ print i
+ w,h,l,r = dc.getImage()
+ cv_l = cv.CreateImageHeader((w, h), cv.IPL_DEPTH_8U, 1)
+ cv.SetData(cv_l, str(l), w)
+ cv_r = cv.CreateImageHeader((w, h), cv.IPL_DEPTH_8U, 1)
+ cv.SetData(cv_r, str(r), w)
+ return (cv_l, cv_r)
-w,h,l,r = self.dc.getImage()
-sz = (w, h)
-print sz
-#li = Im(sz, l)
-#ri = Im(sz, r)
+def compose(a, b):
+ w,h = cv.GetSize(a)
+ r = cv.CreateImage((w*2, h), cv.IPL_DEPTH_8U, 1)
+ cv.SetImageROI(r, (0, 0, w, h))
+ cv.Copy(a, r)
+ cv.SetImageROI(r, (w, 0, w, h))
+ cv.Copy(b, r)
+ cv.ResetImageROI(r)
+ return r
+i = int(sys.argv[1])
+m = sys.argv[2]
+l,r = runTest(m)
+comp = compose(l, r)
+cv.SaveImage("cam-%s-%06d.png" % (m, i), compose(l, r))
+
+## Collect goldens
+#modes = ('none', 'test')
+#goldens = {}
+#for m in modes:
+# goldens[m] = runTest(m)
+#
+#modes = ('test',)
+#for i in range(10):
+# for m in modes:
+# gl,gr = goldens[m]
+# l,r = runTest(m)
+# comp = compose(l, r)
+# cv.SaveImage("cam-%s-%06d.png" % (m, i), compose(l, r))
Added: pkg/trunk/vision/vision_tests/scripts/loop.py
===================================================================
--- pkg/trunk/vision/vision_tests/scripts/loop.py (rev 0)
+++ pkg/trunk/vision/vision_tests/scripts/loop.py 2009-07-17 23:50:49 UTC (rev 19151)
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+# Software License Agreement (BSD License)
+#
+# Copyright (c) 2009, Willow Garage, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following
+# disclaimer in the documentation and/or other materials provided
+# with the distribution.
+# * Neither the name of the Willow Garage nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+import os
+
+modes = ('none', 'test')
+for i in range(10):
+ for m in modes:
+ os.system("scripts/camera_hammer_1.py %d %s" % (i, m))
Property changes on: pkg/trunk/vision/vision_tests/scripts/loop.py
___________________________________________________________________
Added: svn:executable
+ *
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|