diff options
| author | Nikita Kostovsky <nikita@kostovsky.me> | 2025-02-21 07:27:00 +0100 |
|---|---|---|
| committer | Nikita Kostovsky <nikita@kostovsky.me> | 2025-02-21 07:27:00 +0100 |
| commit | d12498504c279a0a85bbfb024f7903e34dbe07db (patch) | |
| tree | 0df9f3f8bf27470ac211a57bb8e44be0aa2f6138 /src/image.cpp | |
| parent | 27637ab117d8738236f6ab155300ff6e79e4843b (diff) | |
broken img calc; change dir struct
Diffstat (limited to 'src/image.cpp')
| -rw-r--r-- | src/image.cpp | 74 |
1 files changed, 57 insertions, 17 deletions
diff --git a/src/image.cpp b/src/image.cpp index e4d51c1..befcb2b 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -9,12 +9,17 @@ #include "macro.h" #include "pixels.h" +uint64_t dq_elapsed_ns = 0; +uint64_t get_elapsed_ns = 0; uint64_t sum_elapsed_ns = 0; uint64_t corr_elapsed_ns = 0; uint64_t max_elapsed_ns = 0; uint64_t value_elapsed_ns = 0; +uint64_t rot_elapsed_ns = 0; -float process_column(const uint8_t (&column)[]) +// float process_column(const uint8_t (&column)[]) +// float process_column(const Image::row_t &column) +float process_column(const Image::column_t &column) { start_timer(process_column); QElapsedTimer t; @@ -23,39 +28,45 @@ float process_column(const uint8_t (&column)[]) float result = std::numeric_limits<float>::quiet_NaN(); constexpr uint32_t signalThreshold = 900; // = SKO * sqrt(patternSize) - static constexpr uint32_t patternOffset = patternSize - - ((patternSize % 2 == 1) ? 1 : 0); - const uint32_t correlationSize = img_height - patternSize + - ((patternSize % 2 == 1) ? 1 : 0); + static constexpr uint32_t patternOffset = patternSize - ((patternSize % 2 == 1) ? 1 : 0); + const uint32_t correlationSize = img_height - patternSize + ((patternSize % 2 == 1) ? 1 : 0); + // constexpr uint32_t correlationSize = img_height - patternSize; uint32_t correlation[img_height]; uint32_t integralSum[img_height]; - uint32_t maxSum = signalThreshold * 50; + uint32_t maxTripleSum = signalThreshold * 50; uint32_t x1 = 0; int32_t y1 = 0; int32_t y2 = 0; memset(correlation, 0, img_height * sizeof(correlation[0])); + // memset(correlation, 0, patternSize / 2); integralSum[0] = 0; for (uint32_t i = 1; i < img_height; ++i) { integralSum[i] = column[i] + integralSum[i - 1]; } + sum_elapsed_ns += t.nsecsElapsed(); t.restart(); + // pixel * <sum of neighbours> for (uint32_t i = 0; i < correlationSize; ++i) correlation[i + patternSize / 2] = column[i + patternSize / 2] * (integralSum[i + patternOffset] - integralSum[i]); + // * (integralSum[i + patternSize] - integralSum[i]); corr_elapsed_ns += t.nsecsElapsed(); t.restart(); for (uint32_t i = 3; i < img_height - 2; ++i) { + // p - pixel, n - neighbour + // P - pixel used in sum, N - neighbour used in sum + // [N P N] const auto sum = correlation[i - 1] + correlation[i] + correlation[i + 1]; - if (sum > maxSum) - { + if (sum > maxTripleSum) { + // [N N n p] - [P N] const int32_t rioux0 = int32_t(correlation[i - 2 - 1] + correlation[i - 1 - 1]) - int32_t(correlation[i + 1 - 1] + @@ -63,6 +74,7 @@ float process_column(const uint8_t (&column)[]) if (rioux0 < 0) { + // [N N p] - [p N N] const int32_t rioux1 = int32_t(correlation[i - 2] + correlation[i - 1]) - int32_t(correlation[i + 1] + @@ -73,7 +85,7 @@ float process_column(const uint8_t (&column)[]) x1 = i - 1; y1 = rioux0; y2 = rioux1; - maxSum = sum; + maxTripleSum = sum; } } } @@ -88,23 +100,40 @@ float process_column(const uint8_t (&column)[]) return result; } +// uint8_t &Image::dataAt(size_t row, size_t col) +// { +// const auto index = img_width * row + col; +// return *(data + index); +// } + void Image::rotate() { - start_timer(rotate); + QElapsedTimer t; + t.start(); + // start_timer(rotate); using namespace std; + // Image::data_t &d = *data; #pragma omp parallel #pragma omp for - for (size_t i = 0; i < img_height; ++i) - { - for (size_t j = 0; j < img_width; ++j) - { - rotated_cw[j][i] = data[img_height - i][j]; + for (size_t i = 0; i < img_height; ++i) { + for (size_t j = 0; j < img_width; ++j) { + // for (size_t j = 0; j < img_width; j += 4) { + rotated_cw[j][i] = data[img_height - i - 1][j]; + // rotated_cw[j][i] = d[img_height - i - 1][j]; + + // rotated_cw[j + 0][i] = data[img_height - i - 1][j + 0]; + // rotated_cw[j + 1][i] = data[img_height - i - 1][j + 1]; + // rotated_cw[j + 2][i] = data[img_height - i - 1][j + 2]; + // rotated_cw[j + 3][i] = data[img_height - i - 1][j + 3]; + + // rotated_cw[j][i] = dataAt(img_height - i - 1, j); } } - stop_timer(rotate); + // stop_timer(rotate); + rot_elapsed_ns += t.nsecsElapsed(); } std::shared_ptr<Pixels> Image::pixels() const @@ -113,6 +142,11 @@ std::shared_ptr<Pixels> Image::pixels() const result->counters = counters; start_timer(process_columns); + // std::transform(std::execution::par_unseq, + // rotated_cw.cbegin(), + // rotated_cw.cend(), + // result->pixels.begin(), + // [](const auto &column) -> float { return process_column(column); }); #pragma omp chunk #pragma omp parallel for @@ -139,15 +173,21 @@ void Image::copyFromData(const void *src, size_t size) switch (pixelFormat) { case libcamera::formats::R8: { // std::cout << "R8" << std::endl; - memcpy(data, src, size); + // memcpy(data, src, size); + // memcpy(data->data(), src, size); + memcpy(&data, src, size); + // data = (uint8_t *) src; break; } case libcamera::formats::R16: { // std::cout << "R16" << std::endl; + // data_t &d = *data; #pragma omp parallel #pragma omp for for (size_t i = 0; i < img_size; i++) { data[i / img_width][i % img_width] = (((uint16_t *) src)[i] & 0xff00) >> 8; + // d[i / img_width][i % img_width] = (((uint16_t *) src)[i] & 0xff00) >> 8; + // dataAt(i / img_width, i % img_width) = (((uint16_t *) src)[i] & 0xff00) >> 8; } break; } |
