diff options
Diffstat (limited to 'src')
| -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 |
5 files changed, 36 insertions, 13 deletions
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; } } |
