I’m trying to create an circular buffer for images in C++ that receives the images as Numpy arrays. I can correctly store the images and retrieve them, but it’s crazy slow, 100’s of times slower than just doing it all in Python. I’m learning C++, but I’m not sure how to speed this up. Any help would be greatly appreciated.
void Buffer::do_nothing(py::array_t<uint8_t> &input_array, int time_code, string time_stamp) {
auto view = input_array.unchecked<3>();
if ((view.shape(0) != Buffer::frame_height) || (view.shape(1) != Buffer::frame_width) || (view.shape(2) != 3)) {
cout << "Error: Incorrect incoming array sizen";
exit(1);
}
const int channels = view.shape(2);
const int height = view.shape(0);
const int width = view.shape(1);
int t;
for (int i = 0; i < channels; i++) {
for (int j = 0; j < height; j++) {
for (int k = 0; k < width; k++) {
Buffer::frames[(Buffer::high * Buffer::frame_size) + (Buffer::channel_size * i) + (j * Buffer::frame_width) + k] = view(j, k, i);
}
}
}
}
Buffer::frames is an array initialized by:
Buffer::frames = new uint8_t[circ_buffer_size * frame_height * frame_width * 3];