Malik Faiq
Malik Faiq

Reputation: 442

bitwise_or Opencv Exception

I am trying to applying skeletonization on my image but it throws exception on bitwise_or function of opencv

    cv::threshold(input, input, 127, 255, cv::THRESH_BINARY);
    cv::Mat skel(input.size(), CV_8UC1, cv::Scalar(0));
    cv::Mat temp(input.size(), CV_8UC1);
    cv::Mat element = cv::getStructuringElement(cv::MORPH_CROSS, cv::Size(3, 3));
    bool done;
    do
    {
        cv::morphologyEx(input, temp, cv::MORPH_OPEN, element);
        cv::bitwise_not(temp, temp);
        cv::bitwise_and(input, temp, temp);
        cv::bitwise_or(skel, temp, skel);
        cv::erode(input, input, element);

        double max;
        cv::minMaxLoc(input, 0, &max);
        done = (max == 0);
    } while (!done);

The exception bitwise_or throws is

C:\builds\master_PackSlave-win32-vc12-static\opencv\modules\core\src\arithm.cpp:1573: error: (-209) The operation is neither 'array op array' (where arrays have the same size and type), nor 'array op scalar', nor 'scalar op array' in function cv::binary_op

Source of Code :http://felix.abecassis.me/2011/09/opencv-morphological-skeleton/

Upvotes: 1

Views: 1771

Answers (2)

Miki
Miki

Reputation: 41765

I can reproduce this error if the input image is not a CV_8UC1. Please be sure that input is a grayscale image.

Upvotes: 1

Flocke
Flocke

Reputation: 1025

You need to provide some scalar. For example:

bitwise_or(mat1, Scalar(0,0,0,255), mat2);

In your code the temp Mat has no values in it (because you only created it with a size). Try something like:

cv::Mat temp(input.size(), CV_8UC1, cv::Scalar(0));

This will create a matrix filled with zeros, which you can use as a scalar for the bitwise_or function.

Upvotes: 0

Related Questions