Update of /cvsroot/playerstage/code/player/server/drivers/shell
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28413/server/drivers/shell
Modified Files:
writelog.cc
Log Message:
applied patch
[ 1849707 ] writelog: more flexible naming/update camera module
Index: writelog.cc
===================================================================
RCS file: /cvsroot/playerstage/code/player/server/drivers/shell/writelog.cc,v
retrieving revision 1.87
retrieving revision 1.88
diff -C2 -d -r1.87 -r1.88
*** writelog.cc 1 Nov 2007 22:16:23 -0000 1.87
--- writelog.cc 15 Feb 2008 08:59:22 -0000 1.88
***************
*** 80,83 ****
--- 80,84 ----
- @ref interface_pointcloud3d
- @ref interface_actarray
+ - @ref interface_camera
The following interfaces are supported in principle but are currently
***************
*** 85,89 ****
- @ref interface_blobfinder
- - @ref interface_camera
- @ref interface_fiducial
- @ref interface_gps
--- 86,89 ----
***************
*** 103,129 ****
- Name of the directory to store the log file in. Relative paths are
taken from the directory player is run from. Absolute paths work
! as expected.
- basename (string)
! - Default: writelog, produces the logfile: "writelog_YYYY_MM_DD_HH_MM.log",
! where YYYY is the year, MM is the month, etc.
! - Base name of the logfile to attach the time stamp to. If specified the
logfile
! will be "(basename)_YYYY_MM_DD_HH_MM.log".
! - filename (string)
! - Default: "(basename)_YYYY_MM_DD_HH_MM.log", where YYYY is the year,
! MM is the month, etc. If this parameter is specified it will NOT be time
stamped.
! - Name of logfile.
- autorecord (integer)
- Default: 0
- Default log state; set to 1 for continous logging.
- camera_save_images (integer)
- Default: 0
! - Save camera data to image files as well as to the log file. The image
! files are named "writelog_YYYY_MM_DD_HH_MM_camera_II_NNNNNNN.pnm",
where II is the device index and NNNNNNN is the frame number.
-
@par Example
@verbatim
! # Log data from laser:0 position2d:0 to
"/home/data/logs/mydata_YYYY_MM_DD_HH_MM.log"
driver
(
--- 103,137 ----
- Name of the directory to store the log file in. Relative paths are
taken from the directory player is run from. Absolute paths work
! as expected. The directory is created if it doesn't exist.
! - timestamp_directory (integer)
! - Default: 0
! - Add a timestamp to log_directory, in the format "YYYY_MM_DD_HH_MM_SS",
! where YYYY is the year, MM is the month, etc.
- basename (string)
! - Default: "writelog_"
! - Base name of the log file.
! - timestamp (integer)
! - Default: 1
! - Add a timestamp to each file, in the format "YYYY_MM_DD_HH_MM_SS",
! where YYYY is the year, MM is the month, etc.
! - extension (string)
! - Default: ".log"
! - File extension for the log file.
- autorecord (integer)
- Default: 0
- Default log state; set to 1 for continous logging.
+ - camera_log_images (integer)
+ - Default: 1
+ - Save image data to the log file. If this is turned off, a log line is
still
+ generated for each frame, containing all information except the raw image
data.
- camera_save_images (integer)
- Default: 0
! - Save image data to external files within the log directory.
! The image files are named "(basename)(timestamp)_camera_II_NNNNNNN.pnm",
where II is the device index and NNNNNNN is the frame number.
@par Example
@verbatim
! # Log data from laser:0 position2d:0 to
"/home/data/logs/mydata_YYYY_MM_DD_HH_MM_SS.log"
driver
(
***************
*** 151,154 ****
--- 159,163 ----
#include <errno.h>
#include <sys/types.h>
+ #include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
***************
*** 258,271 ****
private: int WriteRFID(player_msghdr_t* hdr, void *data);
#if 0
// Write blobfinder data to file
private: void WriteBlobfinder(player_blobfinder_data_t *data);
- // Write camera data to file
- private: void WriteCamera(player_camera_data_t *data);
-
- // Write camera data to image file as well
- private: void WriteCameraImage(WriteLogDevice *device, player_camera_data_t
*data, struct timeval *ts);
-
// Write fiducial data to file
private: void WriteFiducial(player_fiducial_data_t *data);
--- 267,276 ----
private: int WriteRFID(player_msghdr_t* hdr, void *data);
+ // Write camera data to file
+ private: int WriteCamera(WriteLogDevice *device, player_msghdr_t* hdr, void
*data);
#if 0
// Write blobfinder data to file
private: void WriteBlobfinder(player_blobfinder_data_t *data);
// Write fiducial data to file
private: void WriteFiducial(player_fiducial_data_t *data);
***************
*** 284,289 ****
--- 289,297 ----
#endif
+ // Where to save files
+ private: char log_directory[1024];
// File to write data to
+ private: char filestem[1024];
private: char filename[1024];
private: FILE *file;
***************
*** 303,306 ****
--- 311,316 ----
private: bool enable_default;
+ // Save camera frames to log file?
+ private: bool cameraLogImages;
// Save camera frames to image files as well?
private: bool cameraSaveImages;
***************
*** 344,350 ****
char time_stamp[32];
char basename[1024];
char default_filename[1024];
char complete_filename[1024];
- char log_directory[1024];
this->file = NULL;
--- 354,360 ----
char time_stamp[32];
char basename[1024];
+ char extension[32];
char default_filename[1024];
char complete_filename[1024];
this->file = NULL;
***************
*** 356,367 ****
ts = localtime(&t);
strftime(time_stamp, sizeof(time_stamp),
! "_%Y_%m_%d_%H_%M", ts);
// Let user override default basename
! strcpy(basename, cf->ReadString(section, "basename", "writelog"));
// Attach the time stamp
! snprintf(default_filename, sizeof(default_filename), "%s%s.log",
! basename, time_stamp);
// Let user override default filename
--- 366,382 ----
ts = localtime(&t);
strftime(time_stamp, sizeof(time_stamp),
! "%Y_%m_%d_%H_%M_%S", ts);
// Let user override default basename
! strcpy(basename, cf->ReadString(section, "basename", "writelog_"));
!
! strcpy(extension, cf->ReadString(section, "extension", ".log"));
// Attach the time stamp
! snprintf(this->filestem, sizeof(this->filestem), "%s%s",
! basename, cf->ReadInt(section, "timestamp", 1) ? time_stamp : "");
!
! snprintf(default_filename, sizeof(default_filename), "%s%s",
! this->filestem, extension);
// Let user override default filename
***************
*** 370,378 ****
// Let user override log file directory
! strcpy(log_directory, cf->ReadString(section, "log_directory", "."));
// Prepend the directory
snprintf(this->filename, sizeof(this->filename), "%s/%s",
! log_directory, complete_filename);
// Default enabled?
--- 385,398 ----
// Let user override log file directory
! snprintf(this->log_directory, sizeof(this->log_directory), "%s%s",
! cf->ReadString(section, "log_directory", ""),
! cf->ReadInt(section, "timestamp_directory", 0) ? time_stamp : "");
!
! // If neither directory nor timestamp is specified, just use .
! if(this->log_directory[0] == 0) strcpy(this->log_directory, ".");
// Prepend the directory
snprintf(this->filename, sizeof(this->filename), "%s/%s",
! this->log_directory, complete_filename);
// Default enabled?
***************
*** 409,412 ****
--- 429,433 ----
// Camera specific settings
+ this->cameraLogImages = cf->ReadInt(section, "camera_log_images", 1);
this->cameraSaveImages = cf->ReadInt(section, "camera_save_images", 0);
***************
*** 490,493 ****
--- 511,517 ----
WriteLog::OpenFile()
{
+ // Create directory
+ mkdir(this->log_directory, 0755);
+
// Open the file
this->file = fopen(this->filename, "w+");
***************
*** 849,861 ****
retval = this->WriteIR(hdr, data);
break;
#if 0
case PLAYER_BLOBFINDER_CODE:
this->WriteBlobfinder((player_blobfinder_data_t*) data);
break;
- case PLAYER_CAMERA_CODE:
- this->WriteCamera((player_camera_data_t*) data);
- if (this->cameraSaveImages)
- this->WriteCameraImage(device, (player_camera_data_t*) data, &time);
- break;
case PLAYER_FIDUCIAL_CODE:
this->WriteFiducial((player_fiducial_data_t*) data);
--- 873,883 ----
retval = this->WriteIR(hdr, data);
break;
+ case PLAYER_CAMERA_CODE:
+ retval = this->WriteCamera(device, hdr, data);
+ break;
#if 0
case PLAYER_BLOBFINDER_CODE:
this->WriteBlobfinder((player_blobfinder_data_t*) data);
break;
case PLAYER_FIDUCIAL_CODE:
this->WriteFiducial((player_fiducial_data_t*) data);
***************
*** 2074,2077 ****
--- 2096,2100 ----
}
+ #endif
/** @ingroup tutorial_datalog
***************
*** 2086,2160 ****
- format (int): image format
- compression (int): image compression
! - image data, encoded as a string of ASCII hex values
*/
- void WriteLog::WriteCamera(player_camera_data_t *data)
- {
- char *str;
- size_t src_size, dst_size;
! // Image format
! fprintf(this->file, "%d %d %d %d %d %d " ,
! HUINT16(data->width), HUINT16(data->height),
! data->bpp, data->format, data->compression,
! HUINT32(data->image_size));
!
! // Check image size
! src_size = HUINT32(data->image_size);
! dst_size = ::EncodeHexSize(src_size);
! str = (char*) malloc(dst_size + 1);
!
! // Encode image into string
! ::EncodeHex(str, dst_size, data->image, src_size);
!
! // Write image bytes
! fprintf(this->file, str);
! free(str);
!
! return;
! }
! ////////////////////////////////////////////////////////////////////////////
! // Write camera data to image file as well
! void WriteLog::WriteCameraImage(WriteLogDevice *device, player_camera_data_t
*data, struct timeval *time)
! {
! FILE *file;
! char filename[1024];
! if (data->compression != PLAYER_CAMERA_COMPRESS_RAW)
! {
! PLAYER_WARN("unsupported compression method");
! return;
! }
! snprintf(filename, sizeof(filename), "%s_camera_%02d_%06d.pnm",
! this->default_basename, device->id.index, device->cameraFrame++);
! file = fopen(filename, "w+");
! if (file == NULL)
! return;
! if (data->format == PLAYER_CAMERA_FORMAT_RGB888)
! {
! // Write ppm header
! fprintf(file, "P6\n%d %d\n%d\n", HUINT16(data->width),
HUINT16(data->height), 255);
! fwrite(data->image, 1, HUINT32(data->image_size), file);
! }
! else if (data->format == PLAYER_CAMERA_FORMAT_MONO8)
! {
! // Write pgm header
! fprintf(file, "P5\n%d %d\n%d\n", HUINT16(data->width),
HUINT16(data->height), 255);
! fwrite(data->image, 1, HUINT32(data->image_size), file);
! }
! else
! {
! PLAYER_WARN("unsupported image format");
! }
! fclose(file);
! return;
}
/** @ingroup tutorial_datalog
--- 2109,2197 ----
- format (int): image format
- compression (int): image compression
! - (optional) image data, encoded as a string of ASCII hex values
*/
! int WriteLog::WriteCamera(WriteLogDevice *device, player_msghdr_t* hdr, void
*data)
! {
! player_camera_data_t *camera_data;
! switch(hdr->type)
! {
! case PLAYER_MSGTYPE_DATA:
! switch(hdr->subtype)
! {
! case PLAYER_CAMERA_DATA_STATE:
! camera_data = (player_camera_data_t *) data;
!
! // Image format
! fprintf(this->file, "%d %d %d %d %d %d " ,
! camera_data->width, camera_data->height,
! camera_data->bpp, camera_data->format,
! camera_data->compression,
camera_data->image_count);
!
! if(this->cameraLogImages)
! {
! char *str;
! size_t src_size, dst_size;
+ // Check image size
+ src_size = camera_data->image_count;
+ dst_size = ::EncodeHexSize(src_size);
+ str = (char*) malloc(dst_size + 1);
! // Encode image into string
! ::EncodeHex(str, dst_size, camera_data->image,
src_size);
! // Write image bytes
! fprintf(this->file, str);
! free(str);
! }
! if(this->cameraSaveImages)
! {
! FILE *file;
! char filename[1024];
! if (camera_data->compression !=
PLAYER_CAMERA_COMPRESS_RAW)
! {
! PLAYER_WARN("unsupported compression method");
! return -1;
! }
! snprintf(filename, sizeof(filename),
"%s/%s_camera_%02d_%06d.pnm",
! this->log_directory, this->filestem,
device->addr.index, device->cameraFrame++);
! file = fopen(filename, "w+");
! if (file == NULL)
! return -1;
! if (camera_data->format ==
PLAYER_CAMERA_FORMAT_RGB888)
! {
! // Write ppm header
! fprintf(file, "P6\n%d %d\n%d\n",
camera_data->width, camera_data->height, 255);
! fwrite(camera_data->image, 1,
camera_data->image_count, file);
! }
! else if (camera_data->format ==
PLAYER_CAMERA_FORMAT_MONO8)
! {
! // Write pgm header
! fprintf(file, "P5\n%d %d\n%d\n",
camera_data->width, camera_data->height, 255);
! fwrite(camera_data->image, 1,
camera_data->image_count, file);
! }
! else
! {
! PLAYER_WARN("unsupported image format");
! }
! fclose(file);
! }
! return 0;
! default:
! return -1;
! }
! default:
! return -1;
! }
! return -1;
}
+ #if 0
/** @ingroup tutorial_datalog
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit