Skip to content

Commit

Permalink
Merge pull request #566 from ckuethe/verbose_tweak
Browse files Browse the repository at this point in the history
tune output of diagnostic messages.
  • Loading branch information
linuxkidd authored Oct 5, 2021
2 parents cf5dd14 + f67a7ff commit 5771404
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
38 changes: 29 additions & 9 deletions src/keogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void usage_and_exit(int x) {
<< std::endl;
std::cout << "-L | --font-line <int> : font line thickness (3)" << std::endl;
std::cout << "-N | --font-name <str> : font name (simplex)" << std::endl;
std::cout << "-S | --font-side <float> : font size (2.0)" << std::endl;
std::cout << "-S | --font-size <float> : font size (2.0)" << std::endl;
std::cout << "-T | --font-type <int> : font line type (1)" << std::endl;

std::cout << KNRM << std::endl;
Expand Down Expand Up @@ -238,9 +238,16 @@ int get_font_by_name(char* s) {

int main(int argc, char* argv[]) {
struct config_t config;
int i;
char* e;

parse_args(argc, argv, &config);

if (config.verbose < 1)
if ((e = getenv("ALLSKY_DEBUG_LEVEL")))
if ((i = atoi(e)) > 0)
config.verbose = i;

if (config.img_src_dir.empty() || config.img_src_ext.empty() ||
config.dst_keogram.empty())
usage_and_exit(3);
Expand All @@ -262,28 +269,41 @@ int main(int argc, char* argv[]) {
for (size_t f = 0; f < files.gl_pathc; f++) {
cv::Mat imagesrc = cv::imread(files.gl_pathv[f], cv::IMREAD_UNCHANGED);
if (!imagesrc.data) {
std::cout << "Error reading file " << basename(files.gl_pathv[f])
<< std::endl;
if (config.verbose)
std::cout << "Error reading file " << basename(files.gl_pathv[f])
<< std::endl;
continue;
}

if (config.verbose)
if (config.verbose > 1)
std::cout << "[" << f + 1 << "/" << files.gl_pathc << "] "
<< basename(files.gl_pathv[f]) << std::endl;

if (config.img_height && config.img_width &&
(imagesrc.cols != config.img_width ||
imagesrc.rows != config.img_height)) {
fprintf(stderr, "%s size %dx%d != %dx%d\n", files.gl_pathv[f],
imagesrc.cols, imagesrc.cols, config.img_width,
config.img_height);
if (config.verbose) {
fprintf(stderr,
"%s image size %dx%d does not match expected size %dx%d\n",
files.gl_pathv[f], imagesrc.cols, imagesrc.cols,
config.img_width, config.img_height);
}
continue;
}

if (nchan == 0)
nchan = imagesrc.channels();

if (imagesrc.channels() != nchan)
continue;
if (imagesrc.channels() != nchan) {
if (config.verbose) {
fprintf(stderr, "repairing channel mismatch: %d != %d\n",
imagesrc.channels(), nchan);
}
if (imagesrc.channels() < nchan)
cv::cvtColor(imagesrc, imagesrc, cv::COLOR_GRAY2BGR, nchan);
else if (imagesrc.channels() > nchan)
cv::cvtColor(imagesrc, imagesrc, cv::COLOR_BGR2GRAY, nchan);
}

cv::Point2f center((imagesrc.cols - 1) / 2.0, (imagesrc.rows - 1) / 2.0);
cv::Mat rot = cv::getRotationMatrix2D(center, config.rotation_angle, 1.0);
Expand Down
23 changes: 16 additions & 7 deletions src/startrails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,16 @@ void usage_and_exit(int x) {

int main(int argc, char* argv[]) {
struct config_t config;
int i;
char* e;

parse_args(argc, argv, &config);

if (config.verbose < 1)
if ((e = getenv("ALLSKY_DEBUG_LEVEL")))
if ((i = atoi(e)) > 0)
config.verbose = i;

if (config.img_src_dir.empty() || config.img_src_ext.empty())
usage_and_exit(3);

Expand Down Expand Up @@ -158,16 +165,18 @@ int main(int argc, char* argv[]) {
for (size_t f = 0; f < files.gl_pathc; f++) {
cv::Mat image = cv::imread(files.gl_pathv[f], cv::IMREAD_UNCHANGED);
if (!image.data) {
std::cout << "Error reading file " << basename(files.gl_pathv[f])
<< std::endl;
if (config.verbose)
fprintf(stderr, "Error reading file %s\n", basename(files.gl_pathv[f]));
stats.col(f) = 1.0; // mark as invalid
continue;
}

if (config.img_height && config.img_width &&
(image.cols != config.img_width || image.rows != config.img_height)) {
fprintf(stderr, "%s size %dx%d != %dx%d\n", files.gl_pathv[f], image.cols,
image.cols, config.img_width, config.img_height);
if (config.verbose)
fprintf(stderr, "skipped %s - got size %dx%d, want %dx%d\n",
files.gl_pathv[f], image.cols, image.cols, config.img_width,
config.img_height);
continue;
}

Expand Down Expand Up @@ -195,7 +204,7 @@ int main(int argc, char* argv[]) {
mean /= 65535.0;
break;
}
if (config.verbose)
if (config.verbose > 1)
std::cout << "[" << f + 1 << "/" << files.gl_pathc << "] "
<< basename(files.gl_pathv[f]) << " " << mean << std::endl;

Expand All @@ -204,8 +213,8 @@ int main(int argc, char* argv[]) {
if (config.startrails_enabled && mean <= config.brightness_limit) {
if (image.channels() != nchan) {
if (config.verbose)
fprintf(stderr, "repairing channel mismatch: %d != %d\n",
image.channels(), nchan);
fprintf(stderr, "repairing %s channel mismatch: got %d, want %d\n",
files.gl_pathv[f], image.channels(), nchan);
if (image.channels() < nchan)
cv::cvtColor(image, image, cv::COLOR_GRAY2BGR, nchan);
else if (image.channels() > nchan)
Expand Down

0 comments on commit 5771404

Please sign in to comment.