Comments (5)
You don't need to release it, just clear it with cvClearMemStorage() on every
iteration
Can you try to use it in the same way as in the Test2 sample provided in the
README.txt file?
Original comment by [email protected]
on 15 Jan 2011 at 1:39
from javacv.
Thanks for your reply. I already tried creating the memory store only once at
the start of the program and then calling cvClearMemStorage after each
iteration (as shown in Test2 from the README.txt file). The behaviour that I
see is the same as in my memoryLeakExample above. i.e. The time per iteration
remains constant but the memory taken by the process gradually increases...
I have created a stand alone test that doesn't rely on any external images to
illustrate this. I would be grateful if you could have a look.
I have also tried checking running it against the latest JavaCV code from the
SVN and I see the same behaviour. I am using the recommended version of JNA
(3.2.7).
Any help would be gratefully received.
import static com.googlecode.javacv.jna.cv.CV_HOUGH_STANDARD;
import static com.googlecode.javacv.jna.cv.cvCanny;
import static com.googlecode.javacv.jna.cv.cvHoughLines2;
import static com.googlecode.javacv.jna.cxcore.cvClearMemStorage;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import com.googlecode.javacv.JavaCvErrorCallback;
import com.googlecode.javacv.jna.cxcore.CvMemStorage;
import com.googlecode.javacv.jna.cxcore.CvSeq;
import com.googlecode.javacv.jna.cxcore.IplImage;
public class MemoryTest {
// class to test creating and releasing images from JavaCV
public static void main(String[] args) throws IOException,
InterruptedException {
new JavaCvErrorCallback().redirectError();
// create a random image
IplImage image = createRandomImage();
IplImage edge = IplImage.create(image.width, image.height, image.depth,
image.nChannels);
cvCanny(image, edge, 1000, 1200, 3);
CvMemStorage storage = CvMemStorage.create();
long totalTime = 0;
int iteration = 0;
while (true) {
iteration++;
// carry out the hough lines and store the time taken
long start = System.currentTimeMillis();
CvSeq hough = cvHoughLines2(edge, storage.getPointer(),
CV_HOUGH_STANDARD, 1, Math.PI / 360, 1000, 20, 40);
long end = System.currentTimeMillis();
long time = end - start;
totalTime += time;
cvClearMemStorage(storage);
if (iteration % 1000 == 0) {
System.out.println(iteration + " mean time per iteration "
+ (totalTime / 1000));
System.gc();
Thread.sleep(500);
totalTime = 0;
}
}
}
public static IplImage createRandomImage() {
int width = 100;
int height = 100;
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_BYTE_GRAY);
Graphics g = image.getGraphics();
for (int i = 0; i < 50; i++) {
int x = (int) (width * Math.random());
int y = (int) (height * Math.random());
int x2 = (int) (width * Math.random());
int y2 = (int) (height * Math.random());
g.drawLine(x, y, x2, y2);
}
return IplImage.createFrom(image);
}
}
Original comment by [email protected]
on 15 Jan 2011 at 4:33
from javacv.
There is a possibility that OpenCV itself is leaking memory.. Have you tried
something similar in C/C++ to make sure? I get lots of hit on Google search
about cvHoughLines2 and memory leaks..
Original comment by [email protected]
on 16 Jan 2011 at 1:54
from javacv.
I managed to fix the code. I am not sure why this work, but if I called
cvClearMemStorage on the storage attribute *within* the CvSeq rather than the
CvMemStorage itself there is no slowdown and no memory leak. To illustrate
this, in the above example, I simply replaced:
cvClearMemStorage(storage);
with
cvClearMemStorage(hough.storage);
to solve the problem....
Original comment by [email protected]
on 16 Jan 2011 at 1:30
from javacv.
Ah, looks like there is a bug in OpenCV. cvHoughLines2() must ignore the
storage given as argument and always creates its own. Good to know, thanks for
reporting
Original comment by [email protected]
on 16 Jan 2011 at 1:42
- Changed state: Done
from javacv.
Related Issues (20)
- av_interleaved_write_frame() error -22 while writing interleaved video frame HOT 3
- Android video record using H264 format is to large HOT 1
- Error while createFisher/Eigen/LBPHFaceRecognizer() method is called. HOT 7
- FFmpegFrameGrabber doesn't grab upto the end of the video on Android HOT 6
- RTMP streaming problems HOT 1
- Unable to record with sample code on HOT 4
- Question about the applying the proguard on android HOT 2
- CODEC_ID_MPEG1VIDEO,PIX_FMT_YUV420P cannot be resolved to a variable HOT 4
- While using OpenCV 2.4.9 and JavaCV 0.7 in netbeans windows 7 getting error HOT 3
- Help me Dr.Samuel..(Fatal signal 8 (SIGFPE) at 0x00002835 (code=-6), thread 10293 ) HOT 4
- multi processing with opencv HOT 2
- Problem on train method in face recognition HOT 1
- how to rotate video with javacv on android HOT 1
- Caused by: java.lang.UnsatisfiedLinkError: Couldn't load opencv_core from loader dalvik.system.PathClassLoader HOT 1
- .mp4 video not working in splash screen in htc desire 500 HOT 1
- How to grab the RGB frame instead the gray one? HOT 2
- reconstructImageToNewType Method not Found HOT 1
- JavaCV 0.11 getLengthInFrames() HOT 3
- How to apply sepia effect on grabed frame before record it HOT 2
- IplImage Create error, memery allocation problem HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javacv.