|
43 | 43 | #include "utils/apitools.h" |
44 | 44 | #include <random> |
45 | 45 |
|
| 46 | +#include "dto/img_connector.hpp" |
| 47 | + |
46 | 48 | namespace dd |
47 | 49 | { |
48 | 50 |
|
@@ -455,81 +457,89 @@ namespace dd |
455 | 457 |
|
456 | 458 | void fillup_parameters(const APIData &ad) |
457 | 459 | { |
| 460 | + auto params = ad.createSharedDTO<dd::DTO::ImgInputConnectorParameters>(); |
| 461 | + |
458 | 462 | // optional parameters. |
459 | | - if (ad.has("width")) |
460 | | - _width = ad.get("width").get<int>(); |
461 | | - if (ad.has("height")) |
462 | | - _height = ad.get("height").get<int>(); |
463 | | - if (ad.has("crop_width")) |
| 463 | + if (params->width) |
| 464 | + _width = params->width; |
| 465 | + if (params->height) |
| 466 | + _height = params->height; |
| 467 | + if (params->crop_width) |
464 | 468 | { |
465 | | - _crop_width = ad.get("crop_width").get<int>(); |
466 | | - if (_crop_width > _width) |
| 469 | + if (params->crop_width > _width) |
467 | 470 | { |
468 | 471 | _logger->error("Crop width must be less than or equal to width"); |
469 | 472 | throw InputConnectorBadParamException( |
470 | 473 | "Crop width must be less than or equal to width"); |
471 | 474 | } |
| 475 | + _width = params->crop_width; |
472 | 476 | } |
473 | | - if (ad.has("crop_height")) |
| 477 | + if (params->crop_height) |
474 | 478 | { |
475 | | - _crop_height = ad.get("crop_height").get<int>(); |
476 | | - if (_crop_height > _height) |
| 479 | + if (params->crop_height > _height) |
477 | 480 | { |
478 | 481 | _logger->error( |
479 | 482 | "Crop height must be less than or equal to height"); |
480 | 483 | throw InputConnectorBadParamException( |
481 | 484 | "Crop height must be less than or equal to height"); |
482 | 485 | } |
| 486 | + _height = params->crop_height; |
483 | 487 | } |
484 | | - if (ad.has("bw")) |
485 | | - _bw = ad.get("bw").get<bool>(); |
486 | | - if (ad.has("rgb")) |
487 | | - _rgb = ad.get("rgb").get<bool>(); |
488 | | - if (ad.has("histogram_equalization")) |
489 | | - _histogram_equalization = ad.get("histogram_equalization").get<bool>(); |
490 | | - if (ad.has("unchanged_data")) |
491 | | - _unchanged_data = ad.get("unchanged_data").get<bool>(); |
492 | | - if (ad.has("shuffle")) |
493 | | - _shuffle = ad.get("shuffle").get<bool>(); |
494 | | - if (ad.has("seed")) |
495 | | - _seed = ad.get("seed").get<int>(); |
496 | | - if (ad.has("test_split")) |
497 | | - _test_split = ad.get("test_split").get<double>(); |
498 | | - if (ad.has("mean")) |
| 488 | + |
| 489 | + _bw |= params->bw; |
| 490 | + _rgb |= params->rgb; |
| 491 | + _histogram_equalization |= params->histogram_equalization; |
| 492 | + _unchanged_data |= params->unchanged_data; |
| 493 | + _shuffle |= params->shuffle; |
| 494 | + if (params->seed) |
| 495 | + _seed = params->seed; |
| 496 | + if (params->test_split) |
| 497 | + _test_split = params->test_split; |
| 498 | + if (params->mean) |
499 | 499 | { |
500 | | - apitools::get_floats(ad, "mean", _mean); |
| 500 | + // NOTE(sileht): if we have two much of this we can create |
| 501 | + // an oat++ type that directly handle std::vector<float> instead |
| 502 | + // of using the oatpp::Vector<oatpp::Float32> |
| 503 | + _mean = std::vector<float>(); |
| 504 | + for (auto &v : *params->mean) |
| 505 | + _mean.push_back(v); |
501 | 506 | _has_mean_scalar = true; |
502 | 507 | } |
503 | | - if (ad.has("std")) |
| 508 | + if (params->std) |
504 | 509 | { |
505 | | - apitools::get_floats(ad, "std", _std); |
| 510 | + _std = std::vector<float>(); |
| 511 | + for (auto &v : *params->std) |
| 512 | + _std.push_back(v); |
506 | 513 | } |
507 | 514 |
|
508 | 515 | // Variable size |
509 | | - if (ad.has("scale")) |
510 | | - _scale = ad.get("scale").get<double>(); |
511 | | - if (ad.has("scaled") || ad.has("scale_min") || ad.has("scale_max")) |
512 | | - _scaled = true; |
513 | | - if (ad.has("scale_min")) |
514 | | - _scale_min = ad.get("scale_min").get<int>(); |
515 | | - if (ad.has("scale_max")) |
516 | | - _scale_max = ad.get("scale_max").get<int>(); |
| 516 | + _scaled |= params->scaled; |
| 517 | + if (params->scale) |
| 518 | + _scale = params->scale; |
| 519 | + if (params->scale_min) |
| 520 | + { |
| 521 | + _scaled = true; |
| 522 | + _scale_min = params->scale_min; |
| 523 | + } |
| 524 | + if (params->scale_max) |
| 525 | + { |
| 526 | + _scaled = true; |
| 527 | + _scale_max = params->scale_max; |
| 528 | + } |
517 | 529 |
|
518 | 530 | // whether to keep original image (for chained ops, e.g. cropping) |
519 | | - if (ad.has("keep_orig")) |
520 | | - _keep_orig = ad.get("keep_orig").get<bool>(); |
| 531 | + _keep_orig |= params->keep_orig; |
521 | 532 |
|
522 | 533 | // image interpolation method |
523 | | - if (ad.has("interp")) |
524 | | - _interp = ad.get("interp").get<std::string>(); |
| 534 | + if (params->interp) |
| 535 | + _interp = params->interp->std_str(); |
525 | 536 |
|
526 | 537 | // timeout |
527 | 538 | this->set_timeout(ad); |
528 | 539 |
|
529 | 540 | #ifdef USE_CUDA_CV |
530 | 541 | // image resizing on GPU |
531 | | - if (ad.has("cuda")) |
532 | | - _cuda = ad.get("cuda").get<bool>(); |
| 542 | + _cuda |= params->cuda; |
533 | 543 | #endif |
534 | 544 | } |
535 | 545 |
|
|
0 commit comments