Search code examples
androidimage-processingopencvedge-detection

How to find canny edge detected pixels in a Mat object?


I do this:

Imgproc.Canny(mGraySubmat, mIntermediateMat, 50, 100);  

Stop me when I´m wrong:
1. Now the edges should be in mIntermediateMat.
2. All pixels in mIntermediateMat should have a color value of 0 OR 255. (I fetch the values with mIntermediateMat.get(x,y)).
3. mIntermediateMat.type()=> Mat [ 480*640*CV_8UC1, isCont=true, isSubmat=false, nativeObj=0x139ec0, dataAddr=0x4453d010 ]
and
mGraySubmat.type()=> Mat [ 480*640*CV_8UC1, isCont=true, isSubmat=true, nativeObj=0x1e8308, dataAddr=0x450b4010 ]

Now lets say Canny has detected edges similar to a rectangle. Now I start from a seedpoint inside this rectangle and walk to the north, south, east, west and check every pixel value until I reach the edges.
See the results:

Picture can be found here https://i.sstatic.net/JWVJW.png

Walking to the north seems to work. Pixel with value 255 found at coordinates: x,y = 239,346 ->right
South: Pixel with value 255 found at x,y = 239,488 (actually 488 cant be, because 480 is maximum)->wrong
East: Pixel with value 255 found at x,y = 342,388 ->wrong
West: No pixel found, out of screen... -> wrong
Question: Whats wrong? Why is an edge-pixel not detected when I walk over it.

IMPORTANT: At the top and the left of the picture there is a scale with size of 100 pixels. The origin is at the top left and a coordinate of x,y = 100,350 would be 100 pixels to the right and 350 pixels DOWN.


Solution

  • I fetched the pixel color value with mIntermediateMat.get(x,y). Thats just wrong. As function is defined as Mat.get(rows,cols) it would be mIntermediateMat.get(y,x). See the difference? I didn´t. Lots of lost time and another dumbness award for me.