|
From: <mor...@us...> - 2008-03-28 18:22:30
|
Revision: 59
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=59&view=rev
Author: morgan_quigley
Date: 2008-03-28 11:22:34 -0700 (Fri, 28 Mar 2008)
Log Message:
-----------
the cv_cam package uses opencv to grab whatever camera it can find. it won't work until i get the image flows running, however, which requires flowgen_cpp to be modernized... TIME2CODE
Modified Paths:
--------------
pkg/trunk/image_viewer/manifest.xml
pkg/trunk/image_viewer/src/image_viewer/image_viewer.cpp
Added Paths:
-----------
pkg/trunk/cv_cam/
pkg/trunk/cv_cam/build.yaml
pkg/trunk/cv_cam/manifest.xml
pkg/trunk/cv_cam/nodes/
pkg/trunk/cv_cam/nodes/test_cv_cam
pkg/trunk/cv_cam/rosbuild
pkg/trunk/cv_cam/src/
pkg/trunk/cv_cam/src/cv_cam/
pkg/trunk/cv_cam/src/cv_cam/Makefile
pkg/trunk/cv_cam/src/cv_cam/cv_cam.cpp
Added: pkg/trunk/cv_cam/build.yaml
===================================================================
--- pkg/trunk/cv_cam/build.yaml (rev 0)
+++ pkg/trunk/cv_cam/build.yaml 2008-03-28 18:22:34 UTC (rev 59)
@@ -0,0 +1,3 @@
+cpp:
+ make:
+ - src/cv_cam
Added: pkg/trunk/cv_cam/manifest.xml
===================================================================
--- pkg/trunk/cv_cam/manifest.xml (rev 0)
+++ pkg/trunk/cv_cam/manifest.xml 2008-03-28 18:22:34 UTC (rev 59)
@@ -0,0 +1,13 @@
+<package>
+<description brief="Simple OpenCV-based camera grabber">
+
+This is a simple program which grabs frames from a V4L device using OpenCV and publishes them.
+
+</description>
+<author>Morgan Quigley (email: mqu...@cs...)</author>
+<license>BSD</license>
+<url>http://stair.stanford.edu</url>
+<depend package="common_flows"/>
+<depend package="opencv"/>
+</package>
+
Added: pkg/trunk/cv_cam/nodes/test_cv_cam
===================================================================
--- pkg/trunk/cv_cam/nodes/test_cv_cam (rev 0)
+++ pkg/trunk/cv_cam/nodes/test_cv_cam 2008-03-28 18:22:34 UTC (rev 59)
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+require "#{`#{ENV['ROS_ROOT']}/rospack latest yamlgraph`}/lib/yamlgraph/ygl.rb"
+g = YAMLGraph.new
+g.param 'cv_cam.show_image',0
+g.node 'cv_cam/cv_cam', {'launch' => 'xterm'}
+g.node 'image_viewer/image_viewer', {'launch' => 'xterm'}
+g.flow 'cv_cam:image','image_viewer:image'
+YAMLGraphLauncher.new.launch g
+
Property changes on: pkg/trunk/cv_cam/nodes/test_cv_cam
___________________________________________________________________
Name: svn:executable
+ *
Added: pkg/trunk/cv_cam/rosbuild
===================================================================
--- pkg/trunk/cv_cam/rosbuild (rev 0)
+++ pkg/trunk/cv_cam/rosbuild 2008-03-28 18:22:34 UTC (rev 59)
@@ -0,0 +1,2 @@
+#!/usr/bin/env ruby
+exec("#{`#{ENV['ROS_ROOT']}/rospack find rostools`}/scripts/yamlbuild", 'build.yaml', *ARGV)
Property changes on: pkg/trunk/cv_cam/rosbuild
___________________________________________________________________
Name: svn:executable
+ *
Added: pkg/trunk/cv_cam/src/cv_cam/Makefile
===================================================================
--- pkg/trunk/cv_cam/src/cv_cam/Makefile (rev 0)
+++ pkg/trunk/cv_cam/src/cv_cam/Makefile 2008-03-28 18:22:34 UTC (rev 59)
@@ -0,0 +1,5 @@
+SRC = cv_cam.cpp
+OUT = ../../nodes/cv_cam
+PKG = cv_cam
+LFLAGS = -lhighgui
+include $(shell $(ROS_ROOT)/rospack find roscpp)/make_include/node.mk
Added: pkg/trunk/cv_cam/src/cv_cam/cv_cam.cpp
===================================================================
--- pkg/trunk/cv_cam/src/cv_cam/cv_cam.cpp (rev 0)
+++ pkg/trunk/cv_cam/src/cv_cam/cv_cam.cpp 2008-03-28 18:22:34 UTC (rev 59)
@@ -0,0 +1,96 @@
+///////////////////////////////////////////////////////////////////////////////
+// The cv_cam package provides a simple node which grabs images from a camera
+// using OpenCV and publishes them.
+//
+// Copyright (C) 2008, Morgan Quigley
+//
+// 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 Stanford University 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.
+
+#include "ros/ros_slave.h"
+#include "common_flows/FlowImage.h"
+#include "common_flows/ImageCvBridge.h"
+#include "opencv/highgui.h"
+
+class CVCam : public ROS_Slave
+{
+public:
+ FlowImage *image_f;
+ ImageCvBridge<FlowImage> *cv_bridge;
+ CvCapture *capture;
+ IplImage *cam_image;
+ double last_image_time;
+ int show_image;
+
+ CVCam() : ROS_Slave(), last_image_time(0), show_image(0)
+ {
+ register_source(image_f = new FlowImage("image"));
+ image_f->frame_id = 0; // frame is zero unless specified
+ get_int_param(".frame_id", &image_f->frame_id);
+ get_int_param(".show_image", &show_image);
+ cv_bridge = new ImageCvBridge<FlowImage>(image_f);
+ capture = cvCaptureFromCAM(CV_CAP_ANY);
+ if (!capture)
+ log(ROS::ERROR,"woah! couldn't open a camera. is one connected?\n");
+ }
+ virtual ~CVCam()
+ {
+ if (capture)
+ cvReleaseCapture(&capture);
+ }
+ bool take_and_send_picture()
+ {
+ if (!capture)
+ return false;
+ cam_image = cvQueryFrame(capture);
+ double t = runtime();
+ double dt = t - last_image_time;
+ printf("dt = %f\t(%f fps)\n", dt, 1.0 / dt);
+ last_image_time = t;
+ if (show_image)
+ cvShowImage("CV Cam", cam_image);
+ image_f->compression = "raw";
+ cv_bridge->from_cv(cam_image);
+ cv_bridge->set_flow_data();
+ image_f->publish();
+ return true;
+ }
+};
+
+int main(int argc, char **argv)
+{
+ CVCam a;
+ if (a.show_image)
+ cvNamedWindow("CV Cam", CV_WINDOW_AUTOSIZE);
+ while (a.happy())
+ {
+ if (a.show_image)
+ cvWaitKey(5);
+ if (!a.take_and_send_picture())
+ usleep(100000);
+ }
+ if (a.show_image)
+ cvDestroyWindow("CV Cam");
+ return 0;
+}
+
Modified: pkg/trunk/image_viewer/manifest.xml
===================================================================
--- pkg/trunk/image_viewer/manifest.xml 2008-03-28 18:08:35 UTC (rev 58)
+++ pkg/trunk/image_viewer/manifest.xml 2008-03-28 18:22:34 UTC (rev 59)
@@ -6,7 +6,7 @@
<license>BSD</license>
<url>http://stair.stanford.edu</url>
<depend package="roscpp"/>
-<depend package="image_flows"/>
+<depend package="common_flows"/>
<depend package="sdl"/>
</package>
Modified: pkg/trunk/image_viewer/src/image_viewer/image_viewer.cpp
===================================================================
--- pkg/trunk/image_viewer/src/image_viewer/image_viewer.cpp 2008-03-28 18:08:35 UTC (rev 58)
+++ pkg/trunk/image_viewer/src/image_viewer/image_viewer.cpp 2008-03-28 18:22:34 UTC (rev 59)
@@ -40,7 +40,8 @@
ImageViewer() : ROS_Slave(), blit_prep(NULL)
{
- register_sink(image = new FlowImage("image"), ROS_CALLBACK(ImageViewer, image_received));
+ register_sink(image = new FlowImage("image"),
+ ROS_CALLBACK(ImageViewer, image_cb));
codec = new ImageFlowCodec<FlowImage>(image);
register_with_master();
}
@@ -50,12 +51,13 @@
screen = SDL_SetVideoMode(320, 240, 24, 0);
return (screen ? true : false);
}
- void image_received()
+ void image_cb()
{
if (!screen)
return; // paranoia. shouldn't happen. we should have bailed by now.
if (screen->h != image->height || screen->w != image->width)
{
+ printf("resizing for a %d by %d image\n", image->width, image->height);
screen = SDL_SetVideoMode(image->width, image->height, 24, 0);
if (!screen)
{
@@ -64,7 +66,9 @@
exit(1);
}
}
- if (!blit_prep || blit_prep->w != image->width || blit_prep->h != image->width)
+ if (!blit_prep ||
+ blit_prep->w != image->width ||
+ blit_prep->h != image->width)
{
if (blit_prep)
SDL_FreeSurface(blit_prep);
@@ -120,9 +124,7 @@
exit(1);
}
while (v.happy())
- {
usleep(1000000);
- }
return 0;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|