在javacv和opencv之间进行转换以从mat

时间:2016-01-19 08:33:58

标签: android opencv javacv

我可以在eclipse中使用opencv成功访问mean和stdDev的值。但我没有在Android中使用javacv这样做。有两个主要问题。首先,javacv不支持MatODouble。其次,不能调用“get”函数。这里的任何人都知道如何为javacv翻译这些代码。

请帮助我,我确实需要你们......

MatOfDouble mu = new MatOfDouble();
MatOfDouble sigma = new MatOfDouble();
Core.meanStdDev( detected_edges, mu, sigma);
double m = mu.get(0,0)[0];
double d = sigma.get(0,0)[0];

1 个答案:

答案 0 :(得分:1)

以下示例可能会有所帮助: ColorCalibrator.java

CvMat b = CvMat.create(referenceColors.length*3, 1);

...

CvScalar mean = new CvScalar(), stddev = new CvScalar();
cvAvgSdv(b, mean, stddev, null);

之后meanstddev可用作4元素向量(即stddev.val(0))。

关于如何从CvMat创建BufferedImage

更新#1

// To get a BufferedImage from an IplImage, or vice versa, we can chain calls to
// Java2DFrameConverter and OpenCVFrameConverter, one after the other.
Java2DFrameConverter cvt1 = new Java2DFrameConverter();
OpenCVFrameConverter.ToIplImage cvt2 = new OpenCVFrameConverter.ToIplImage();

BufferedImage img = ImageIO.read(new File(imagePath));
IplImage image1 = cvt2.convert(cvt1.convert(img));

CvMat image2 = image1.asCvMat();