1 | initial version |
Mat::create
method checks Mat's size and reallocate data only if requested size or type differs from existed. So, if you call create
twice with the same size and type it won't reallocate data. All OpenCV functions works in the same way. You can declare Mat
object outside processing loop and it will be allocated only once, if all input frames have the same size:
VideoCapture cap;
Mat src;
mat gray;
Mat edges;
for(;;)
{
// all following functions will allocate memory only once on first iteration
cap >> src;
cvtColor(src, gray, COLOR_BGR2GRAY);
Canny(gray, edges, 50, 100);
}
2 | No.2 Revision |
Mat::create
method checks Mat's size and reallocate data only if requested size or type differs from existed. So, if you call create
twice with the same size and type it won't reallocate data. All OpenCV functions works in the same way. You can declare Mat
object outside of processing loop and it will be allocated only once, if all input frames have the same size:
VideoCapture cap;
Mat src;
mat >Mat gray;
Mat edges;
for(;;)
{
// all following functions will allocate memory only once on first iteration
cap >> src;
cvtColor(src, gray, COLOR_BGR2GRAY);
Canny(gray, edges, 50, 100);
}
3 | No.3 Revision |
Mat::create
method checks Mat's size and reallocate data only if requested size or type differs from existed. So, if you call create
twice with the same size and type it won't reallocate data. All OpenCV functions works in the same way. You can declare Mat
object outside of processing loop and it will be allocated only once, if all input frames have the same size:
VideoCapture cap;
Mat src;
>Mat Mat gray;
Mat edges;
for(;;)
{
// all following functions will allocate memory only once on first iteration
cap >> src;
cvtColor(src, gray, COLOR_BGR2GRAY);
Canny(gray, edges, 50, 100);
}