I'm trying to properly detect the edges of a playing card that has been blurred, grayscaled and then thresholded. I thought having the sharp black and white contrast would make the edges quite easy to detect, but no joy so far. I'm starting with:
And using the Canny Edge Detector I wrote producing this:
The result of Sobel was basically the same. However using OpenCV's Canny Detection I could produce this:
The border being correctly fitted together is what I'm desperately needing to recreate in my own code, and I'm not committed to using any particular type of Edge Detection, I just need to find an algorithm that will give me the connected edge! My Canny code can be found here, and it is very much based from the LIRE code here. If anybody could help me go from the first image to the third I would be incredibly grateful! Any edge detection welcome!
Edit: Code for NMS:
//main program
for(int x = 1; x < width-1; x++)
{
for(int y = 1; y < height-1; y++)
{
if(src.getRaster().getPixel(x, y, tmp)[0] >= 250)
{
trackWeakOnes(x, y, src);
}
}
}
private static void trackWeakOnes(int x, int y, BufferedImage src)
{
for (int a = x - 1; a <= x + 1; a++)
{
for (int b = y - 1; b <= y + 1; b++)
{
if (checkWeak(a, b, src))
{
src.getRaster().setPixel(x, y, tmpMax);
trackWeakOnes(a, b, src);
}
}
}
}
private static boolean checkWeak(int x, int y, BufferedImage src)
{
return ((src.getRaster().getPixel(x, y, tmpPix)[0] > 0) &&
(src.getRaster().getPixel(x, y, tmpPix)[0] < 255));
}
tmpPix is an empty array to be filled, tmpMax is an array {255, 255, 255} to make edges white.