Skip to content

Commit

Permalink
Add tests for successful loading of image files
Browse files Browse the repository at this point in the history
with image files that represent different tiff encodings
  • Loading branch information
martin-schulze-vireso authored and SSE4 committed Jun 10, 2020
1 parent d4f6e56 commit 947457b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ CONAN_BASIC_SETUP()

ADD_EXECUTABLE(lena lena.cpp)
TARGET_LINK_LIBRARIES(lena ${CONAN_LIBS})

ADD_EXECUTABLE(load-image load-image.cpp)
TARGET_LINK_LIBRARIES(load-image ${CONAN_LIBS})
configure_file(normal.tiff "${CMAKE_BINARY_DIR}/bin" COPYONLY)
configure_file(jbig.tiff "${CMAKE_BINARY_DIR}/bin" COPYONLY)
configure_file(lzma.tiff "${CMAKE_BINARY_DIR}/bin" COPYONLY)
2 changes: 2 additions & 0 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ def test(self):
shutil.copy(img_path, 'bin')
with tools.chdir('bin'):
self.run('lena.exe' if self.settings.os == 'Windows' else './lena', run_environment=True)
for image in ['lena.jpg', 'normal.tiff', 'lzma.tiff', 'jbig.tiff']:
self.run(('load-image.exe' if self.settings.os == 'Windows' else './load-image') + ' ' + image, run_environment=True)
Binary file added test_package/jbig.tiff
Binary file not shown.
25 changes: 25 additions & 0 deletions test_package/load-image.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "opencv2/opencv.hpp"
#include "opencv2/core/utils/logger.hpp"
#include <iostream>
#include <fstream>

bool file_exists(const char *filepath) {
std::ifstream file(filepath);
return file.good();
}

int main( int argc, const char** argv ){
cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_DEBUG);
cv::Mat image = cv::imread(argv[1]);
if(!file_exists(argv[1])) {
std::cerr << "File " << argv[1] << " does not exist!\n";
return 1;
}
if(image.data == nullptr) {
std::cerr << "Error: could not load image " << argv[1] << "\n";
return 1;
} else {
std::cout << "Successfully load image " << argv[1] << " of size " << image.size() << "\n";
return 0;
}
}
Binary file added test_package/lzma.tiff
Binary file not shown.
Binary file added test_package/normal.tiff
Binary file not shown.

0 comments on commit 947457b

Please sign in to comment.