I/O
[Vision Package]
Collaboration diagram for I/O:
|
Classes | |
| class | claraty::Camera_Group |
Functions | |
| template<class T> | |
| bool | save_camera_image (const std::string &filename, const Camera_Image< T > &img, const Parse_Block *extraHeader=NULL, const RGB_Image< T > *color_img=NULL) |
Detailed Description
Image file operations. Images can be saved and loaded to/from files using the Image_IO interface. The Image_IO class is actually an abstract base class with purely virtual load() and save() functions.
A generic algorithm would simply use an Image_IO object and not care about the implementation:
void my_algorithm(Image_IO& io) {
Image<unsigned char> my_image;
io.load(my_image);
...
The virtual Image_IO functions are overridden by specific Image_IO classes, such as Image_IO_Tiff, which implements loading and saving to/from files with the TIFF format.
We could then pass a specific implementation to the generic algorithm:
Image_IO_Tiff my_tiff_io();
my_tiff_io.set_filename("input.tif");
my_algorithm(my_tiff_io);
Or use the implementation directly:
Image<unsigned char> my_image;
my_tiff_io.save("output.tif", my_image);
Function Documentation
| bool save_camera_image | ( | const std::string & | filename, | |
| const Camera_Image< T > & | img, | |||
| const Parse_Block * | extraHeader = NULL, |
|||
| const RGB_Image< T > * | color_img = NULL | |||
| ) |
Saves a camera image, with its camera model and associated framestore. Additional header information can be passed in, as well as a color image, which will be saved instead of the pixels in the camera_image if it is given (so far we don't have a color camera_image type).
Definition at line 48 of file camera_image_io.h.
References claraty::object_to_string(), and claraty::string_suffix().
00052 { 00053 Image_IO_Factory *io = 00054 (*Image_IO_Factory::factory)(string_suffix(filename)); 00055 if (io == NULL) { 00056 std::cerr << "Unable to find helper class for saving images of type " 00057 << string_suffix(filename) << std::endl; 00058 return false; 00059 } 00060 00061 const int image_io_state_version = 2; 00062 00063 std::auto_ptr<Camera_Model> model(img.get_camera_model_ptr()); 00064 std::string mRep = FDM_Parse_Tree::object_to_string(model); 00065 assert(model.get() == img.get_camera_model_ptr()); 00066 00067 std::string fs_rep; 00068 if (model.get() == NULL || model->get_frame().is_empty()) { 00069 Framestore tmp(""); 00070 fs_rep = FDM_Parse_Tree::object_to_string(tmp); 00071 } else 00072 fs_rep = FDM_Parse_Tree::object_to_string(model->get_frame().get_store()); 00073 00074 model.release(); 00075 00076 Parse_Block pb; 00077 if (extraHeader != NULL) 00078 pb = *extraHeader; 00079 00080 pb.add_entry("framestore", fs_rep); 00081 pb.add_entry("model", mRep); 00082 pb.add_entry("image_io_state_version", image_io_state_version); 00083 std::string pbString = pb.write_to_string(); 00084 00085 bool raster_allocated = true; 00086 unsigned char *raster; 00087 int sig_bits; 00088 00089 if (color_img != NULL) { 00090 sig_bits = Image_IO_Factory::compute_sigbits(color_img->get_red_channel()); 00091 raster = Image_IO_Factory::rasterize_image(*color_img); 00092 } else { 00093 sig_bits = Image_IO_Factory::compute_sigbits(img); 00094 raster = Image_IO_Factory::rasterize_image(img, raster_allocated); 00095 } 00096 00097 bool ok = io->save_image_bytes(filename, raster, img.nrows(), img.ncols(), 00098 sizeof(T), sig_bits, pbString, 00099 color_img != NULL); 00100 if (raster_allocated) 00101 delete [] raster; 00102 00103 delete io; 00104 00105 return ok; 00106 }
Here is the call graph for this function:
