这是我的代码。它不断显示这样的消息"方法getBufferedImage()对于类型opencv_core.IplImage是未定义的"。我该如何摆脱它?有没有其他方法可以获得缓冲图像??如果有人有任何想法,请尽快告诉我
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);
}
我在尝试检测Hand时也遇到了同样的问题。我发现新的openCV版本没有用于org.byteco.openCV_core.IplImage类的方法getBufferedImage()。我发现了这种方法,它为我做了工作。
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);
}
我希望这种方法能帮助你解决你的问题。