From 96fc17b99d56eb636c894c5be9ab39bfdb4ba454 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sat, 27 Aug 2022 00:55:38 -0400 Subject: Initial code dump. --- tests/image_util_tests.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/image_util_tests.cpp (limited to 'tests/image_util_tests.cpp') diff --git a/tests/image_util_tests.cpp b/tests/image_util_tests.cpp new file mode 100644 index 0000000..af77f75 --- /dev/null +++ b/tests/image_util_tests.cpp @@ -0,0 +1,46 @@ +#include "imageutil.hpp" + +#include +#include + +#include +#include +#include + +int main(int argc, char** argv) +{ + if (argc < 2) + { + printf("usage: %s \n", argv[0]); + return 1; + } + cv::Mat i = cv::imread(argv[1], cv::IMREAD_UNCHANGED); + if (i.data == NULL) + { + printf("invalid image.\n"); + return 1; + } + cv::Mat fi, bw; + double sc = 1; + switch (i.depth()) + { + case CV_8U: sc = 1. / 255; break; + case CV_16U: sc = 1. / 65535; break; + } + i.convertTo(fi, CV_32F, sc); + if (fi.channels() == 4) + fi = image_util::blend_white(fi); + cv::cvtColor(fi, bw, cv::COLOR_RGB2GRAY); + cv::imshow(std::string("test"), bw); + cv::Range xr, yr; + double contrast_threshold = 0.05; + double max_crop_ratio = 0.25; + xr = image_util::crop_axis(bw, 0, contrast_threshold, max_crop_ratio); + yr = image_util::crop_axis(bw, 1, contrast_threshold, max_crop_ratio); + cv::Mat cfi = image_util::crop(bw, contrast_threshold, max_crop_ratio); + cv::imshow(std::string("cropped"), cfi); + printf("xxx [%d, %d) [%d, %d)\n", yr.start, yr.end, xr.start, xr.end); + puts("press q to quit."); + while (cv::waitKey(0) != 'q'); + return 0; +} -- cgit v1.2.3