美文网首页
将Opencv java中的Mat通过JNI传递到C++

将Opencv java中的Mat通过JNI传递到C++

作者: su945 | 来源:发表于2020-05-22 17:50 被阅读0次
    • 示例
    //java层
    public native void FindFeatures(long matAddrGr, long matAddrRgba);
    ...
            mRgba = new Mat(height, width, CvType.CV_8UC4);
            mGray = new Mat(height, width, CvType.CV_8UC1);
    
            mRgba = inputFrame.rgba();
            mGray = inputFrame.gray();
    
            FindFeatures(mGray.getNativeObjAddr(), mRgba.getNativeObjAddr());
    ...
    //jni层
    extern "C" {
    JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial2_Tutorial2Activity_FindFeatures(JNIEnv*, jobject, jlong addrGray, jlong addrRgba);
    
    JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial2_Tutorial2Activity_FindFeatures(JNIEnv*, jobject, jlong addrGray, jlong addrRgba)
    {
        Mat& mGr  = *(Mat*)addrGray;
        Mat& mRgb = *(Mat*)addrRgba;
        vector<KeyPoint> v;
    
        Ptr<FeatureDetector> detector = FastFeatureDetector::create(50);
        detector->detect(mGr, v);
        for( unsigned int i = 0; i < v.size(); i++ )
        {
            const KeyPoint& kp = v[i];
            circle(mRgb, Point(kp.pt.x, kp.pt.y), 10, Scalar(255,0,0,255));
        }
    }
    }
    

    相关文章

      网友评论

          本文标题:将Opencv java中的Mat通过JNI传递到C++

          本文链接:https://www.haomeiwen.com/subject/qhlcahtx.html