在javacv中将IplImage转换为Mat [英] Convert IplImage to Mat in javacv

查看:283
本文介绍了在javacv中将IplImage转换为Mat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助将我的IplImage转换为Mat.我想为图像计算HOGDescriptor,然后用SVM对它进行分类,但是计算"需要Mat类型.

I need help to convert my IplImage into Mat. I want to compute HOGDescriptor for my image and then classify it with SVM, but "compute" requires Mat type.

您能举一些例子说明如何在Java中将IplImage转换为Mat吗?

Can you give some example of how to convert IplImage into Mat in java ?

推荐答案

不要混淆官方此处如果您使用的是JavaCV,则无需转换IplImage即可使用HOGDescriptor,如

If you're using JavaCV, you don't need to convert your IplImage in order to use the HOGDescriptor, as you can see in the JavaCV source, the HOGDescriptor object wrapper manipulates CvArr objects :

// javacv/cpp/opencv_objdetect.java:527
public static class HOGDescriptor extends Pointer {
    public HOGDescriptor();
    ...
    public native void setSVMDetector(CvArr _svmdetector);
    ...
    public native void compute(CvArr img, FloatPointer descriptors, CvSize winStride, CvSize padding, CvPoint locations);
    public native void detect(CvArr img, CvPoint foundLocations, DoublePointer weights, double hitThreshold, CvSize winStride, CvSize padding, CvPoint searchLocations);
    public native void detect(CvArr img, CvPoint foundLocations, double hitThreshold, CvSize winStride, CvSize padding, CvPoint searchLocations);
    public native void detectMultiScale(CvArr img, CvRect foundLocations, double hitThreshold, CvSize winStride, CvSize padding, double scale, int groupThreshold);
    public native void detectMultiScale(CvArr img, CvRect foundLocations, DoublePointer foundWeights, double hitThreshold, CvSize winStride, CvSize padding, double scale, double finalThreshold, boolean useMeanshiftGrouping);
    public native void detectMultiScale(CvArr img, CvRect foundLocations, double hitThreshold, CvSize winStride, CvSize padding, double scale, double finalThreshold, boolean useMeanshiftGrouping);
    ...
};

现在,您可以在

Now, as you can see in opencv_core.java, the IplImage wrapper object extends CvArr :

// javacv/cpp/opencv_core.java:410
public static class IplImage extends CvArr {
    ...
};

因此您不必进行任何转换.

So you shouldn't have to do any conversion.

以下是使用HOGDescriptor.detectMultiScale的示例:

IplImage img = cvLoadImage("image.jpg");
CvRect foundRects = new CvRect(null);
HOGDescriptor hog = new HOGDescriptor(); 
FloatPointer svm = HOGDescriptor.getDefaultPeopleDetector();
hog.setSVMDetector(svm);
hog.detectMultiScale(img, foundRects, 0, cvSize(8,8), cvSize(32,32), 1.05, 2);

这篇关于在javacv中将IplImage转换为Mat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆