The doc of opencv on the distance tranform states that the input image must be "8-bit, single-channel " (CV_8UC1) and that the output image will be "32-bit floating-point, single-channel" (CV_32FC1) http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html .
It is likely that your input image is not CV_8UC1. To get one, you may use a comparison operator such as >=
, as in the sample code on the distance transform distrans.cpp ( in the source, in opencv/samples/cpp
).
Mat edge = gray >= edgeThresh;
edge
will be the input, gray
may be a grayscale image and edgeThresh
is an integer (=100).
To get a grayscale image, you may use first : How can I convert a cv::Mat to a gray scale in OpenCv?
cv::cvtColor(colorMat, gray, CV_BGR2GRAY);
Bye,