iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tests/test-ImageReader.C
/*! @file
@author Unknown
@copyright GNU Public License (GPL v3)
@section License
@verbatim
// ////////////////////////////////////////////////////////////////////////
// The iLab Neuromorphic Robotics Toolkit (NRT) //
// Copyright 2010-2012 by the University of Southern California (USC) //
// and the iLab at USC. //
// //
// iLab - University of Southern California //
// Hedco Neurociences Building, Room HNB-10 //
// Los Angeles, Ca 90089-2520 - USA //
// //
// See http://ilab.usc.edu for information about this project. //
// ////////////////////////////////////////////////////////////////////////
// This file is part of The iLab Neuromorphic Robotics Toolkit. //
// //
// The iLab Neuromorphic Robotics Toolkit is free software: you can //
// redistribute it and/or modify it under the terms of the GNU General //
// Public License as published by the Free Software Foundation, either //
// version 3 of the License, or (at your option) any later version. //
// //
// The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
// that it will be useful, but WITHOUT ANY WARRANTY; without even the //
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
// PURPOSE. See the GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with The iLab Neuromorphic Robotics Toolkit. If not, see //
// <http://www.gnu.org/licenses/>. //
// ////////////////////////////////////////////////////////////////////////
@endverbatim */
#include <iostream>
NRT_DECLARE_PARAMETER(file, std::string, "Input file", "");
NRT_DECLARE_PARAMETER(quality, int, "JPEG quality (between 0-100)", 75);
int main(int argc, char const* argv[])
{
nrt::Manager mgr(argc, argv);
auto sink = mgr.addComponent<nrt::DisplayImageSink>("sink");
class MyParameters : public nrt::Component, public nrt::Parameter<file, quality>
auto params = mgr.addComponent<MyParameters>("params");
mgr.launch();
nrt::GenericImage img = nrt::readImage(params->file::get());
auto compressStart = nrt::now();
std::vector<nrt::byte> buffer = nrt::compressJPG(img, params->quality::get());
auto compressTime = nrt::now() - compressStart;
auto decompressStart = nrt::now();
nrt::GenericImage img2 = nrt::decompressJPG(buffer);
auto decompressTime = nrt::now() - decompressStart;
NRT_INFO("Original image size : " << rgbimg.width() * rgbimg.height() * 3);
NRT_INFO("Compressed image size: " << buffer.size());
NRT_INFO("Compression Took " << std::chrono::duration_cast<std::chrono::milliseconds>(compressTime).count() << " ms");
NRT_INFO("Decompression Took " << std::chrono::duration_cast<std::chrono::milliseconds>(decompressTime).count() << " ms");
sink->out(img2, "Compressed");
NRT_INFO("<<<<<<<< PRESS RETURN TO EXIT >>>>>>>>");
std::cin.get();
return 0;
}