NativeMethod(long NativeMatAddress);
JNIEXPORT void ... (JNIENV* env, jobject thiz, jlong addrNativeMat) { ...
... Mat* mat = (Mat*) addrNativeMat; ...
Hey,
I'm currently trying to copy a matrix in native code via memcpy.
Because my code crashes, I searched the web and found this:
https://code.ros.org/trac/opencv/browser/branches/android-experimental/opencv/android/android-opencv/jni/image_pool.cpp?rev=4700
In line 118 it says:
void copyMatToBuffer(char* buffer, const cv::Mat& mat)
{
memcpy(buffer, mat.data, mat.rows * mat.cols * mat.step1());
}
But seems wrong to me! The memory length of one mat is mat.rows*mat.step().
Since the method does not seem to be used anywhere, this is not a big deal but if it's really wrong it should probably be changed.
Have I found a bug and if yes could you forward it to the developers?
P.S.: How do I copy the content of one mat into a char* buffer?
both
1) memcpy(buffer, mat.data, mat.rows * mat.cols * mat.step1());
2) memcpy(buffer, mat.data, mat.rows*mat.step());
are not working and I get a memory access error
Hey,
I'm currently trying to copy a matrix in native code via memcpy.
Because my code crashes, I searched the web and found this:
https://code.ros.org/trac/opencv/browser/branches/android-experimental/opencv/android/android-opencv/jni/image_pool.cpp?rev=4700
In line 118 it says:
void copyMatToBuffer(char* buffer, const cv::Mat& mat)
{
memcpy(buffer, mat.data, mat.rows * mat.cols * mat.step1());
}
But seems wrong to me! The memory length of one mat is mat.rows*mat.step().
Since the method does not seem to be used anywhere, this is not a big deal but if it's really wrong it should probably be changed.
Have I found a bug and if yes could you forward it to the developers?
P.S.: How do I copy the content of one mat into a char* buffer?
both
1) memcpy(buffer, mat.data, mat.rows * mat.cols * mat.step1());
2) memcpy(buffer, mat.data, mat.rows*mat.step());
are not working and I get a memory access error
Hey,
I'm currently trying to copy a matrix in native code via memcpy.
Because my code crashes, I searched the web and found this:
https://code.ros.org/trac/opencv/browser/branches/android-experimental/opencv/android/android-opencv/jni/image_pool.cpp?rev=4700
In line 118 it says:
void copyMatToBuffer(char* buffer, const cv::Mat& mat)
{
memcpy(buffer, mat.data, mat.rows * mat.cols * mat.step1());
}
But seems wrong to me! The memory length of one mat is mat.rows*mat.step().
Since the method does not seem to be used anywhere, this is not a big deal but if it's really wrong it should probably be changed.
Have I found a bug and if yes could you forward it to the developers?
P.S.: How do I copy the content of one mat into a char* buffer?
both
1) memcpy(buffer, mat.data, mat.rows * mat.cols * mat.step1());
2) memcpy(buffer, mat.data, mat.rows*mat.step());
are not working and I get a memory access error
Hey,
I'm currently trying to copy a matrix in native code via memcpy.
Because my code crashes, I searched the web and found this:
https://code.ros.org/trac/opencv/browser/branches/android-experimental/opencv/android/android-opencv/jni/image_pool.cpp?rev=4700
In line 118 it says:
void copyMatToBuffer(char* buffer, const cv::Mat& mat)
{
memcpy(buffer, mat.data, mat.rows * mat.cols * mat.step1());
}
But seems wrong to me! The memory length of one mat is mat.rows*mat.step().
Since the method does not seem to be used anywhere, this is not a big deal but if it's really wrong it should probably be changed.
Have I found a bug and if yes could you forward it to the developers?
P.S.: How do I copy the content of one mat into a char* buffer?
both
1) memcpy(buffer, mat.data, mat.rows * mat.cols * mat.step1());
2) memcpy(buffer, mat.data, mat.rows*mat.step());
are not working and I get a memory access error
Mat* mat = (Mat*) addrNativeMat;
int size = mat.rows*mat.step();
unsigned char datagram[10+size];
//... leaving out code
unsigned char *ptr = &datagram[10];
memcpy(&ptr, mat.data, size); //This line fails and I don't know why
in size = mat->rows * mat->step() ...
int size = (*mat).rows * (*mat).step() ...
What I am trying to do is not exactly android specific - I posted this message here because the mistake I found was in (as Rui said: old) android code.
Anyhow: If I had used
Mat* mat = (Mat*) addrNativeMat;
void aMethod(cv::Mat *mat) {
int size = mat->rows*mat->step;
unsigned char datagram[10+size];
//... leaving out code
unsigned char *ptr = &datagram[10];
memcpy(&ptr, mat->data, size); //This line fails and I don't know why
}
memcpy(ptr, mat->data, size);
mat->isContinuous() == true