Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

copying a portion of a matrix to itself

Hi, I'm working on an application that does some DSP for streaming data. OpenCV Mat seems like a pretty elegant solution for implementing a circular buffer inside a parent array. The moving window array will increment forward with each new dataRecord input as a column. When the front of the window (leading direction of motion) reaches the end of the parent matrix, I need to deep copy the window data to the start of the parent matrix. From http://docs.opencv.org/2.4/modules/core/doc/basic_structures.html#mat-copyto

The method copies the matrix data to another matrix. Before copying the data, the method invokes

m.create(this->size(), this->type);

so that the destination matrix is reallocated if needed. While m.copyTo(m); works flawlessly, the function does not handle the case of a partial overlap between the source and the destination matrices.

I'd like to do

public void wrapWindowToStart() {
            mWindowData.copyTo(mParentMatrix);
            //... extra code
        }

but based on the comments above i'm not sure if that will work. Does create() decide reallocation isn't needed and everything just works fine? For now, I'm doing something like this:

for (int i=mWindowBack; i<mwindowfront; i++)="" {="" for="" (int="" j="0;" j<mrecordlength;j++)="" {="" mgpudatabuffer.put(i-mqueuelength+mwindowlength,="" j,="" mgpudatabuffer.get(i,="" j))="" }="" }<="" p="">

copying a portion of a matrix to itself

Hi, I'm working on an application that does some DSP for streaming data. OpenCV Mat seems like a pretty elegant solution for implementing a circular buffer inside a parent array. The moving window array will increment forward with each new dataRecord input as a column. When the front of the window (leading direction of motion) reaches the end of the parent matrix, I need to deep copy the window data to the start of the parent matrix. From http://docs.opencv.org/2.4/modules/core/doc/basic_structures.html#mat-copyto

The method copies the matrix data to another matrix. Before copying the data, the method invokes

m.create(this->size(), this->type);

so that the destination matrix is reallocated if needed. While m.copyTo(m); works flawlessly, the function does not handle the case of a partial overlap between the source and the destination matrices.

I'd like to do

public void wrapWindowToStart() {
            mWindowData.copyTo(mParentMatrix);
            //... extra code
        }

but based on the comments above i'm not sure if that will work. Does create() decide reallocation isn't needed and everything just works fine? For now, I'm doing something like this:

for (int i=mWindowBack; i<mwindowfront; i++)="" {="" for="" (int="" j="0;" j<mrecordlength;j++)="" {="" mgpudatabuffer.put(i-mqueuelength+mwindowlength,="" j,="" mgpudatabuffer.get(i,="" j))="" }="" }<="" p="">

i<mWindowFront; i++) { for (int j=0; j<mRecordLength;j++) { mGpuDataBuffer.put(i-mQueueLength+mWindowLength, j, mGpuDataBuffer.get(i, j)) } }

copying a portion of a matrix to itself

Hi, I'm working on an application that does some DSP for streaming data. OpenCV Mat seems like a pretty elegant solution for implementing a circular buffer inside a parent array. The moving window array will increment forward with each new dataRecord input as a column. When the front of the window (leading direction of motion) reaches the end of the parent matrix, I need to deep copy the window data to the start of the parent matrix. From copyTo() looks good: http://docs.opencv.org/2.4/modules/core/doc/basic_structures.html#mat-copyto

The method copies the matrix data to another matrix. Before copying the data, the method invokes

m.create(this->size(), this->type);

so that the destination matrix is reallocated if needed. While m.copyTo(m); works flawlessly, the function does not handle the case of a partial overlap between the source and the destination matrices.

I'd like to douse copyTo

public void wrapWindowToStart() {
            mWindowData.copyTo(mParentMatrix);
            //... extra code
        }

but based on the comments above i'm not sure if that will work. Does create() decide reallocation isn't needed and everything just works fine? For now, I'm doing something like this:

for (int i=mWindowBack; i<mWindowFront; i++) {
    for (int j=0; j<mRecordLength;j++) {
        mGpuDataBuffer.put(i-mQueueLength+mWindowLength, j, mGpuDataBuffer.get(i, j))
    }
}