summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt49
-rw-r--r--src/LibCamera.cpp (renamed from LibCamera.cpp)0
-rw-r--r--src/LibCamera.h (renamed from LibCamera.h)0
-rw-r--r--src/camera/icamera.h4
-rw-r--r--src/camera/innomakerov9281.cpp180
-rw-r--r--src/camera/innomakerov9281.h11
-rw-r--r--src/camera/ov9281.cpp12
-rw-r--r--src/constants.h2
-rw-r--r--src/fuck_intel.h (renamed from fuck_intel.h)0
-rw-r--r--src/genetic_algos.cpp (renamed from genetic_algos.cpp)0
-rw-r--r--src/genetic_algos.h (renamed from genetic_algos.h)0
-rw-r--r--src/httpservice.cpp (renamed from httpservice.cpp)0
-rw-r--r--src/httpservice.h (renamed from httpservice.h)0
-rw-r--r--src/image.cpp74
-rw-r--r--src/image.h18
-rw-r--r--src/imagealgos.cpp (renamed from imagealgos.cpp)25
-rw-r--r--src/imagealgos.h (renamed from imagealgos.h)5
-rw-r--r--src/macro.h (renamed from macro.h)0
-rw-r--r--src/main.cpp (renamed from main.cpp)35
-rw-r--r--src/printerclient.cpp (renamed from printerclient.cpp)0
-rw-r--r--src/printerclient.h (renamed from printerclient.h)0
-rw-r--r--src/profile.cpp (renamed from profile.cpp)0
-rw-r--r--src/profile.h (renamed from profile.h)0
-rw-r--r--src/rotaryencoder.cpp (renamed from rotaryencoder.cpp)0
-rw-r--r--src/rotaryencoder.h (renamed from rotaryencoder.h)0
25 files changed, 265 insertions, 150 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 01bf27f..8826e5e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,7 +7,7 @@ set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
-# set(CMAKE_AUTOMOC ON)
+set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC OFF)
# set(TARGET_SYSROOT /home/nikita/rpi/rpi-sysroot)
@@ -27,6 +27,9 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${TARGET_SYSROOT}/usr/include")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}")
+# NOTE: in case of header issues during inno-maker driver compilation - try to
+# reinstall linux-headers-<your exact running kernel version here>, like this
+# sudo apt install linux-headers-6.6.74+rpt-rpi-v8 --reinstall
# NOTE: on your rpi you'll need to install
# libcamera-dev, libcamera-ipa (TODO: check if ipa is needed)
@@ -61,6 +64,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}")
#
# export this path for qtcreator:
# LD_LIBRARY_PATH=/home/nikita/rpi/rpi-sysroot/usr/lib/aarch64-linux-gnu/:$LD_LIBRARY_PATH
+set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}/usr)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
@@ -97,40 +101,15 @@ find_package(TBB REQUIRED)
qt_standard_project_setup(REQUIRES 6.4)
-include_directories(. "${CAMERA_INCLUDE_DIRS}" src)
+include_directories("${CAMERA_INCLUDE_DIRS}" src)
# libpistache
pkg_check_modules(Pistache REQUIRED IMPORTED_TARGET libpistache)
# add_executable(${PROJECT_NAME}
-qt_add_executable(apporpheus
- httpservice.h
- httpservice.cpp
- imagealgos.h
- imagealgos.cpp
- macro.h
- main.cpp
- LibCamera.h
- LibCamera.cpp
- genetic_algos.h
- genetic_algos.cpp
- rotaryencoder.h
- rotaryencoder.cpp
- printerclient.h
- printerclient.cpp
- fuck_intel.h
- src/pixels.h src/pixels.cpp
- src/constants.h
- src/typedefs.h
- src/dumps.h src/dumps.cpp
- src/calibration.h src/calibration.cpp
- profile.h profile.cpp
- src/camera/ov9281.h src/camera/ov9281.cpp
- src/image.h src/image.cpp
- src/laser.h src/laser.cpp
- src/camera/innomakerov9281.h src/camera/innomakerov9281.cpp
- src/camera/icamera.h
-)
+file(GLOB_RECURSE SOURCES src/*.h src/*.cpp src/*.c src/*.qrc)
+message("sources: ${SOURCES}")
+qt_add_executable(apporpheus ${SOURCES})
target_link_libraries(app${PROJECT_NAME}
PRIVATE
"${LIBCAMERA_LIBRARIES}"
@@ -150,11 +129,11 @@ install(TARGETS app${PROJECT_NAME}
)
if ("${CMAKE_BUILD_TYPE}" MATCHES "Release")
- # message("it's Debug")
+ message("it's Release")
+ add_compile_options(-Ofast -fno-unroll-loops -Wall)
+ # add_compile_options(-Wall -Wextra -Wpedantic)
+ # add_compile_options(-O3 -Wall)
else()
- #message("it's not Debug")
+ message("it's not Release")
endif()
-
-# add_compile_options(-Wall -Wextra -Wpedantic)
-add_compile_options(-Ofast -fno-unroll-loops -Wall)
diff --git a/LibCamera.cpp b/src/LibCamera.cpp
index 1e68228..1e68228 100644
--- a/LibCamera.cpp
+++ b/src/LibCamera.cpp
diff --git a/LibCamera.h b/src/LibCamera.h
index 89cf835..89cf835 100644
--- a/LibCamera.h
+++ b/src/LibCamera.h
diff --git a/src/camera/icamera.h b/src/camera/icamera.h
index 3fccc4b..11919bb 100644
--- a/src/camera/icamera.h
+++ b/src/camera/icamera.h
@@ -35,12 +35,14 @@ public:
virtual bool setExposureTimeUs(int value) = 0;
virtual bool setGain(int value) = 0;
virtual bool setLaserLevel(int value) = 0;
+ virtual bool setSomething(int value) = 0;
public:
libcamera::Signal<std::shared_ptr<Pixels>> newPixels;
libcamera::Signal<std::shared_ptr<Image>> newImage;
std::function<void(std::shared_ptr<Pixels>)> newPixelsCallback;
- std::function<void(std::shared_ptr<Image>)> newImageCallback;
+ // std::function<void(std::shared_ptr<Image>)> newImageCallback;
+ std::function<void(Image &)> newImageCallback;
public:
virtual bool startStream() = 0;
diff --git a/src/camera/innomakerov9281.cpp b/src/camera/innomakerov9281.cpp
index b7c5cd4..79ae0b4 100644
--- a/src/camera/innomakerov9281.cpp
+++ b/src/camera/innomakerov9281.cpp
@@ -10,6 +10,9 @@
#include <unistd.h>
#include <iostream>
+#include <span>
+
+#include <QElapsedTimer>
#include "constants.h"
// #include "rotaryencoder.h"
@@ -23,10 +26,13 @@
#define DBG(fmt, args...) LOGD("%s:%d, " fmt, __FUNCTION__, __LINE__, ##args);
+extern uint64_t dq_elapsed_ns;
+extern uint64_t get_elapsed_ns;
extern uint64_t sum_elapsed_ns;
extern uint64_t corr_elapsed_ns;
extern uint64_t max_elapsed_ns;
extern uint64_t value_elapsed_ns;
+extern uint64_t rot_elapsed_ns;
// constexpr char videoDevice[] = "/dev/video0";
@@ -37,6 +43,9 @@ InnoMakerOV9281::~InnoMakerOV9281()
m_streamThread.request_stop();
m_streamThread.join();
+ m_someThread.request_stop();
+ m_someThread.join();
+
int ret{-1};
for (int i = 0; i < BUFFER_COUNT; ++i)
@@ -74,43 +83,84 @@ std::vector<std::shared_ptr<ICamera> > InnoMakerOV9281::search()
if (!cam->init())
return {};
- if (!cam->setExposureTimeUs(3000))
+ if (!cam->setExposureTimeUs(68000))
+ return {};
+
+ if (!cam->setLaserLevel(1))
+ return {};
+
+ if (!cam->setGain(2))
return {};
- if (!cam->setGain(3000))
+ if (!cam->setSomething(0)) {
return {};
+ }
+
+ // m_someThread = std::jthread{[=](std::stop_token stopToken) {
+ // std::cout << "InnoMakerOV9281: start stream" << std::endl;
+ // sleep(5);
+
+ // static int i = 0;
+ // while (!stopToken.stop_requested()) {
+ // cam->setSomething(i);
+ // i -= 1;
+ // }
+ // }};
return {cam};
}
bool InnoMakerOV9281::startStream()
{
+ int buffer_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ auto ret = ioctl(m_cam_fd, VIDIOC_STREAMON, &buffer_type);
+
+ if (ret != 0) {
+ DBG("ioctl(VIDIOC_STREAMON) failed %d(%s)", errno, strerror(errno));
+ return false;
+ }
+
m_streamThread = std::jthread{[&](std::stop_token stopToken) {
std::cout << "InnoMakerOV9281: start stream" << std::endl;
+ // Image image;
+ std::shared_ptr<Image> imageCopy = std::make_shared<Image>();
while (!stopToken.stop_requested())
{
- std::shared_ptr<Image> image = std::make_shared<Image>();
- getImage(*image);
-// FIXME: backup emit value
-#ifdef emit
-#undef emit
- // std::cout << "emit new image" << std::endl << std::flush;
- // newImage.emit(image);
- if (newImageCallback)
- {
+ size_t imageIndex{};
+
+ // if (!getImage(image))
+ if (!getImage(imageIndex))
+ break;
+
+ auto image = m_images[imageIndex];
+
+ // // FIXME: backup emit value
+ // #ifdef emit
+ // #undef emit
+ // // std::cout << "emit new image" << std::endl << std::flush;
+ // // newImage.emit(image);
+ if (newImageCallback) {
+ // memcpy(imageCopy.get(), &image, sizeof(Image));
+ // newImageCallback(imageCopy);
newImageCallback(image);
}
- // newPixels.emit(pixels);
- image->rotate();
- if (newPixelsCallback)
- {
- auto pixels = image->pixels();
+ // continue;
+ // // // newPixels.emit(pixels);
+ // auto &img = *image;
+ // image->rotate();
+ // img.rotate();
+ image.rotate();
+ // image.rotate();
+ if (newPixelsCallback) {
+ // auto pixels = image->pixels();
+ auto pixels = image.pixels();
newPixelsCallback(pixels);
}
+ continue;
}
-#define emit
-#endif
+ // #define emit
+ // #endif
std::cout << "InnoMakerOV9281: stream interruption requested"
<< std::endl;
}};
@@ -170,6 +220,13 @@ bool InnoMakerOV9281::setLaserLevel(int value)
return setCamParam(V4L2_CID_FLASH_TIMEOUT, value);
}
+bool InnoMakerOV9281::setSomething(int value)
+{
+ std::cout << __func__ << ": " << value << std::endl << std::flush;
+
+ return setCamParam(V4L2_CID_FLASH_INTENSITY, value);
+}
+
bool InnoMakerOV9281::setCamParam(unsigned int v4l2controlId, int value)
{
v4l2_control ctl{v4l2controlId, value};
@@ -182,6 +239,7 @@ bool InnoMakerOV9281::setCamParam(unsigned int v4l2controlId, int value)
"cannot set cam param: id - %d, error - '%s'\n",
v4l2controlId,
strerror(errno));
+ fflush(stderr);
return false;
}
@@ -195,6 +253,8 @@ bool InnoMakerOV9281::setCamParam(unsigned int v4l2controlId, int value)
v4l2controlId,
strerror(errno));
+ fflush(stderr);
+
return false;
}
@@ -277,11 +337,8 @@ bool InnoMakerOV9281::initCam()
request.memory = V4L2_MEMORY_MMAP;
ret = ioctl(m_cam_fd, VIDIOC_REQBUFS, &request);
- if (ret < 0)
- {
- fprintf(stderr,
- "cannot set cam request buffers: ioctl error - '%s'\n",
- strerror(errno));
+ if (ret < 0) {
+ fprintf(stderr, "cannot set cam request buffers: ioctl error - '%s'\n", strerror(errno));
return false;
}
@@ -311,14 +368,9 @@ bool InnoMakerOV9281::initCam()
DBG("buffer.length: %d", buffer.length);
DBG("buffer.m.offset: %d", buffer.m.offset);
- video_buffer_ptr[i] = (uint8_t *) mmap(NULL,
- buffer.length,
- PROT_READ | PROT_WRITE,
- MAP_SHARED,
- m_cam_fd,
- buffer.m.offset);
- if (video_buffer_ptr[i] == MAP_FAILED)
- {
+ video_buffer_ptr[i] = (uint8_t *)
+ mmap(NULL, buffer.length, PROT_READ | PROT_WRITE, MAP_SHARED, m_cam_fd, buffer.m.offset);
+ if (video_buffer_ptr[i] == MAP_FAILED) {
DBG("mmap() failed %d(%s)", errno, strerror(errno));
return false;
}
@@ -334,20 +386,23 @@ bool InnoMakerOV9281::initCam()
}
}
- int buffer_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- ret = ioctl(m_cam_fd, VIDIOC_STREAMON, &buffer_type);
- if (ret != 0)
- {
- DBG("ioctl(VIDIOC_STREAMON) failed %d(%s)", errno, strerror(errno));
- return false;
- }
+ // int buffer_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ // ret = ioctl(m_cam_fd, VIDIOC_STREAMON, &buffer_type);
+ // if (ret != 0)
+ // {
+ // DBG("ioctl(VIDIOC_STREAMON) failed %d(%s)", errno, strerror(errno));
+ // return false;
+ // }
DBG("cam init done.");
return true;
}
-bool InnoMakerOV9281::getImage(Image &image)
+// Image &InnoMakerOV9281::getImage()
+// bool InnoMakerOV9281::getImage(Image &image)
+bool InnoMakerOV9281::getImage(size_t &imageIndex)
+// TODO: get Image from video_buffer_ptr
{
static struct timeval curr, prev;
static uint16_t counter = 0;
@@ -359,17 +414,25 @@ bool InnoMakerOV9281::getImage(Image &image)
if (elapsedTime > 1000.)
{
- fprintf(stderr, "fps: %d, sec: %d\n", counter, curr.tv_sec);
fprintf(stderr,
- "sum: %d,\tcorr: %d,\tval: %d\n",
+ "fps: %d\tsec: %d\tdq: %d\tget: %d\trot: %d\tsum: %d,\tcorr: %d,\tval: %d\n",
+ counter,
+ curr.tv_sec % 1000,
+ dq_elapsed_ns / 1000 / counter,
+ get_elapsed_ns / 1000 / counter,
+ rot_elapsed_ns / 1000 / counter,
sum_elapsed_ns / 1000 / counter,
corr_elapsed_ns / 1000 / counter,
// max_elapsed_ns / 1000 / counter,
value_elapsed_ns / 1000 / counter);
+
+ dq_elapsed_ns = 0;
+ get_elapsed_ns = 0;
sum_elapsed_ns = 0;
corr_elapsed_ns = 0;
max_elapsed_ns = 0;
value_elapsed_ns = 0;
+ rot_elapsed_ns = 0;
counter = 0;
prev = curr;
@@ -383,10 +446,14 @@ bool InnoMakerOV9281::getImage(Image &image)
buffer.memory = V4L2_MEMORY_MMAP;
buffer.index = BUFFER_COUNT;
- ret = ioctl(m_cam_fd, VIDIOC_DQBUF, &buffer);
-
- if (ret != 0)
{
+ QElapsedTimer t;
+ t.start();
+ ret = ioctl(m_cam_fd, VIDIOC_DQBUF, &buffer);
+ dq_elapsed_ns += t.nsecsElapsed();
+ }
+
+ if (ret != 0) {
DBG("ioctl(VIDIOC_DQBUF) failed %d(%s)", errno, strerror(errno));
return false;
}
@@ -397,19 +464,34 @@ bool InnoMakerOV9281::getImage(Image &image)
return false;
}
+ // auto &image = video_buffer_ptr[buffer.index];
+ imageIndex = buffer.index;
+ auto &image = m_images[buffer.index];
image.height = img_height;
image.width = img_width;
// TODO: fill
// image.counters.encoderPosition = RotaryEncoder::instance()->position();
image.counters.measurementCounter = buffer.sequence;
- image.counters.timestampUs = buffer.timestamp.tv_sec * 1000 * 1000 +
- buffer.timestamp.tv_usec;
- memcpy(image.data, video_buffer_ptr[buffer.index], img_size);
+ image.counters.timestampUs = buffer.timestamp.tv_sec * 1000 * 1000 + buffer.timestamp.tv_usec;
+
+ {
+ QElapsedTimer t;
+ t.start();
+ memcpy(&image.data, video_buffer_ptr[buffer.index], img_size);
+ // std::cout << (void *) video_buffer_ptr[buffer.index] << std::endl;
+ get_elapsed_ns += t.nsecsElapsed();
+ }
+
+ static bool done{false};
+
+ if (!done) {
+ // memcpy(image.data.data(), video_buffer_ptr[buffer.index], img_size);
+ done = true;
+ }
ret = ioctl(m_cam_fd, VIDIOC_QBUF, &buffer);
- if (ret != 0)
- {
+ if (ret != 0) {
DBG("ioctl(VIDIOC_QBUF) failed %d(%s)", errno, strerror(errno));
return false;
}
diff --git a/src/camera/innomakerov9281.h b/src/camera/innomakerov9281.h
index ccfe1ac..7f2d206 100644
--- a/src/camera/innomakerov9281.h
+++ b/src/camera/innomakerov9281.h
@@ -33,7 +33,11 @@ public:
bool setLaserLevel(int value) override;
- bool getImage(Image &image);
+ bool setSomething(int value) override;
+
+ // bool getImage(Image &image);
+ bool getImage(size_t &image);
+ // Image &getImage();
public:
libcamera::Signal<std::shared_ptr<Pixels>> newPixels;
@@ -48,7 +52,12 @@ private:
private:
int m_cam_fd{-1};
static constexpr uint8_t BUFFER_COUNT{3};
+ // #ifdef USER_PTR
+ Image m_images[BUFFER_COUNT];
+ // #else
uint8_t *video_buffer_ptr[BUFFER_COUNT];
+ // #endif
// buffer_t m_buf;
std::jthread m_streamThread;
+ static inline std::jthread m_someThread;
};
diff --git a/src/camera/ov9281.cpp b/src/camera/ov9281.cpp
index 1a324e4..5b6936d 100644
--- a/src/camera/ov9281.cpp
+++ b/src/camera/ov9281.cpp
@@ -259,14 +259,14 @@ std::vector<std::shared_ptr<OV9281>> OV9281::search(
{
auto id = camera->id();
auto c = manager->get(id);
- auto ov9281 = std::shared_ptr<OV9281>(new OV9281(c));
+ // auto ov9281 = std::shared_ptr<OV9281>(new OV9281(c));
- if (!ov9281->init())
- {
- continue;
- }
+ // if (!ov9281->init())
+ // {
+ // continue;
+ // }
- result.push_back(ov9281);
+ // result.push_back(ov9281);
}
return result;
diff --git a/src/constants.h b/src/constants.h
index 4f37fe5..53e6063 100644
--- a/src/constants.h
+++ b/src/constants.h
@@ -10,7 +10,7 @@ constexpr size_t img_width = 1280;
constexpr size_t img_height = 800;
constexpr size_t img_size = img_width * img_height;
-constexpr uint32_t patternSize = 16;
+constexpr uint32_t patternSize = 10;
constexpr float hardcodedZRangeMm{175.f};
constexpr size_t calibrationTableHeight{0x4000}; // 16384
diff --git a/fuck_intel.h b/src/fuck_intel.h
index 6d9f9d5..6d9f9d5 100644
--- a/fuck_intel.h
+++ b/src/fuck_intel.h
diff --git a/genetic_algos.cpp b/src/genetic_algos.cpp
index 1962768..1962768 100644
--- a/genetic_algos.cpp
+++ b/src/genetic_algos.cpp
diff --git a/genetic_algos.h b/src/genetic_algos.h
index 8dea732..8dea732 100644
--- a/genetic_algos.h
+++ b/src/genetic_algos.h
diff --git a/httpservice.cpp b/src/httpservice.cpp
index 7fa72fb..7fa72fb 100644
--- a/httpservice.cpp
+++ b/src/httpservice.cpp
diff --git a/httpservice.h b/src/httpservice.h
index a6c3f76..a6c3f76 100644
--- a/httpservice.h
+++ b/src/httpservice.h
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;
}
diff --git a/src/image.h b/src/image.h
index 934aa40..b4e8a58 100644
--- a/src/image.h
+++ b/src/image.h
@@ -3,6 +3,8 @@
#include "constants.h"
#include "typedefs.h"
+#define USER_PTR
+
class Pixels;
// TODO: template
@@ -10,8 +12,20 @@ struct Image
{
int width{0};
int height{0};
- uint8_t data[img_height][img_width] = {{0}};
- uint8_t rotated_cw[img_width][img_height] = {{0}};
+ // uint8_t data[img_height][img_width] = {{0}};
+
+ using row_t = std::array<uint8_t, img_width>;
+ using data_t = std::array<row_t, img_height>;
+ using rotated_row_t = std::array<uint8_t, img_height>;
+ using column_t = rotated_row_t;
+ using rotated_data_t = std::array<column_t, img_width>;
+ // data_t d;
+ data_t data;
+ // data_t *data;
+ // uint8_t *data = {nullptr};
+ // uint8_t &dataAt(size_t row, size_t col);
+ // uint8_t rotated_cw[img_width][img_height] = {{0}};
+ rotated_data_t rotated_cw;
// size_t dataSize{0};
// unsigned int stride{0};
libcamera::PixelFormat pixelFormat{0};
diff --git a/imagealgos.cpp b/src/imagealgos.cpp
index 801c588..2257244 100644
--- a/imagealgos.cpp
+++ b/src/imagealgos.cpp
@@ -25,34 +25,21 @@ T median3(const T &a, const T &b, const T &c)
return max(min(a, b), min(max(a, b), c));
}
-size_t pgm_save(std::shared_ptr<Image> img, FILE *outfile, bool really_save)
+// size_t pgm_save(std::shared_ptr<Image> img, FILE *outfile, bool really_save)
+size_t pgm_save(Image *img, FILE *outfile, bool really_save)
{
std::lock_guard<std::mutex> lg(pgm_image_mtx);
- size_t n = 0;
+ size_t n{0};
- // n += fprintf(outfile, "P5\n%d %d\n%d\n",
- // img->width, img->height, 0xFF);
n += sprintf((char*)pgm_image, "P5\n%d %d\n%d\n",
img->width, img->height, 0xFF);
- // for (size_t i = 0; i < img->width * img->height; ++i)
- for (size_t i = 0; i < img_width * img_height; ++i)
- {
- uint8_t *pixels = (uint8_t *) img->data;
- // const auto p = pixels[i];
- // uint8_t value = (pixels[i] & 0xFF00) >> 8;
- uint8_t value = pixels[i];
-
- // n += fwrite(&value, 1, 1, outfile);
- memcpy((void*)(pgm_image + n), &value, sizeof(value));
- n += sizeof(value);
- }
-
+ memcpy(pgm_image + n, img->data.data(), sizeof(img->data));
+ // memcpy(pgm_image + n, img->data->data(), sizeof(img->data));
+ n += sizeof(img->data);
pgm_image_size = n;
- // std::cout << "size is " << n << std::endl;
-
if (really_save)
{
if (outfile) {
diff --git a/imagealgos.h b/src/imagealgos.h
index e443e10..4fd9d53 100644
--- a/imagealgos.h
+++ b/src/imagealgos.h
@@ -6,9 +6,8 @@
#include "image.h"
#include "pixels.h"
-size_t pgm_save(std::shared_ptr<Image> img,
- FILE *outfile = nullptr,
- bool really_save = false);
+// size_t pgm_save(std::shared_ptr<Image> img,
+size_t pgm_save(Image *img, FILE *outfile = nullptr, bool really_save = false);
// void unpack_10bit(uint8_t const *src, Image const &image, uint16_t *dest);
// void unpack_16bit(uint8_t const *src, Image const &image, uint16_t *dest);
diff --git a/macro.h b/src/macro.h
index 9bcc8e0..9bcc8e0 100644
--- a/macro.h
+++ b/src/macro.h
diff --git a/main.cpp b/src/main.cpp
index 2166b3a..d986f91 100644
--- a/main.cpp
+++ b/src/main.cpp
@@ -55,7 +55,8 @@ extern volatile int32_t positionSteps;
requested_params_t requested_params;
namespace {
-std::shared_ptr<Image> img;
+// std::shared_ptr<Image> img;
+Image *img = nullptr;
Pixels pixels;
std::vector<Pixels> calibrationPixels;
QMutex calibrationPixelsMutex;
@@ -91,17 +92,18 @@ auto printPixels = [](const auto& pixels) {
std::cout << std::endl;
};
-void onNewImage(std::shared_ptr<Image> image)
+// void onNewImage(std::shared_ptr<Image> image)
+void onNewImage(Image &image)
{
// std::cout << __func__ << std::endl << std::flush;
- if (!image)
- {
- qDebug() << __func__ << "no image";
- return;
- }
+ // if (!image)
+ // {
+ // qDebug() << __func__ << "no image";
+ // return;
+ // }
- ::img = image;
+ ::img = &image;
}
void onNewPixels(std::shared_ptr<Pixels> pixels)
@@ -172,18 +174,18 @@ int main(int argc, char* argv[])
{
initializers << QtConcurrent::run([&]() {
if (!openCalibrationTable(
- "/home/user/dumps/binz.calibration_table",
- ::calibrationTableZ))
- {
+ // "/home/user/dumps/binz.calibration_table",
+ "/tmp/binz.calibration_table",
+ ::calibrationTableZ)) {
exit(EXIT_FAILURE);
}
});
initializers << QtConcurrent::run([&]() {
if (!openCalibrationTable(
- "/home/user/dumps/binx.calibration_table",
- ::calibrationTableX))
- {
+ // "/home/user/dumps/binx.calibration_table",
+ "/tmp/binx.calibration_table",
+ ::calibrationTableX)) {
exit(EXIT_FAILURE);
}
});
@@ -354,7 +356,7 @@ int main(int argc, char* argv[])
qDebug() << "msecs before encoder:" << t.elapsed();
- RotaryEncoder encoder;
+ // RotaryEncoder encoder;
qDebug() << "msecs before camera:" << t.elapsed();
// FIXME: don't use one var for everything
@@ -393,6 +395,7 @@ int main(int argc, char* argv[])
for (auto& i : initializers)
i.waitForFinished();
+ std::cout << "loaded calibration tables" << std::endl;
if (!camera->startStream())
{
@@ -441,7 +444,7 @@ int main(int argc, char* argv[])
QJsonObject json;
json["pixels"] = pixels;
- json["encoderPosition"] = qint64{encoder.position()};
+ // json["encoderPosition"] = qint64{encoder.position()};
// FIXME: get prom pixels struct
json["measurementCounter"] = qint64{img->counters.measurementCounter};
json["timestampUs"] = qint64(img->counters.timestampUs);
diff --git a/printerclient.cpp b/src/printerclient.cpp
index 4fed38f..4fed38f 100644
--- a/printerclient.cpp
+++ b/src/printerclient.cpp
diff --git a/printerclient.h b/src/printerclient.h
index d1266dd..d1266dd 100644
--- a/printerclient.h
+++ b/src/printerclient.h
diff --git a/profile.cpp b/src/profile.cpp
index 2c7b9a9..2c7b9a9 100644
--- a/profile.cpp
+++ b/src/profile.cpp
diff --git a/profile.h b/src/profile.h
index 0e2f839..0e2f839 100644
--- a/profile.h
+++ b/src/profile.h
diff --git a/rotaryencoder.cpp b/src/rotaryencoder.cpp
index 62ca33d..62ca33d 100644
--- a/rotaryencoder.cpp
+++ b/src/rotaryencoder.cpp
diff --git a/rotaryencoder.h b/src/rotaryencoder.h
index c0c39d8..c0c39d8 100644
--- a/rotaryencoder.h
+++ b/src/rotaryencoder.h