How to convert Mat to IplImage in Javacv?

1.1k views Asked by At

Is any one know how i can convert Mat to IplImage ? to achieve this i have converted Mat to BufferedImage but again not able to find conversion in BufferedImage to IplImage.

is there any way where i can convert Mat to IplImage?

Thanks

1

There are 1 answers

3
Rajind Ruparathna On

I believe you can convert BufferedImage to IplImage as follows.

public static IplImage toIplImage(BufferedImage src) {
  Java2DFrameConverter bimConverter = new Java2DFrameConverter();
  OpenCVFrameConverter.ToIplImage iplConverter = new OpenCVFrameConverter.ToIplImage();
  Frame frame = bimConverter.convert(src);
  IplImage img = iplConverter.convert(frame);
  IplImage result = img.clone();
  img.release();
  return result;
}

I got this from this question. Try this for now. I'll check if direct conversion is possible.

UPDATE: Please have a look at this api docs. I haven't tested the following. Wrote it just now. Please do try and let me know.

public static IplImage toIplImage(Mat src) {
 OpenCVFrameConverter.ToIplImage iplConverter = new OpenCVFrameConverter.ToIplImage();
 OpenCVFrameConverter.ToMat  matConverter = new OpenCVFrameConverter.ToMat();
 Frame frame =  matConverter.convert(src);
 IplImage img = iplConverter.convert(frame);
 IplImage result = img.clone();
 img.release();
 return result;
}