I will throw a stone into the lake and watch the ripples. Note. I have no idea what the waiting subscriber should do with the converted data, mainly because of my inexperienced knowledge of OpenCV. However, the basic issue of transformation seemed pretty straightforward. If I leave the database, please leave a comment, and I will drop the answer. I propose two approaches: one for inverting data in place and one for simple appaporization using the C ++ class.
Inversion in place . If the caller needs to invert the strings to use for transferring to the API, this can be done locally. Just be sure to do it again as soon as you finish using inverted data. An example of a purely byte oriented is:
// in-place inversion of the linear matrix to re-origin. void mat_invert(float *data, size_t height, size_t width) { // must be at least 2 rows high for this to mean anything. if (height < 2) return; // setup a pair of pointers to walk the rows in byte-form unsigned char* top = (unsigned char*)data; unsigned char *bottom = (unsigned char *)(data + (height-1)*width); size_t row_width = sizeof(data[0]) * width; while (top < bottom) { for (size_t i=0; i<row_width; i++) { *top ^= *bottom; *bottom ^= *top; *top++ ^= *bottom++; } bottom -= 2*row_width; } }
Using an example:
int main(int argc, char *argv[]) { const size_t w = 10; const size_t h = 5; float ar[h*w]; memset(ar, 0, sizeof(ar)); ar[0] = 0.1; ar[1*w + 1] = 1.1; ar[2*w + 2] = 2.1; ar[3*w + 3] = 3.1; ar[4*w + 4] = 4.1; // dump original for (size_t i=0; i<h; i++) { for (size_t j=0; j<w; j++) cout << ar[i*w+j] << ' '; cout << endl; } cout << endl; // invert original mat_invert(ar, h, w); for (size_t i=0; i<h; i++) { for (size_t j=0; j<w; j++) cout << ar[i*w+j] << ' '; cout << endl; } cout << endl; // invert again mat_invert(ar, h, w); for (size_t i=0; i<h; i++) { for (size_t j=0; j<w; j++) cout << ar[i*w+j] << ' '; cout << endl; } cout << endl; return EXIT_SUCCESS; }
Results:
0.1 0 0 0 0 0 0 0 0 0 0 1.1 0 0 0 0 0 0 0 0 0 0 2.1 0 0 0 0 0 0 0 0 0 0 3.1 0 0 0 0 0 0 0 0 0 0 4.1 0 0 0 0 0 0 0 0 0 4.1 0 0 0 0 0 0 0 0 3.1 0 0 0 0 0 0 0 0 2.1 0 0 0 0 0 0 0 0 1.1 0 0 0 0 0 0 0 0 0.1 0 0 0 0 0 0 0 0 0 0.1 0 0 0 0 0 0 0 0 0 0 1.1 0 0 0 0 0 0 0 0 0 0 2.1 0 0 0 0 0 0 0 0 0 0 3.1 0 0 0 0 0 0 0 0 0 0 4.1 0 0 0 0 0
Implicit access class . If you need a virtualized mathematical line / height made for you, it will be enough to do the following:
#include <iostream> #include <exception> #include <stdexcept> using namespace std; class matrix_xform { private: size_t width, height; float *data; public: matrix_xform(float *data, size_t height, size_t width) : data(data), width(width), height(height) { } float * operator[](size_t x) { if (x > (height-1)) throw std::out_of_range("matrix_xform[x]"); return data + (width * (height - 1 - x)); } const float * operator[](size_t x) const { if (x > (height-1)) throw std::out_of_range("matrix_xform[x]"); return data + (width * (height - 1 - x)); } };
Using an example:
int main(int argc, char *argv[]) { const size_t w = 10; const size_t h = 5; float ar[h*w]; memset(ar, 0, sizeof(ar)); matrix_xform mat(ar, h, w); mat[0][0] = 1.0; mat[1][1] = 1.0; mat[2][2] = 1.0; mat[3][3] = 1.0; mat[4][4] = 1.0;
Results:
0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
I hope it covers every base the OP is looking for.