diff options
| author | Nikita Kostovsky <nikita@kostovsky.me> | 2025-01-23 15:49:39 +0100 |
|---|---|---|
| committer | Nikita Kostovsky <nikita@kostovsky.me> | 2025-01-23 15:49:39 +0100 |
| commit | 459fe70f53b2f3a7dc33c3833210f60840a23204 (patch) | |
| tree | b670c6fe344e499affad0334491ddeaa26d102e0 | |
| parent | 80949709a1132b5198bb8006963f177fcde2e991 (diff) | |
change img data type to uint8_t, fix loading of bin calibration table
| -rw-r--r-- | imagealgos.cpp | 1 | ||||
| -rw-r--r-- | main.cpp | 22 | ||||
| -rw-r--r-- | src/calibration.cpp | 5 | ||||
| -rw-r--r-- | src/camera/innomakerov9281.h | 13 | ||||
| -rw-r--r-- | src/camera/ov9281.cpp | 5 | ||||
| -rw-r--r-- | src/camera/ov9281.h | 2 | ||||
| -rw-r--r-- | src/image.cpp | 24 |
7 files changed, 56 insertions, 16 deletions
diff --git a/imagealgos.cpp b/imagealgos.cpp index 5936855..80a1c92 100644 --- a/imagealgos.cpp +++ b/imagealgos.cpp @@ -65,6 +65,7 @@ size_t pgm_save(std::shared_ptr<Image> img, FILE *outfile, bool really_save) } } + std::cout << "written pgm image" << std::endl; return n; } @@ -110,6 +110,12 @@ void onNewPixels( // qDebug() << __func__ << "got empty pixels"; } + for (size_t i = 640 - 5; i < 640 + 5; i++) { + // std::cout << pixels->pixels[i] << " "; + } + + // std::cout << std::endl + ::pixels = *pixels; } @@ -144,7 +150,7 @@ int main(int argc, char* argv[]) // if (false) qDebug() << "size of raw profile" << sizeof(Pixels); - if (false) { + if (true) { // open binary calibration table if (true) { if (!openCalibrationTable("/home/user/dumps/binz.calibration_table", @@ -294,8 +300,7 @@ int main(int argc, char* argv[]) interpolate(::calibrationTableX); - if (!dump(::calibrationTableZ, - "/home/user/dumps/binx.calibration_table")) { + if (!dump(::calibrationTableX, "/home/user/dumps/binx.calibration_table")) { qApp->exit(EXIT_FAILURE); } @@ -305,6 +310,14 @@ int main(int argc, char* argv[]) } } + QCryptographicHash hashZ(QCryptographicHash::Sha256); + hashZ.addData(QByteArrayView((char *) ::calibrationTableZ.data(), sizeof(CalibrationTable))); + qDebug() << "hash z" << sizeof(::calibrationTableZ) << hashZ.result().toHex(); + + QCryptographicHash hashX(QCryptographicHash::Sha256); + hashX.addData(QByteArrayView((char *) ::calibrationTableX.data(), sizeof(CalibrationTable))); + qDebug() << "hash x" << sizeof(::calibrationTableX) << hashX.result().toHex(); + // exit(EXIT_SUCCESS); // if (!initLaser()) { @@ -353,7 +366,10 @@ int main(int argc, char* argv[]) QHttpServer qHttpServer; qHttpServer.route("/v1/sensor/image", [&]() { std::cout << "http: image" << std::endl << std::flush; + // FILE *f = fopen("/tmp/img.pgm", "w"); + // static bool save = false; pgm_save(::img); + // save = false; std::lock_guard<std::mutex> lg(pgm_image_mtx); qDebug() << "mutex locked"; qDebug() << "image saved to array"; diff --git a/src/calibration.cpp b/src/calibration.cpp index 33423b3..5caae02 100644 --- a/src/calibration.cpp +++ b/src/calibration.cpp @@ -324,8 +324,9 @@ CalibrationTablePtr calibrateX( // `pixelsToLines`. e.g. the most left/right lines. skip such points if (columnX < xLeft || columnX > xRight) { if (rawProfile.counters.encoderPosition >= 0) { - qWarning() - << "x anchor not found" << xLeft << columnX << xRight; + // FIXME: xRight can be smaller than xLeft + // qWarning() + // << "x anchor not found" << xLeft << columnX << xRight; continue; } } diff --git a/src/camera/innomakerov9281.h b/src/camera/innomakerov9281.h index bcafc12..51485cb 100644 --- a/src/camera/innomakerov9281.h +++ b/src/camera/innomakerov9281.h @@ -5,7 +5,14 @@ #include "constants.h" #include "image.h" -class InnoMakerOV9281 +class ICamera +{ +public: + virtual bool setExposureTimeMs(int value) = 0; + virtual bool setGain(int value) = 0; +}; + +class InnoMakerOV9281 : public ICamera { public: using buffer_t = std::array<uint8_t, img_size>; @@ -17,8 +24,8 @@ public: public: bool init(); - bool setExposureTimeMs(int value); - bool setGain(int value); + bool setExposureTimeMs(int value) override; + bool setGain(int value) override; bool getImage(Image &image); diff --git a/src/camera/ov9281.cpp b/src/camera/ov9281.cpp index b76ecdd..48f445f 100644 --- a/src/camera/ov9281.cpp +++ b/src/camera/ov9281.cpp @@ -189,7 +189,7 @@ void OV9281::onRequestCompleted(libcamera::Request *completed_request) .planes()[i]; size_t size = std::min(metaplane.bytesused, plane.length); - std::cout << "size is: " << size << std::endl; + // std::cout << "size is: " << size << std::endl; void *data = m_mappedBuffers[plane.fd.get()].first; auto img = std::make_shared<Image>(); @@ -204,7 +204,8 @@ void OV9281::onRequestCompleted(libcamera::Request *completed_request) img->counters.timestampUs = metadata.timestamp / 1000; img->counters.encoderPosition = RotaryEncoder::instance()->position(); - memcpy(img->data, data, size); + img->copyFromData(data, size); + // memcpy(img->data, data, size); img->rotate(); auto pixels = img->pixels(); diff --git a/src/camera/ov9281.h b/src/camera/ov9281.h index e989d96..1f2011a 100644 --- a/src/camera/ov9281.h +++ b/src/camera/ov9281.h @@ -65,5 +65,5 @@ private: std::unique_ptr<libcamera::FrameBufferAllocator> m_allocator{nullptr}; // TODO: set exposureTime from outside - int32_t m_exposureTime{100}; + int32_t m_exposureTime{3000}; }; diff --git a/src/image.cpp b/src/image.cpp index 000ca2d..e4d51c1 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -132,13 +132,27 @@ std::shared_ptr<Pixels> Image::pixels() const void Image::copyFromData(const void *src, size_t size) { - if (size > sizeof(data)) - { - // throw std::logic_error(std::format) + if (Q_UNLIKELY(size % sizeof(data) != 0 || size < sizeof(data))) { + throw std::logic_error(__func__ + std::string(": wrong data size")); } - if (pixelFormat == libcamera::formats::R8) - { + switch (pixelFormat) { + case libcamera::formats::R8: { + // std::cout << "R8" << std::endl; memcpy(data, src, size); + break; + } + case libcamera::formats::R16: { + // std::cout << "R16" << std::endl; +#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; + } + break; + } + default: + throw std::logic_error(__func__ + std::string(": unsupported pixel format")); + break; } } |
