Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

hard to spot, if you don't know it, but easy to explain, i hope ;)

this line:

 frm_test[cnt] = frame;

does a shallow copy ( frm_test[cnt] points to the same data as frame)

and since Mat frame is defined outside the for loop, cap.read(frame) will not allocate new data for it.

so indeed, all items in your frm_test array will point to the same image !

the remedy is, to move the frame definition inside the for loop, like this:

for (;;)
{
    Mat frame;
    // wait for a new frame from camera and store it into 'frame'
    cap.read(frame);
    ...

so a new Mat will be allocated for each frame

hard to spot, if you don't know it, but easy to explain, i hope ;)

this line:

 frm_test[cnt] = frame;

does a shallow copy ( frm_test[cnt] points to the same data as frame)

and since Mat frame is defined outside the for loop, cap.read(frame) will not allocate new data for it.

so indeed, all items in your frm_test array will point to the same image !

the remedy is, is either, to move the frame definition inside the for loop, like this:

for (;;)
{
    Mat frame;
    // wait for a new frame from camera and store it into 'frame'
    cap.read(frame);
    ...

so a new Mat will be allocated for each frame

or to use deep copies:

 frm_test[cnt] = frame.clone();