Remove dependency on png++, use openCV instead.

This commit is contained in:
2018-04-06 12:24:07 +02:00
parent 2bc3d5ae95
commit 9dc4f1546d
5 changed files with 12 additions and 99 deletions

View File

@@ -22,7 +22,6 @@ target_compile_options(fmri PRIVATE "-Wall" "-Wextra" "-pedantic")
find_package(Caffe REQUIRED) find_package(Caffe REQUIRED)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED) find_package(GLUT REQUIRED)
find_package(png++ REQUIRED)
find_package(Boost REQUIRED COMPONENTS filesystem program_options) find_package(Boost REQUIRED COMPONENTS filesystem program_options)
find_package(OpenCV REQUIRED COMPONENTS core imgproc imgcodecs) find_package(OpenCV REQUIRED COMPONENTS core imgproc imgcodecs)
@@ -30,7 +29,6 @@ target_link_libraries(fmri PUBLIC
Caffe::Caffe Caffe::Caffe
GLUT::GLUT GLUT::GLUT
OpenGL::GLU OpenGL::GLU
png++::png++
Boost::program_options Boost::program_options
opencv_core opencv_core
opencv_imgproc opencv_imgproc

View File

@@ -1,66 +0,0 @@
# - Try to find png++
#
# The following variables are optionally searched for defaults
# png++_ROOT_DIR: Base directory where all png++ components are found
#
# The following are set after configuration is done:
# png++_FOUND
# png++_INCLUDE_DIRS
# png++_LIBRARIES
find_package(PNG REQUIRED)
include(FindPackageHandleStandardArgs)
set(png++_ROOT_DIR "" CACHE PATH "Folder contains png++")
find_path(png++_INCLUDE_DIR
NAMES
png++/color.hpp
png++/config.hpp
png++/consumer.hpp
png++/convert_color_space.hpp
png++/end_info.hpp
png++/error.hpp
png++/ga_pixel.hpp
png++/generator.hpp
png++/gray_pixel.hpp
png++/image.hpp
png++/image_info.hpp
png++/index_pixel.hpp
png++/info.hpp
png++/info_base.hpp
png++/io_base.hpp
png++/packed_pixel.hpp
png++/palette.hpp
png++/pixel_buffer.hpp
png++/pixel_traits.hpp
png++/png.hpp
png++/reader.hpp
png++/require_color_space.hpp
png++/rgb_pixel.hpp
png++/rgba_pixel.hpp
png++/streaming_base.hpp
png++/tRNS.hpp
png++/types.hpp
png++/writer.hpp
PATHS
${png++_ROOT_DIR}
PATH_SUFFIXES
src)
set(png++_INCLUDE_DIRS ${png++_INCLUDE_DIR} ${PNG_INCLUDE_DIRS})
set(png++_LIBRARY ${PNG_LIBRARIES})
find_package_handle_standard_args(png++ DEFAULT_MSG
png++_INCLUDE_DIR)
if(png++_FOUND)
set(png++_INCLUDE_DIRS ${png++_INCLUDE_DIR})
set(png++_LIBRARIES ${png++_LIBRARY})
add_library(png++::png++ INTERFACE IMPORTED)
set_target_properties(png++::png++ PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${png++_INCLUDE_DIR}
INTERFACE_LINK_LIBRARIES PNG::PNG)
endif()

View File

@@ -2,7 +2,8 @@
#include <glog/logging.h> #include <glog/logging.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <png++/png.hpp> #include <opencv2/core/mat.hpp>
#include <opencv2/imgcodecs.hpp>
#include "PNGDumper.hpp" #include "PNGDumper.hpp"
@@ -50,41 +51,21 @@ void PNGDumper::dumpImageSeries(const LayerData &layer)
const auto images = shape[0], channels = shape[1], height = shape[2], width = shape[3]; const auto images = shape[0], channels = shape[1], height = shape[2], width = shape[3];
const auto imagePixels = width * height; const auto imagePixels = width * height;
// Buffer for storing the current image data. cv::Mat image(width, height, CV_32FC1);
vector<DType> buffer(imagePixels);
auto data = layer.data(); auto data = layer.data();
png::image<png::gray_pixel> image(width, height);
for (int i = 0; i < images; ++i) { for (int i = 0; i < images; ++i) {
for (int j = 0; j < channels; ++j) { for (int j = 0; j < channels; ++j) {
memcpy(buffer.data(), data, imagePixels * sizeof(DType)); char pathBuf[PATH_MAX];
std::copy_n(data, imagePixels, image.begin<float>());
rescale(image.begin<float>(), image.end<float>(), 0, 255);
std::snprintf(pathBuf, sizeof(pathBuf), "%s/%s-%d-%d.png", baseDir_.c_str(), layer.name().c_str(), i, j);
cv::imwrite(pathBuf, image);
// advance the buffer;
data += imagePixels; data += imagePixels;
rescale(buffer.begin(), buffer.end(), 0.0, 255.0);
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
image[y][x] = png::gray_pixel((int) buffer[x + y * width]);
}
}
image.write(getFilename(layer.name(), i, j));
} }
} }
} }
string PNGDumper::getFilename(const string &layerName, int i, int j)
{
stringstream nameBuilder;
nameBuilder << baseDir_
<< "/" << layerName
<< "-" << i
<< "-" << j << ".png";
return nameBuilder.str();
}

View File

@@ -23,6 +23,5 @@ namespace fmri
void dumpImageSeries(const LayerData &data); void dumpImageSeries(const LayerData &data);
string getFilename(const string &basic_string, int i, int j);
}; };
} }

View File

@@ -28,7 +28,6 @@ static void loadSimulationData(const Options &options)
} }
CHECK_GT(results.size(), 0) << "Should have some results" << endl; CHECK_GT(results.size(), 0) << "Should have some results" << endl;
RenderingState::instance().loadSimulationData(simulator.layerInfo(), std::move(results));
if (dumper) { if (dumper) {
for (auto &layer : *results.begin()) { for (auto &layer : *results.begin()) {
@@ -46,6 +45,8 @@ static void loadSimulationData(const Options &options)
LOG(INFO) << "Got answer: " << labels[bestIndex] << endl; LOG(INFO) << "Got answer: " << labels[bestIndex] << endl;
} }
} }
RenderingState::instance().loadSimulationData(simulator.layerInfo(), std::move(results));
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])