I am trying to read video frames in OpenCV, then copy the data into my another C++ code to perform something else. My code is as follows:
cv::Mat capturedFrame;
int newData[600][800];
std::cout<<"Debug1 " << std::endl;
memcpy((char*)newData, (char*)capturedFrame.data, 600*800*sizeof(int) );
std::cout<<"Debug2 " << std::endl;
mycode.setData ( newData );
std::cout<<"Debug3 " << std::endl;
Then the class “setData” was defined as follows:
char data [600][800];
void mycode::setData ( char newData[600][800] )
{
for ( int m=0; m < 600; m ++ )
{
for ( int n = 0; n < 800; n ++ )
{
data[i][j] = newData[i][j];
}
}
}
But the code stops when it comes to the line:
mycode.setData ( newData );
What confuses me is, if I delete this code, then I can see “Debug1” to “Debug3” on the screen, which is normal. But if I use this code, the program stops even without printing out “Debug1” and “Debug2” on the screen. This is really strange. I also tried to comment out all the lines in the “setData” class to make it be an empty class, but the error still is the same. So I believe it was not about the “setData” class.
I also know that the “capturedFrame.data” was correct, because I performed some other filters on it, and the result was good. Can someone explain the error here?
Edit:
I used a debugger, but there was no error message but the program just stopped responding. Also, I changed the data type into “char”.
This array:
is larger than 1 MB. If this is a local variable, then you’re likely blowing the stack.
The same may go for the
dataarray, but since your code snippets have very little context, it’s hard to know what might be statically allocated vs. automatically allocated.I think you should consider dynamically allocating these large arrays.