popdeveloper / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

IplImage Create error, memery allocation problem #507

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
guys,I am newer with javacv,there is a error when i use javacv,it make me 
crazy...
here is code.
public void detect() throws IOException {
        for (int i = 0; i < 10; i++) {
            BufferedImage buff = ImageIO.read(new File("d:/wts/src.png"));
            IplImage screenImage = IplImage.createFrom(buff);//8U 4cheannel
            screenImage.copyFrom(buff);
            IplImage srcImage = IplImage.create(cvSize(buff.getWidth(), buff.getHeight()), IPL_DEPTH_8U, 1);
            cvCvtColor(screenImage, srcImage, CV_BGR2GRAY);
            IplImage tarImage = cvLoadImage("d:/wts/tar.png", CV_LOAD_IMAGE_GRAYSCALE);
/*
            Settings settings = new ObjectFinder.Settings();
            settings.setUseFLANN(true);
            settings.setRansacReprojThreshold(5);
            settings.setObjectImage(tarImage);
            ObjectFinder finder = new ObjectFinder(settings);
            double[] result = finder.find(srcImage);
*/if i comment these lines , it works well.
            srcImage.release();
            screenImage.release();
            cvReleaseImage(tarImage);
        }
    }
if I comment loop(for),just call fuctio one time,the fuction work well.but 
sometimes I must call fuction many times,and problem comes,I got java runtime 
error "EXCEPTION_ACCESS_VIOLATION (0xc0000005)",error comes when second call 
fuction or third....
once I comment some lines,it works,so I think problem is memery allocation ,if 
I don't assign srcImage,screenImage,tarImage to other variable,the fution works 
well  whatever times I call.

by the way,my version is javacv0.7 opencv2.4.8 jdk1.7.
Is there anybody have some suggustion on the problem? please

Original issue reported on code.google.com by long57...@gmail.com on 23 Aug 2015 at 4:12

GoogleCodeExporter commented 8 years ago
Please try again with version 1.0, thank you.

Original comment by samuel.a...@gmail.com on 24 Aug 2015 at 12:00

GoogleCodeExporter commented 8 years ago
samuel,thanks.
I use version 1.0,it works.The changes between 0.7 and 1.0 is so large.there is 
no fuction IplImage.createFrom(BufferedImage) or 
IplImage.copyFrom(BufferedImage) in ver1.0,but I really need the fuction create 
IplImage from BufferedImage.
In my program,source image is a screenshot saved by BufferedImage.Now I have to 
save BufferedImage to disk,and read it again with cvLoadImage().

Original comment by long57...@gmail.com on 24 Aug 2015 at 9:06

GoogleCodeExporter commented 8 years ago
Yes, it changed a lot. Details here:
http://bytedeco.org/news/2015/04/04/javacv-frame-converters/

Original comment by samuel.a...@gmail.com on 24 Aug 2015 at 11:15