liuliu / ccv

C-based/Cached/Core Computer Vision Library, A Modern Computer Vision Library
http://libccv.org
Other
7.08k stars 1.72k forks source link

SWT error ? #21

Closed steeve closed 12 years ago

steeve commented 12 years ago

I'm having something weird with SWT.

When I input this image: Imgur

I get this: Imgur

Would you know why that happens? (BTW, the Canny edge works fine).

liuliu commented 12 years ago

The SWT implementation is very much in progress. It seems to me that you set "direction" wrong, or need to upscale the image (up2x parameter). I will have a new SWT implementation based on MSER and a new stroke transform algorithm (probably in a month), which should be more stable.

steeve commented 12 years ago

Thanks for the quick answer! I did try with direction at 1 and -1 but got pretty much the same garbage. I'll try the up2x param, but I don't it used anywhere in the code for SWT?

steeve commented 12 years ago

By the way, to let you know, the image resized 2x via OpenCV's Lanczos yields the same results!

UPDATE: and also, thanks for the great work !

liuliu commented 12 years ago

Yeah, I forget up2x is an obsolete parameter. If assume all parameters are correctly set (as from swtdetect.c example), I suspect in this case, the direction derived from Sobel filter is off. Try use a bigger Sobel mask (or apply Gaussian filter before processing ccv_blur), if it still doesn't work, I will wait for my shining new MSER-based SWT :-)

steeve commented 12 years ago

Yeah I'm using the params from swtdetect.c, and I'm already doing a 3x3 gaussian blur for denoising before hand. Let me just say that when I input the whole picture (in the complete scene, not the cropped version I posted), it does work though. We'll be able to wait on your new SWT filter :)

steeve commented 12 years ago

Also, does SWT can function for vertical text? Like in the case above, detect the 2 lines as one rectangle? Because it's line based at the moment :)

steeve commented 12 years ago

BTW, what do you think happens in this case? Is a quick fix possible or this needs more in-depth fixing? Thanks :)

steeve commented 12 years ago

Also, I'm using clang on OS X Lion

steeve commented 12 years ago

Okay. I finally got to the bottom of this. It was actually caused by numpy and pointer alignment issues. Your SWT works fine! Sorry for the ordeal, but that was a nasty one to spot !

liuliu commented 12 years ago

Thanks for the follow up. I am planning a ccv_read function to handle these tricky memory copies. Doing raw memory operation on ccv dense matrix type is ok for me, but not going to work for other developers :-)

steeve commented 12 years ago

Just for future reference, here's how to convert a 2d numpy matrix (grayscale) to a ccv_matrix:

def np_to_ccv(mat):
    return ccv.ccv_dense_matrix(
        mat.shape[0],
        mat.shape[1],
        ccv.CCV_8U | ccv.CCV_C1,
        mat.ctypes.data_as(POINTER(c_ubyte)),
        0
    )