0

I am trying to save the watershed segments as image to sdcard in android.

Code tried in c++ and working fine

for (int m = 0; m < images.size(); m++) {
            //wshed = wshed*0.5 + imgGray*0.5;

            cv::Mat input_bgra;
            cv::cvtColor(images[m], input_bgra, CV_BGR2BGRA);

            // find all white pixel and set alpha value to zero:
            for (int y = 0; y < input_bgra.rows; ++y)
                for (int x = 0; x < input_bgra.cols; ++x)
                {
                    cv::Vec4b & pixel = input_bgra.at<cv::Vec4b>(y, x);
                    // if pixel is black
                    if (pixel[0] == 0 && pixel[1] == 0 && pixel[2] == 0)
                    {
                        // set alpha to zero:
                        pixel[3] = 0;
                    }
                }

            std::ostringstream name;
            name << "D:/Sathiya/res/intlayer" << m << ".png";





imwrite(name.str(), input_bgra);
        }

Not sure how to achieve this in android.

  • Expose that as a JNI interface and call that method from java. You can convert a bitmap to Mat in java (using Utils.bitmapToMat()) and pass the native address to the JNI interface. Also Remember to pass the write permission to the manifest. – Udit Mukherjee Jun 21 '17 at 11:51
  • Hi,Tried but facing an error "Error:(252, 63) error: cannot pass object of non-trivial type 'cv::Mat' through variadic method; call will abort at runtime [-Wnon-pod-varargs]" – SathiyaKrishnan Jun 21 '17 at 12:44
  • jclass clazz = env->FindClass("com/asianpaints/watershed/hellojni/MainActivity"); jmethodID mid = env->GetStaticMethodID(clazz, "fromNative", "(Ljava/lang/String;)V"); jobject obj = env->CallStaticObjectMethod(clazz, mid, input_bgra); – SathiyaKrishnan Jun 21 '17 at 12:45
  • Create the mat in java and pass it's address to ndk – Udit Mukherjee Jun 21 '17 at 13:39
  • Could you share the sample code. – SathiyaKrishnan Jun 22 '17 at 04:40

1 Answers1

0

I am trying to save watershed segments as png in java , is it straightforward to do.