Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Efficient way to rotate #70

Closed
cangelis opened this issue Dec 17, 2014 · 1 comment
Closed

Efficient way to rotate #70

cangelis opened this issue Dec 17, 2014 · 1 comment
Labels

Comments

@cangelis
Copy link

I crop and rotate the IplImage using this way on Android but rotate() consumes much memory and application stops immediately after about 140 frames with an insufficient memory exception:

Frame frame;
        while ( (frame = grabber.grabFrame()) != null ) {
            if (frame.image == null) {
                recordAudio(frame, timeRange);
                continue;
            }
            recordVideo(frame.image, timeRange, rotation);
            Log.d("VideoPlugin", "Record: " + grabber.getFrameNumber());
        }
public void recordVideo(IplImage frame, Long[] timeLimit, Integer rotation) throws org.bytedeco.javacv.FrameRecorder.Exception, IllegalArgumentException {
        if ((grabber.getTimestamp() >= timeLimit[0]) && (grabber.getTimestamp() <= timeLimit[1])) {
            recorder.record(crop(rotate(frame, rotation)));
        }
    }

rotate:

    public IplImage rotate(IplImage src, int angle) {
        IplImage img = IplImage.create(src.height(), src.width(), src.depth(), src.nChannels());
        opencv_core.cvTranspose(src, img);
        opencv_core.cvFlip(img, img, angle);
        return img;
    }

When I remove rotate() from recorder.record() it works fine. I think something is wrong with this rotate() method. Anyway to make this more efficient? or Is something wrong with JavaCV or OpenCV?

this code works fine:

    public void recordVideo(IplImage frame, Long[] timeLimit, Integer rotation) throws org.bytedeco.javacv.FrameRecorder.Exception, IllegalArgumentException {
        if ((grabber.getTimestamp() >= timeLimit[0]) && (grabber.getTimestamp() <= timeLimit[1])) {
            recorder.record(crop(frame));
        }
    }
@cangelis
Copy link
Author

called cvReleaseImage() after the record() and the problem is resolved. The code for the further needs:

public void recordVideo(IplImage frame, Long[] timeLimit, Integer rotation) {
        if ((grabber.getTimestamp() >= timeLimit[0]) && (grabber.getTimestamp() <= timeLimit[1])) {
            IplImage rotated = rotate(frame, rotation);
            IplImage cropped = crop(rotated);
            recorder.record(cropped);
            opencv_core.cvReleaseImage(rotated);
            opencv_core.cvReleaseImage(cropped);
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants