How to remove this Error "The method getBufferedImage() is undefined for the type opencv_core.IplImage"

1k views Asked by At

Here is my code. It keeps on showing this message "The method getBufferedImage() is undefined for the type opencv_core.IplImage". How can I get rid of it? Is there any alternative way of getting the buffered image?? If anyone have any idea please tell me as soon as possible

public IplImage snapIm = null;
public Rectangle faceRect;
public void paintComponent(Graphics g){ 
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;

        if (snapIm != null)
            g2.drawImage(snapIm.getBufferedImage(), 0, 0, this); //This Line is causing problem

        drawRect(g2);
        writeStats(g2);
        writeName(g2);
}
public void recogFace(IplImage img)
{
    BufferedImage clipIm = null;
    synchronized(faceRect) {
        if (faceRect.width == 0) {
            System.out.println("No face selected");
            return;
        }
        clipIm = ImageUtils.clipToRectangle(img.getBufferedImage(),faceRect.x, faceRect.y, faceRect.width, faceRect.height); //This Line is causing problem
    }
    if (clipIm != null) 
    matchClip(clipIm);
}
1

There are 1 answers

0
chandan sr On

I also had the same problem when I was trying to detect Hand. I found out that the new openCV version had no method getBufferedImage() for org.bytedeco.opencv_core.IplImage class. I found this method which did the work for me.

public static BufferedImage IplImageToBufferedImage(IplImage src) {
    OpenCVFrameConverter.ToIplImage grabberConverter = new OpenCVFrameConverter.ToIplImage();
    Java2DFrameConverter paintConverter = new Java2DFrameConverter();
    Frame frame = grabberConverter.convert(src);
    return paintConverter.getBufferedImage(frame,1);
}

I hope this method will help you to solve your problem.