Skip to content

Commit 947457b

Browse files
martin-schulze-viresoSSE4
authored andcommitted
Add tests for successful loading of image files
with image files that represent different tiff encodings
1 parent d4f6e56 commit 947457b

File tree

6 files changed

+33
-0
lines changed

6 files changed

+33
-0
lines changed

test_package/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ CONAN_BASIC_SETUP()
99

1010
ADD_EXECUTABLE(lena lena.cpp)
1111
TARGET_LINK_LIBRARIES(lena ${CONAN_LIBS})
12+
13+
ADD_EXECUTABLE(load-image load-image.cpp)
14+
TARGET_LINK_LIBRARIES(load-image ${CONAN_LIBS})
15+
configure_file(normal.tiff "${CMAKE_BINARY_DIR}/bin" COPYONLY)
16+
configure_file(jbig.tiff "${CMAKE_BINARY_DIR}/bin" COPYONLY)
17+
configure_file(lzma.tiff "${CMAKE_BINARY_DIR}/bin" COPYONLY)

test_package/conanfile.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ def test(self):
2727
shutil.copy(img_path, 'bin')
2828
with tools.chdir('bin'):
2929
self.run('lena.exe' if self.settings.os == 'Windows' else './lena', run_environment=True)
30+
for image in ['lena.jpg', 'normal.tiff', 'lzma.tiff', 'jbig.tiff']:
31+
self.run(('load-image.exe' if self.settings.os == 'Windows' else './load-image') + ' ' + image, run_environment=True)

test_package/jbig.tiff

272 Bytes
Binary file not shown.

test_package/load-image.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "opencv2/opencv.hpp"
2+
#include "opencv2/core/utils/logger.hpp"
3+
#include <iostream>
4+
#include <fstream>
5+
6+
bool file_exists(const char *filepath) {
7+
std::ifstream file(filepath);
8+
return file.good();
9+
}
10+
11+
int main( int argc, const char** argv ){
12+
cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_DEBUG);
13+
cv::Mat image = cv::imread(argv[1]);
14+
if(!file_exists(argv[1])) {
15+
std::cerr << "File " << argv[1] << " does not exist!\n";
16+
return 1;
17+
}
18+
if(image.data == nullptr) {
19+
std::cerr << "Error: could not load image " << argv[1] << "\n";
20+
return 1;
21+
} else {
22+
std::cout << "Successfully load image " << argv[1] << " of size " << image.size() << "\n";
23+
return 0;
24+
}
25+
}

test_package/lzma.tiff

494 Bytes
Binary file not shown.

test_package/normal.tiff

3.31 KB
Binary file not shown.

0 commit comments

Comments
 (0)