I’m trying to copy a pointers data to another pointer, so that if I change one, the value in the other doesn’t change.
I need this because I am coding a loop where I have two struct pointers, value, and lastValue. In each iteration of the loop I assign value‘s content to lastValue, and I fill value with new content. The problem is that because both are struct pointers, when I change value, lastValue changes too, and that’s not the behavior I want. The code would be something like this (the structs are IplImages from OpenCV):
IplImage *value;
Iplimage *lastValue;
while(1)
{
lastValue=value;
value=cvQueryFrame( capture );//This fills the struct with new information
}
This would work if they where normal structs, but because they are pointers, both end up with the same value. Is there a way to get a copy of a pointer, with the same value, but different address?
The function
cvQueryFramegrabs a frame from camera or video file, decompresses and returns it. It returns the pointer to internal OpenCV buffer having the last grabbed frame. That should be the reason why you get the same value. If you want 2 frames, you should create a copy of the image.