Skip to content

Instantly share code, notes, and snippets.

@vrunoa
Last active June 3, 2016 21:42

Revisions

  1. vrunoa renamed this gist Jun 1, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. vrunoa created this gist Jun 1, 2016.
    29 changes: 29 additions & 0 deletions jni.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    // trying to convert Luv image to BGR

    JNIEXPORT jboolean JNICALL Java_com_test_run(JNIEnv* env, jobject thiz, jlong data) {

    __android_log_write(ANDROID_LOG_INFO, "TEST", "run");
    if(data == 0) {
    __android_log_write(ANDROID_LOG_ERROR, "TEST", "empty jlong mat");
    return false;
    }

    cv::Mat frame = *((cv::Mat*)data);
    if(frame.empty()) {
    return false;
    }

    cv::Mat bgr = cv::Mat(frame.rows, frame.cols);
    cv::cvtColor(frame, bgr, cv::COLOR_Luv2BGR);

    cv::Mat rotated;
    cv::Point2f center(frame.cols/2.0F, frame.rows/2.0F);
    cv::Mat rot = getRotationMatrix2D(center, 90, 1.0);
    cv::warpAffine(frame, rotated, rot, frame.size());

    return doCollStuff(rotated.data);
    }

    /* throws this error
    * 05-31 21:02:23.021 22356-22854/? E/cv::error(): OpenCV Error: Assertion failed (scn == 3 && (dcn == 3 || dcn == 4) && (depth == CV_8U || depth == CV_32F)) in void cv::cvtColor(cv::InputArray, cv::OutputArray, int, int), file /builds/master_pack-android/opencv/modules/imgproc/src/color.cpp, line 8291
    */