I’m trying to copy a MAT image loaded in from a file to a specific address location. I have the following code
cv::Mat inImg = cv::imread("M6_traffic.jpg");
//Data point copy
unsigned char * pData = (unsigned char *)inImg.data;
unsigned char * Dest = (unsigned char *)0x0f000000;;
int width = inImg.rows;
int height = inImg.cols;
//data copy using memcpy function
memcpy(Dest, pData, sizeof(unsigned char)*width*height*3);
But when I run this it always crashes, any idea why? and is there a better why to do this? My end goal is to able to copy a image data to specific address in a Linux based system
propably there is no allocated memory on address 0x0f000000.
and you cannot force this to be a valid address
Allocate the right size of memory with malloc and it will work.
The OS then determines your address space and returns a pointer to it.
unsigned char* Dest = malloc(sizeof(pData));
memcpy(Dest, pData, sizeof(pData))
0x0f000000 is essentially a null pointer. What you’re trying to do is copy data into a memory address that has not been set with
memcpy(Dest, pData, sizeof(unsigned char)*width*height*3);.
You should allocate memory for
Dest before your
memcpy statement. You can do this with either
calloc. These function calls are described in the following links. Hope this helps!