bitwise_or Opencv 异常
bitwise_or Opencv Exception
我正在尝试对我的图像应用骨架化,但它会在 opencvbitwise_or 函数上抛出异常
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);
bitwise_or抛出的异常是
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
代码来源:http://felix.abecassis.me/2011/09/opencv-morphological-skeleton/
您需要提供一些标量。
例如:
bitwise_or(mat1, Scalar(0,0,0,255), mat2);
在您的代码中,temp
Mat 没有任何值(因为您只创建了一个尺寸)。
尝试类似的东西:
cv::Mat temp(input.size(), CV_8UC1, cv::Scalar(0));
这将创建一个用零填充的矩阵,您可以将其用作 bitwise_or
函数的标量。
如果 input
图像不是 CV_8UC1
,我可以重现此错误。请确保 input
是 灰度 图像。
我正在尝试对我的图像应用骨架化,但它会在 opencvbitwise_or 函数上抛出异常
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);
bitwise_or抛出的异常是
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
代码来源:http://felix.abecassis.me/2011/09/opencv-morphological-skeleton/
您需要提供一些标量。 例如:
bitwise_or(mat1, Scalar(0,0,0,255), mat2);
在您的代码中,temp
Mat 没有任何值(因为您只创建了一个尺寸)。
尝试类似的东西:
cv::Mat temp(input.size(), CV_8UC1, cv::Scalar(0));
这将创建一个用零填充的矩阵,您可以将其用作 bitwise_or
函数的标量。
如果 input
图像不是 CV_8UC1
,我可以重现此错误。请确保 input
是 灰度 图像。