Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV4Android - Otsu's Method: Error

What I'm trying to do is this.

Imgproc.threshold(image, image, 0, 255, Imgproc.THRESH_BINARY+Imgproc.THRESH_OTSU);

OpenCV4Android - Otsu's Method: Error

What I'm trying to do is this.

Imgproc.threshold(image, image, 0, 255, Imgproc.THRESH_BINARY+Imgproc.THRESH_OTSU);

I have been looking around and I see various recommendations on what to put in for the threshold and max value. I can do a standard Binary Threshold so I'm assuming it's something specific with Otsu's method that I've misunderstood.

Error

OpenCV Error: Assertion failed (src.type() == CV_8UC1) in double cv::threshold(cv::InputArray, cv::OutputArray, double, double, int), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/thresh.cpp, line 719
imgproc::threshold_10() caught cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/thresh.cpp:719: error: (-215) src.type() == CV_8UC1 in function double cv::threshold(cv::InputArray, cv::OutputArray, double, double, int)

OpenCV4Android - Otsu's Method: Error

What I'm trying to do is this.

Imgproc.threshold(image, image, 0, 255, Imgproc.THRESH_BINARY+Imgproc.THRESH_OTSU);

I have been looking around and I see various recommendations on what to put in for the threshold and max value. I can do a standard Binary Threshold so I'm assuming it's something specific with Otsu's method that I've misunderstood.

Error

OpenCV Error: Assertion failed (src.type() == CV_8UC1) in double cv::threshold(cv::InputArray, cv::OutputArray, double, double, int), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/thresh.cpp, line 719
imgproc::threshold_10() caught cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/thresh.cpp:719: error: (-215) src.type() == CV_8UC1 in function double cv::threshold(cv::InputArray, cv::OutputArray, double, double, int)

EDIT: So I checked my image type and it's coming back with type 24. I attempt to convert it to 8UC1 and I still get an error.

New Code.

if (image.type() == CvType.CV_8UC1)
        {
            Imgproc.threshold(image, image, 0, 255, Imgproc.THRESH_BINARY+Imgproc.THRESH_OTSU);

            return image;
        }
        else
        {
            Log.v(TAG, "Cannot Threshold: Wrong Image Type: " + image.type() + " Converting to CV_8UC1");

            Mat convertedTo8UC1 = new Mat(); 

            image.convertTo(convertedTo8UC1, CvType.CV_8UC1);

            Imgproc.threshold(convertedTo8UC1, convertedTo8UC1, 0, 255, Imgproc.THRESH_BINARY+Imgproc.THRESH_OTSU);

            return convertedTo8UC1;
        }

New Error

OpenCV Error: Assertion failed (src.type() == CV_8UC1) in double cv::threshold(cv::InputArray, cv::OutputArray, double, double, int), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/thresh.cpp, line 719
imgproc::threshold_10() caught cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/thresh.cpp:719: error: (-215) src.type() == CV_8UC1 in function double cv::threshold(cv::InputArray, cv::OutputArray, double, double, int)

OpenCV4Android - Otsu's Method: Error

What I'm trying to do is this.

Imgproc.threshold(image, image, 0, 255, Imgproc.THRESH_BINARY+Imgproc.THRESH_OTSU);

I have been looking around and I see various recommendations on what to put in for the threshold and max value. I can do a standard Binary Threshold so I'm assuming it's something specific with Otsu's method that I've misunderstood.

Error

OpenCV Error: Assertion failed (src.type() == CV_8UC1) in double cv::threshold(cv::InputArray, cv::OutputArray, double, double, int), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/thresh.cpp, line 719
imgproc::threshold_10() caught cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/thresh.cpp:719: error: (-215) src.type() == CV_8UC1 in function double cv::threshold(cv::InputArray, cv::OutputArray, double, double, int)

EDIT: So I checked my image type and it's coming back with type 24. I attempt to convert it to 8UC1 and I still get an the same error.

New Code.

if (image.type() == CvType.CV_8UC1)
        {
            Imgproc.threshold(image, image, 0, 255, Imgproc.THRESH_BINARY+Imgproc.THRESH_OTSU);

            return image;
        }
        else
        {
            Log.v(TAG, "Cannot Threshold: Wrong Image Type: " + image.type() + " Converting to CV_8UC1");

            Mat convertedTo8UC1 = new Mat(); 

            image.convertTo(convertedTo8UC1, CvType.CV_8UC1);

            Imgproc.threshold(convertedTo8UC1, convertedTo8UC1, 0, 255, Imgproc.THRESH_BINARY+Imgproc.THRESH_OTSU);

            return convertedTo8UC1;
        }

New Error

OpenCV Error: Assertion failed (src.type() == CV_8UC1) in double cv::threshold(cv::InputArray, cv::OutputArray, double, double, int), file /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/thresh.cpp, line 719
imgproc::threshold_10() caught cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/thresh.cpp:719: error: (-215) src.type() == CV_8UC1 in function double cv::threshold(cv::InputArray, cv::OutputArray, double, double, int)