|
From: <jl...@us...> - 2008-04-16 01:35:16
|
Revision: 104
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=104&view=rev
Author: jleibs
Date: 2008-04-15 18:35:21 -0700 (Tue, 15 Apr 2008)
Log Message:
-----------
Check in library for reading from elphel camera.
Added Paths:
-----------
pkg/trunk/elphel_cam/
pkg/trunk/elphel_cam/build.yaml
pkg/trunk/elphel_cam/include/
pkg/trunk/elphel_cam/include/elphel_cam/
pkg/trunk/elphel_cam/include/elphel_cam/elphel_cam.h
pkg/trunk/elphel_cam/lib/
pkg/trunk/elphel_cam/manifest.xml
pkg/trunk/elphel_cam/nodes/
pkg/trunk/elphel_cam/rosbuild
pkg/trunk/elphel_cam/src/
pkg/trunk/elphel_cam/src/libelphel_cam/
pkg/trunk/elphel_cam/src/libelphel_cam/Makefile
pkg/trunk/elphel_cam/src/libelphel_cam/elphel_cam.cpp
pkg/trunk/elphel_cam/test/
pkg/trunk/elphel_cam/test/test_cam/
pkg/trunk/elphel_cam/test/test_cam/Makefile
pkg/trunk/elphel_cam/test/test_cam/test_cam.cpp
Added: pkg/trunk/elphel_cam/build.yaml
===================================================================
--- pkg/trunk/elphel_cam/build.yaml (rev 0)
+++ pkg/trunk/elphel_cam/build.yaml 2008-04-16 01:35:21 UTC (rev 104)
@@ -0,0 +1,4 @@
+cpp:
+ make:
+ - src/libelphel_cam
+ - test/test_cam
Added: pkg/trunk/elphel_cam/include/elphel_cam/elphel_cam.h
===================================================================
--- pkg/trunk/elphel_cam/include/elphel_cam/elphel_cam.h (rev 0)
+++ pkg/trunk/elphel_cam/include/elphel_cam/elphel_cam.h 2008-04-16 01:35:21 UTC (rev 104)
@@ -0,0 +1,78 @@
+///////////////////////////////////////////////////////////////////////////////
+// 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, 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:
+// * 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, 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.
+
+#ifndef ELPHEL_CAM_ELPHEL_CAM_H
+#define ELPHEL_CAM_ELPHEL_CAM_H
+
+#include <curl/curl.h>
+#include <string>
+#include <sstream>
+#include "thread_utils/mutex.h"
+
+using namespace std;
+
+class Elphel_Cam
+{
+public:
+ Elphel_Cam(string ip);
+ ~Elphel_Cam();
+
+ bool next_jpeg(uint8_t ** const fetch_jpeg_buf, uint32_t *fetch_buf_size);
+
+ bool config_cmd(string url, string cmd);
+
+ bool compressor_cmd(string cmd);
+ bool ccam_cmd(string cmd);
+ bool towp();
+
+ bool start();
+ bool stop();
+
+ bool init(float = 10, int = 4, int = 4);
+
+private:
+ string ip;
+ uint8_t *jpeg_buf, ;
+ uint32_t jpeg_buf_size, jpeg_file_size;
+
+ CURL *jpeg_curl, *config_curl;
+
+ char *image_url, *towp_url, *ccam_url, *comp_url;
+
+ stringstream config_ss;
+ ThreadUtils::Mutex config_ss_mutex;
+
+ static size_t jpeg_write(void *buf, size_t size, size_t nmemb, void *userp);
+ static size_t config_write(void *buf, size_t size, size_t nmemb, void *userp);
+
+};
+
+#endif
+
Added: pkg/trunk/elphel_cam/manifest.xml
===================================================================
--- pkg/trunk/elphel_cam/manifest.xml (rev 0)
+++ pkg/trunk/elphel_cam/manifest.xml 2008-04-16 01:35:21 UTC (rev 104)
@@ -0,0 +1,13 @@
+<package>
+<description brief="Controlling and acquiring data from the Elphel IP-based cameras">
+A package to configure and grab images from the Elphel IP-based camera.
+
+</description>
+<author>Jeremy Leibs (email: le...@wi...)</author>
+<license>BSD</license>
+<url>http://pr.willowgarage.com</url>
+<depend package="common_flows"/>
+<depend package="thread_utils"/>
+<depend package="image_viewer"/>
+</package>
+
Added: pkg/trunk/elphel_cam/rosbuild
===================================================================
--- pkg/trunk/elphel_cam/rosbuild (rev 0)
+++ pkg/trunk/elphel_cam/rosbuild 2008-04-16 01:35:21 UTC (rev 104)
@@ -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/elphel_cam/rosbuild
___________________________________________________________________
Name: svn:executable
+ *
Added: pkg/trunk/elphel_cam/src/libelphel_cam/Makefile
===================================================================
--- pkg/trunk/elphel_cam/src/libelphel_cam/Makefile (rev 0)
+++ pkg/trunk/elphel_cam/src/libelphel_cam/Makefile 2008-04-16 01:35:21 UTC (rev 104)
@@ -0,0 +1,4 @@
+SRC = elphel_cam.cpp
+OUT = ../../lib/libelphel_cam.a
+PKG = elphel_cam
+include $(shell $(ROS_ROOT)/rospack find roscpp)/make_include/lib.mk
Added: pkg/trunk/elphel_cam/src/libelphel_cam/elphel_cam.cpp
===================================================================
--- pkg/trunk/elphel_cam/src/libelphel_cam/elphel_cam.cpp (rev 0)
+++ pkg/trunk/elphel_cam/src/libelphel_cam/elphel_cam.cpp 2008-04-16 01:35:21 UTC (rev 104)
@@ -0,0 +1,247 @@
+///////////////////////////////////////////////////////////////////////////////
+// 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, 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:
+// * 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, 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.
+
+#include <sstream>
+#include <iostream>
+#include "elphel_cam/elphel_cam.h"
+
+Elphel_Cam::Elphel_Cam(string ip) : ip(ip)
+{
+ jpeg_buf = NULL;
+ jpeg_buf_size = 0;
+ curl_global_init(0);
+
+ ostringstream oss;
+ oss << "http://" << ip << ":8081/torp/wait/img/next/save";
+ image_url = new char[oss.str().length()+1];
+ strcpy(image_url, oss.str().c_str());
+
+
+ oss.str("");
+ oss << "http://" << ip << ":8081/towp/save";
+ towp_url = new char[oss.str().length()+1];
+ strcpy(towp_url, oss.str().c_str());
+
+ oss.str("");
+ oss << "http://" << ip << "/admin-bin/ccam.cgi?";
+ ccam_url = new char[oss.str().length()+1];
+ strcpy(ccam_url, oss.str().c_str());
+
+ oss.str("");
+ oss << "http://" << ip << ":81/compressor.php?";
+ comp_url = new char[oss.str().length()+1];
+ strcpy(comp_url, oss.str().c_str());
+
+ jpeg_curl = curl_easy_init();
+ curl_easy_setopt(jpeg_curl, CURLOPT_URL, image_url);
+ curl_easy_setopt(jpeg_curl, CURLOPT_WRITEFUNCTION, Elphel_Cam::jpeg_write);
+ curl_easy_setopt(jpeg_curl, CURLOPT_WRITEDATA, this);
+
+ config_curl = curl_easy_init();
+ // curl_easy_setopt(config_curl, CURLOPT_URL, config_url);
+ curl_easy_setopt(config_curl, CURLOPT_WRITEFUNCTION, Elphel_Cam::config_write);
+ curl_easy_setopt(config_curl, CURLOPT_WRITEDATA, this);
+
+
+}
+
+Elphel_Cam::~Elphel_Cam()
+{
+ delete[] image_url;
+ delete[] towp_url;
+ delete[] ccam_url;
+ delete[] comp_url;
+ if (jpeg_buf)
+ delete[] jpeg_buf;
+ jpeg_buf = NULL;
+ curl_global_cleanup();
+}
+
+bool Elphel_Cam::next_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;
+ }
+ else
+ {
+ printf("woah! bad input parameters\n");
+ return false; // don't make me crash
+ }
+ CURLcode code;
+ do
+ {
+ jpeg_file_size = 0;
+ if (code = curl_easy_perform(jpeg_curl))
+ {
+ printf("woah! curl error: [%s]\n", curl_easy_strerror(code));
+ return false;
+ }
+ if (jpeg_buf[0] == 0 && jpeg_buf[1] == 0)
+ printf("[Elphel_Cam] ODD...first two bytes are zero...\n");
+ } while (jpeg_buf[0] == 0 && jpeg_buf[1] == 0);
+ *fetch_jpeg_buf = jpeg_buf;
+ *fetch_buf_size = jpeg_file_size;
+ return true;
+}
+
+
+bool Elphel_Cam::config_cmd(string url, string cmd)
+{
+ config_ss_mutex.lock();
+ config_ss.clear(); // reset stringstream state so we can insert into it again
+ config_ss.str("");
+ config_ss_mutex.unlock();
+
+ ostringstream oss;
+ oss << url << cmd;
+
+ char urlbuf[512];
+ strcpy(urlbuf, oss.str().c_str());
+
+ // printf("Executing command: %s\n", urlbuf);
+
+ curl_easy_setopt(config_curl, CURLOPT_URL, urlbuf);
+
+ CURLcode code;
+ if (code = curl_easy_perform(config_curl))
+ {
+ printf("woah! curl error: [%s]\n", curl_easy_strerror(code));
+ return false;
+ }
+ return true;
+}
+
+
+bool Elphel_Cam::compressor_cmd(string cmd) {
+ return config_cmd(comp_url, cmd);
+}
+
+bool Elphel_Cam::ccam_cmd(string cmd) {
+ return config_cmd(ccam_url, cmd);
+}
+
+bool Elphel_Cam::towp() {
+ return config_cmd(towp_url, string(""));
+}
+
+bool Elphel_Cam::init(float fps, int im_dec, int im_bin) {
+
+ uint8_t *jpeg;
+ uint32_t jpeg_size;
+
+ for (int i = 0; i < 2; i++) { //loop twice
+
+ if (!compressor_cmd("cmd=reset"))
+ return false;
+
+ //magic incantation:
+ //http://wiki.elphel.com/index.php?title=Ccam.cgi
+ ostringstream oss;
+ oss << "opt=vhcxyu+!-"
+ << "&dh=" << im_dec << "&dv=" << im_dec
+ << "&bh=" << im_bin << "&bh=" << im_bin
+ << "&iq=90"
+ << "&fps=" << fps << "&fpslm=3"
+ << "&kgm=6&sens=2&bit=8&gam=50&pxl=10&csb=200&csr=200&rscale=auto&bscale=auto";
+
+ if (!ccam_cmd(oss.str()))
+ return false;
+
+ if (!compressor_cmd("cmd=run"))
+ return false;
+
+ if (!towp())
+ return false;
+
+ for (int j = 0; j < 10;j++) {
+ if (!next_jpeg(&jpeg, &jpeg_size))
+ return false;
+ }
+
+ if (!compressor_cmd("cmd=stop"))
+ return false;
+ }
+
+ return true;
+
+}
+
+
+bool Elphel_Cam::start() {
+ if (!compressor_cmd("cmd=run"))
+ return false;
+
+ if (!towp())
+ return false;
+
+ return true;
+
+}
+
+bool Elphel_Cam::stop() {
+ return compressor_cmd("cmd=stop");
+}
+
+
+size_t Elphel_Cam::jpeg_write(void *buf, size_t size, size_t nmemb, void *userp)
+{
+ if (size * nmemb == 0)
+ return 0;
+ Elphel_Cam *a = (Elphel_Cam *)userp;
+ if (a->jpeg_file_size + size*nmemb >= a->jpeg_buf_size)
+ {
+ // overalloc
+ a->jpeg_buf_size = 2 * (a->jpeg_file_size + (size*nmemb));
+ //printf("jpeg_buf_size is now %d\n", a->jpeg_buf_size);
+ if (a->jpeg_buf)
+ delete[] a->jpeg_buf;
+ a->jpeg_buf = new uint8_t[a->jpeg_buf_size];
+ }
+ memcpy(a->jpeg_buf + a->jpeg_file_size, buf, size*nmemb);
+ a->jpeg_file_size += size*nmemb;
+ return size*nmemb;
+}
+
+
+size_t Elphel_Cam::config_write(void *buf, size_t size, size_t nmemb, void *userp)
+{
+ if (size * nmemb == 0)
+ return 0;
+ Elphel_Cam *a = (Elphel_Cam *)userp;
+ a->config_ss_mutex.lock();
+ a->config_ss << string((char *)buf, size*nmemb);
+ //printf("writing %d bytes\n", size*nmemb);
+ //cout << a->ptz_ss.str() << endl;
+ a->config_ss_mutex.unlock();
+ //cout << string((char *)buf, size*nmemb);
+ return size*nmemb;
+}
Added: pkg/trunk/elphel_cam/test/test_cam/Makefile
===================================================================
--- pkg/trunk/elphel_cam/test/test_cam/Makefile (rev 0)
+++ pkg/trunk/elphel_cam/test/test_cam/Makefile 2008-04-16 01:35:21 UTC (rev 104)
@@ -0,0 +1,4 @@
+SRC = test_cam.cpp
+OUT = test_cam
+PKG = elphel_cam
+include $(shell $(ROS_ROOT)/rospack find roscpp)/make_include/node.mk
Added: pkg/trunk/elphel_cam/test/test_cam/test_cam.cpp
===================================================================
--- pkg/trunk/elphel_cam/test/test_cam/test_cam.cpp (rev 0)
+++ pkg/trunk/elphel_cam/test/test_cam/test_cam.cpp 2008-04-16 01:35:21 UTC (rev 104)
@@ -0,0 +1,64 @@
+/*********************************************************************
+* Software License Agreement (BSD License)
+*
+* Copyright (c) 2008, 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.
+*********************************************************************/
+
+#include <iostream>
+#include <fstream>
+#include "elphel_cam/elphel_cam.h"
+
+using namespace std;
+
+int main() {
+
+ Elphel_Cam e("192.168.0.9");
+
+ uint8_t* jpeg;
+ uint32_t jpeg_size;
+
+ e.init(80, 4, 4);
+
+ e.start();
+
+ for (int i = 0; i < 200;i++) {
+ ostringstream oss;
+ oss << "img" << i << ".jpg";
+
+ ofstream outfile(oss.str().c_str(),ofstream::binary);
+ e.next_jpeg(&jpeg, &jpeg_size);
+ outfile.write((char*)jpeg, jpeg_size);
+
+ outfile.close();
+ }
+
+ e.stop();
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|