Hereunder a task that generates an OpenCV Mat.
I do it by loading the content of the buffer pointed at by CPTA_uchar in a string called buffer.
Then I cast it to void *.
This is an extra copy action that is not necessary. After all, the original buffer is already given by CPTA_uchar (constant pointer to array of unsigned char). But, I tried it in different ways, was not able to cast the CPTA_uchar to a (void *).
How can I use the pointer to the texture in the construction of the Mat-variable (CV::Mat), without having to copy the content ?
AsyncTask::DoneStatus example_task(GenericAsyncTask* task, void* data){
WindowFramework *window = (WindowFramework *) data;
PT(DisplayRegion) displayRegion = window->get_display_region_3d();
int width = displayRegion->get_pixel_width();
int height = displayRegion->get_pixel_height();
PT(Texture) tex = displayRegion->get_screenshot();
CPTA_uchar ding = tex->get_ram_image_as("BGR");
string buffer = ding.get_data();
void * c = (void *) &buffer[0];
// void * ptr = (void *) (&ding);
//void * ptr3 = (void *) ding;
Mat cv_frame = Mat(cv::Size(width, height), CV_8UC3, c);
cv::flip(cv_frame,cv_frame,0);
imshow("CV window", cv_frame);
waitKey(2000);
return AsyncTask::DS_done;
}