I cannot successfully calculate the distance transformation using OpenCV (2.3) on an ubuntu. The output is either black or a copy of the orignial image, but never as expected an greyscale image with gradients.
My code:
Mat input(Size(100,100), CV_8UC1);
circle(input, Point(50,50), 10 Scalar(255,255,255), 15, 0, 0));
Mat output(Size(100,100), CV_32FC1);
distanceTransformation(input, output, CV_DIST_L2, CV_DIST_MASK_3); //Output is completely black
//distanceTransformation(input, output, CV_DIST_L2, CV_DIST_MASK_PRECISE); //Output is a "copy" of input
imshow("in", input);
imshow("out", output);
Any suggestions?
The first call is correct, but being a distance, it’s not stored as uchar. When you want to display it, OpenCV converts those float (i think) into uchars. And the result seems black.
Find the max value in the output, and then scale it to fit a grayscale image
EDIT
The first idea was correct, but you actually did not try to find maxVal! You said that by looking at the picture, instead of actually extracting it. Difference between win and fail.
So, calculate the dist transform using the precise algoritm, and then
Edit 2
And you must put the setTo(0) there.