2
Ranchu
84d

And now I've run into a whole another issue which is really fucking strange.

Has it ever occured that a Object in java looses all it's values after being put into an array of same type?

My problem:

[code...]

Mat[] matArray = new Mat[totalFramesOfVideo];

videoCapture.open();

Mat currentFrame = new Mat();
int frameCounter = 0;
while(videoCapture.read()) {

currentFrame = (last read frame as a Mat)

matArray[frameCounter] = currentFrame;

frameCounter++;
}

then, after filling the array and accessing elements, they lose all their object values.
Eg. Before currentFrame's dimensions were 1080*1920, but matArray[index] dimensions are suddenly 0*0.

Comments
  • 1
  • 3
    Probably because you are modifying an external variable and only putting its reference into the array?
  • 1
    Since it looks like you're using OpenCV I'm guessing the problem is that you're doing

    Mat currentFrame = new Mat();
    while(videoCapture.read()) {
    videoCapture.retrieve(currentFrame);
    matArray[frameCounter] = currentFrame;
    }

    This basically puts each new frame into the same Mat object, and then sets all items in the array to point to that object - try something like

    @highlight
    Mat currentFrame = new Mat();
    int frameCounter = 0;
    while(videoCapture.read(currentFrame))) {
    matArray[frameCounter] = currentFrame;
    currentFrame = new Mat();
    frameCounter++;
    }
  • 1
  • 1
    Thanks for all replies, it's a really dumb mistake on my side.
    I'll see if it works tomorrow.
  • 0
    @hitko Been a long time, I tried it, it worked, thanks a lot.
Add Comment