将一个Mat对象分配给另一个Mat对象会产生错误

时间:2015-10-22 06:54:10

标签: c++ java-native-interface mat opencv3.0 opencv4android

我从函数参数接收到Mat对象,当我将此对象分配给本地Mat参数时,给出了这个错误:

@IBOutlet var imageView: UIImageView!
@IBOutlet var MyImageView: UIImageView!

override func viewDidLoad() {
    super.viewDidLoad()

    // create tap gesture recognizer
    let tapGesture = UITapGestureRecognizer(target: self, action: "tapGesture:")

    // add it to the image view;
    imageView.addGestureRecognizer(tapGesture)
    // make sure imageView can be interacted with by user
    imageView.userInteractionEnabled = true        
}

func tapGesture(gesture: UIGestureRecognizer) {
    // if the tapped view is a UIImageView then set it to imageview
    if let imageView = gesture.view as? UIImageView {  // if you subclass UIImageView, then change "UIImageView" to your subclass
        // change the image on the MyImageView
        MyImageView.image = imageView.image
        // if you subclass UIImageView, then you could get the filename here.
    }
}

其中: grafty-hr-main.cpp:97

********** Crash dump: **********
Build fingerprint: 'google/hammerhead/hammerhead:6.0/MRA58K/2256973:user/release-keys'
pid: 32563, tid: 333, name: Thread-12993  >>> com.adhamenaya <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
Stack frame 10-22 09:44:20.605 14500 14500 F DEBUG   :     #00 pc 00232708  /data/app/com.adhamenaya-2/lib/arm/libGrafty.so (cv::Mat::operator=(cv::Ma
t const&)+244): Routine cv::Mat::operator=(cv::Mat const&) at D:/scryptech/ndk_project/OpenCV-android-sdk/sdk/native/jni/include/opencv2/core/mat.inl.
hpp:573
Stack frame 10-22 09:44:20.605 14500 14500 F DEBUG   :     #01 pc 0023b4ac  /data/app/com.adhamenaya-2/lib/arm/libGrafty.so (GraftySystem::setCurrentF
rame(cv::Mat&)+308): Routine GraftySystem::setCurrentFrame(cv::Mat&) at C:\Users\aenaya\git\GraftyAndroid\GraftyAndroid/jni/grafty-system-settings.cpp
:65
Stack frame 10-22 09:44:20.605 14500 14500 F DEBUG   :     #02 pc 002b3374  /data/app/com.adhamenaya-2/lib/arm/libGrafty.so (Java_com_adhamenaya_Nativ
e_runGrafty+540): Routine Java_com_adhamenaya_Native_runGrafty at C:\Users\aenaya\git\GraftyAndroid\GraftyAndroid/jni/grafty-hr-main.cpp:97 (discrimin
ator 1)
Stack frame 10-22 09:44:20.605 14500 14500 F DEBUG   :     #03 pc 0036a491  /data/app/com.adhamenaya-2/oat/arm/base.odex (offset 0x29c000) (byte[] com
.adhamenaya.Native.runGrafty(java.lang.Long)+92)
Stack frame 10-22 09:44:20.605 14500 14500 F DEBUG   :     #04 pc 00369e3d  /data/app/com.adhamenaya-2/oat/arm/base.odex (offset 0x29c000) (void com.a
dhamenaya.MainActivity$2.run()+328)
Stack frame 10-22 09:44:20.606 14500 14500 F DEBUG   :     #05 pc 729298d1  /data/dalvik-cache/arm/system@framework@boot.oat (offset 0x1eb1000)

grafty-system-settings.cpp:65

JNIEXPORT jbyteArray JNICALL Java_com_adhamenaya_Native_runGrafty(JNIEnv * env,jobject obj,jlong frame) {

    cv::Mat& inFrame = *(cv::Mat*) frame;


line 97 >>>>    gsys.setCurrentFrame(inFrame);

void GraftySystem::setCurrentFrame(cv::Mat& frame) { cv::Size2d imgRes; float resRatio; line 65 >>>>> this->nFrame = frame; } 的调用方式如下:

JNI

修改

mat.inl.hpp:573

private Mat mGray;

    public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
        mRgba = inputFrame.rgba();
        Imgproc.cvtColor(mRgba, mGray, Imgproc.COLOR_BGRA2GRAY);
        if (mRgba.empty())
            return null;
        else if (mRgba.channels() > 1)
            Imgproc.cvtColor(mRgba, mGray, Imgproc.COLOR_BGRA2GRAY);
        else
            mGray = mRgba;

        return mRgba;
    }
...
...
result = Native.runGrafty(mGray.getNativeObjAddr());

请帮助我弄清问题是什么?

0 个答案:

没有答案