|
From: <mor...@us...> - 2008-03-26 23:42:38
|
Revision: 36
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=36&view=rev
Author: morgan_quigley
Date: 2008-03-26 16:42:44 -0700 (Wed, 26 Mar 2008)
Log Message:
-----------
using jeremy's hot libcurl code instead of wget for axis_cam
Modified Paths:
--------------
pkg/trunk/axis_cam/src/libaxis_cam/axis_cam.cpp
Added Paths:
-----------
pkg/trunk/axis_cam/src/axis_cam/
Removed Paths:
-------------
pkg/trunk/axis_cam/src/axis_cam_wget/
Copied: pkg/trunk/axis_cam/src/axis_cam (from rev 33, pkg/trunk/axis_cam/src/axis_cam_wget)
Modified: pkg/trunk/axis_cam/src/libaxis_cam/axis_cam.cpp
===================================================================
--- pkg/trunk/axis_cam/src/libaxis_cam/axis_cam.cpp 2008-03-26 22:48:08 UTC (rev 35)
+++ pkg/trunk/axis_cam/src/libaxis_cam/axis_cam.cpp 2008-03-26 23:42:44 UTC (rev 36)
@@ -2,7 +2,8 @@
// The axis_cam package provides a library that talks to Axis IP-based cameras
// as well as ROS nodes which use these libraries
//
-// Copyright (C) 2008, Morgan Quigley
+// Copyright (C) 2008, Morgan Quigley, Stanford Univerity
+// Jeremy Leibs, Willow Garage
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
@@ -11,9 +12,9 @@
// * 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.
+// * Neither the name of Stanford University, 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
@@ -28,13 +29,28 @@
// POSSIBILITY OF SUCH DAMAGE.
#include <sstream>
-#include <sys/stat.h>
#include "axis_cam/axis_cam.h"
AxisCam::AxisCam(string ip) : ip(ip)
{
jpeg_buf = NULL;
jpeg_buf_size = 0;
+ curl_global_init(0);
+ ostringstream oss;
+ oss << "http://" << ip << "/axis-cgi/com/ptz.cgi";
+ setptz_curl = curl_easy_init();
+ curl_easy_setopt(setptz_curl, CURLOPT_URL, oss.str().c_str());
+ curl_easy_setopt(setptz_curl, CURLOPT_WRITEFUNCTION, AxisCam::setptz_write);
+ curl_easy_setopt(setptz_curl, CURLOPT_WRITEDATA, this);
+
+ oss.str(""); // clear it
+ oss << "http://" << ip << "/jpg/image.jpg";
+ jpeg_curl = curl_easy_init();
+ curl_easy_setopt(jpeg_curl, CURLOPT_URL, oss.str().c_str());
+ curl_easy_setopt(jpeg_curl, CURLOPT_WRITEFUNCTION, AxisCam::jpeg_write);
+ curl_easy_setopt(jpeg_curl, CURLOPT_WRITEDATA, this);
+
+ printf("Getting images from [%s]", oss.str().c_str());
}
AxisCam::~AxisCam()
@@ -42,39 +58,45 @@
if (jpeg_buf)
delete[] jpeg_buf;
jpeg_buf = NULL;
+ curl_global_cleanup();
}
-bool AxisCam::wget_jpeg(uint8_t ** const fetch_jpeg_buf, uint32_t *fetch_buf_size, string filename)
+bool AxisCam::get_jpeg(uint8_t ** const fetch_jpeg_buf, uint32_t *fetch_buf_size)
{
if (fetch_jpeg_buf && fetch_buf_size)
{
*fetch_jpeg_buf = NULL;
*fetch_buf_size = 0;
}
- if (filename == string())
- filename = "axiscam-temp.jpg";
- ostringstream oss;
- oss << string("wget -q -O") << filename << string(" \"") << ip << string("/jpg/image.jpg\"");
- //printf("about to execute: [%s]\n", oss.str().c_str());
- int retval = system(oss.str().c_str());
- if (retval > 0)
+ else
+ return false; // don't make me crash
+ jpeg_file_size = 0;
+ if (curl_easy_perform(jpeg_curl))
+ return false;
+ *fetch_jpeg_buf = jpeg_buf;
+ *fetch_buf_size = jpeg_file_size;
+ return true;
+}
+
+size_t AxisCam::jpeg_write(void *buf, size_t size, size_t nmemb, void *userp)
+{
+ if (size * nmemb == 0)
+ return 0;
+ AxisCam *a = (AxisCam *)userp;
+ if (a->jpeg_file_size + size*nmemb >= a->jpeg_buf_size)
{
- printf("ahhh nonzero return value from wget: %d\n", retval);
- return false;
+ // overalloc
+ a->jpeg_buf_size = 2 * (a->jpeg_file_size + (size*nmemb));
+ if (a->jpeg_buf)
+ delete[] a->jpeg_buf;
+ a->jpeg_buf = new uint8_t[a->jpeg_buf_size];
}
- else if (retval < 0)
- printf("wget system retval = %d\n", retval);
+ memcpy(a->jpeg_buf + a->jpeg_file_size, buf, size*nmemb);
+ a->jpeg_file_size += size*nmemb;
+ return size*nmemb;
+}
- FILE *jpeg_file = fopen(filename.c_str(),"rb");
- if (!jpeg_file)
- {
- printf("couldn't read back the jpeg file from disk\n");
- return false;
- }
-
- struct stat s;
- stat(filename.c_str(), &s);
- uint32_t jpeg_file_size = (uint32_t) s.st_size;
+ /*
if (jpeg_file_size > jpeg_buf_size)
{
if (jpeg_buf)
@@ -89,16 +111,10 @@
return false;
}
fclose(jpeg_file);
-
*fetch_jpeg_buf = jpeg_buf;
*fetch_buf_size = jpeg_file_size;
+ */
- if (jpeg_file_size < 500) // sanity check
- return false;
-
- return true;
-}
-
bool AxisCam::ptz(double pan, double tilt, double zoom)
{
pan = clamp(pan, -175, 175);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mor...@us...> - 2008-03-27 00:34:56
|
Revision: 42
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=42&view=rev
Author: morgan_quigley
Date: 2008-03-26 17:35:00 -0700 (Wed, 26 Mar 2008)
Log Message:
-----------
bye bye wget in axis_cam
Added Paths:
-----------
pkg/trunk/axis_cam/src/axis_cam_polled/
pkg/trunk/axis_cam/src/axis_cam_polled/Makefile
pkg/trunk/axis_cam/src/axis_cam_polled/axis_cam_polled.cpp
Removed Paths:
-------------
pkg/trunk/axis_cam/src/axis_cam_polled/Makefile
pkg/trunk/axis_cam/src/axis_cam_polled/axis_cam_wget_polled.cpp
pkg/trunk/axis_cam/src/axis_cam_wget_polled/
Copied: pkg/trunk/axis_cam/src/axis_cam_polled (from rev 38, pkg/trunk/axis_cam/src/axis_cam_wget_polled)
Deleted: pkg/trunk/axis_cam/src/axis_cam_polled/Makefile
===================================================================
--- pkg/trunk/axis_cam/src/axis_cam_wget_polled/Makefile 2008-03-27 00:27:14 UTC (rev 38)
+++ pkg/trunk/axis_cam/src/axis_cam_polled/Makefile 2008-03-27 00:35:00 UTC (rev 42)
@@ -1,4 +0,0 @@
-SRC = axis_cam_wget_polled.cpp
-OUT = ../../nodes/axis_cam_wget_polled
-PKG = axis_cam
-include $(shell $(ROS_ROOT)/rospack find roscpp)/make_include/node.mk
Copied: pkg/trunk/axis_cam/src/axis_cam_polled/Makefile (from rev 41, pkg/trunk/axis_cam/src/axis_cam_wget_polled/Makefile)
===================================================================
--- pkg/trunk/axis_cam/src/axis_cam_polled/Makefile (rev 0)
+++ pkg/trunk/axis_cam/src/axis_cam_polled/Makefile 2008-03-27 00:35:00 UTC (rev 42)
@@ -0,0 +1,4 @@
+SRC = axis_cam_polled.cpp
+OUT = ../../nodes/axis_cam_polled
+PKG = axis_cam
+include $(shell $(ROS_ROOT)/rospack find roscpp)/make_include/node.mk
Copied: pkg/trunk/axis_cam/src/axis_cam_polled/axis_cam_polled.cpp (from rev 41, pkg/trunk/axis_cam/src/axis_cam_wget_polled/axis_cam_polled.cpp)
===================================================================
--- pkg/trunk/axis_cam/src/axis_cam_polled/axis_cam_polled.cpp (rev 0)
+++ pkg/trunk/axis_cam/src/axis_cam_polled/axis_cam_polled.cpp 2008-03-27 00:35:00 UTC (rev 42)
@@ -0,0 +1,92 @@
+///////////////////////////////////////////////////////////////////////////////
+// The axis_cam package provides a library that talks to Axis IP-based cameras
+// as well as ROS nodes which use these libraries
+//
+// 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 "SDL/SDL.h"
+#include "image_flows/FlowImage.h"
+#include "common_flows/FlowEmpty.h"
+#include "axis_cam/axis_cam.h"
+
+class AxisCamPolled : public ROS_Slave
+{
+public:
+ FlowImage *image;
+ FlowEmpty *shutter;
+ string axis_host;
+ AxisCam *cam;
+ int frame_id;
+
+ AxisCamPolled() : ROS_Slave(), cam(NULL), frame_id(0)
+ {
+ register_source(image = new FlowImage("image"));
+ register_sink(shutter = new FlowEmpty("shutter"),
+ ROS_CALLBACK(AxisCamPolled, shutter_cb));
+ if (!get_string_param(".host", axis_host))
+ {
+ printf("axis_host parameter not specified; defaulting to 192.168.0.90\n");
+ axis_host = "192.168.0.90";
+ }
+ printf("axis host set to [%s]\n", axis_host.c_str());
+ get_int_param(".frame_id", &frame_id);
+ cam = new AxisCam(axis_host);
+ }
+ virtual ~AxisCamPolled()
+ {
+ if (cam)
+ delete cam;
+ }
+ bool take_and_send_image()
+ {
+ uint8_t *jpeg;
+ uint32_t jpeg_size;
+ if (!cam->get_jpeg(&jpeg, &jpeg_size))
+ return false;
+ image->set_data_size(jpeg_size);
+ memcpy(image->data, jpeg, jpeg_size);
+ image->width = 704;
+ image->height = 480;
+ image->compression = "jpeg";
+ image->colorspace = "rgb24";
+ image->frame_id = frame_id;
+ image->publish();
+ return true;
+ }
+ void shutter_cb()
+ {
+ take_and_send_image();
+ }
+};
+
+int main(int argc, char **argv)
+{
+ AxisCamPolled a;
+ a.spin();
+ return 0;
+}
+
Deleted: pkg/trunk/axis_cam/src/axis_cam_polled/axis_cam_wget_polled.cpp
===================================================================
--- pkg/trunk/axis_cam/src/axis_cam_wget_polled/axis_cam_wget_polled.cpp 2008-03-27 00:27:14 UTC (rev 38)
+++ pkg/trunk/axis_cam/src/axis_cam_polled/axis_cam_wget_polled.cpp 2008-03-27 00:35:00 UTC (rev 42)
@@ -1,91 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////
-// The axis_cam package provides a library that talks to Axis IP-based cameras
-// as well as ROS nodes which use these libraries
-//
-// 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 "SDL/SDL.h"
-#include "image_flows/FlowImage.h"
-#include "common_flows/FlowEmpty.h"
-#include "axis_cam/axis_cam.h"
-
-class AxisCamWgetPolled : public ROS_Slave
-{
-public:
- FlowImage *image;
- FlowEmpty *shutter;
- string axis_host;
- AxisCam *cam;
- int frame_id;
-
- AxisCamWgetPolled() : ROS_Slave(), cam(NULL), frame_id(0)
- {
- register_source(image = new FlowImage("image"));
- register_sink(shutter = new FlowEmpty("shutter"), ROS_CALLBACK(AxisCamWgetPolled, shutter_callback));
- if (!get_string_param(".host", axis_host))
- {
- printf("axis_host parameter not specified; defaulting to 192.168.0.90\n");
- axis_host = "192.168.0.90";
- }
- printf("axis host set to [%s]\n", axis_host.c_str());
- get_int_param(".frame_id", &frame_id);
- cam = new AxisCam(axis_host);
- }
- virtual ~AxisCamWgetPolled()
- {
- if (cam)
- delete cam;
- }
- bool take_and_send_image()
- {
- uint8_t *jpeg;
- uint32_t jpeg_size;
- if (!cam->wget_jpeg(&jpeg, &jpeg_size))
- return false;
- image->set_data_size(jpeg_size);
- memcpy(image->data, jpeg, jpeg_size);
- image->width = 704;
- image->height = 480;
- image->compression = "jpeg";
- image->colorspace = "rgb24";
- image->frame_id = frame_id;
- image->publish();
- return true;
- }
- void shutter_callback()
- {
- take_and_send_image();
- }
-};
-
-int main(int argc, char **argv)
-{
- AxisCamWgetPolled a;
- a.spin();
- return 0;
-}
-
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|