I’m trying to use Canny Edge detection in an Android App.
I tested in Python first using the below steps:
gray = cv.cvtColor(img, cv.COLOR_RGB2GRAY)
kernel = np.ones((5,5),np.uint8)
dilate = cv.morphologyEx(gray, cv.MORPH_CLOSE, kernel, iterations= 30)
blurred = cv.GaussianBlur(dilate, (5, 5), 0)
edges = cv.Canny(blurred, 50, 150)
Which resulted in a solid outlined image of a piece of paper.
However, when I run the similar steps through on the Android App in Kotlin using this code
val tmp = Mat(tempImage.width , tempImage.height , CV_8UC1 )
Utils.bitmapToMat(tempImage, tmp)
//Convert to Grey
cvtColor(tmp, tmp, COLOR_RGB2GRAY )
//dilate
val kernel = Mat.ones(5, 5, CvType.CV_8U )
val point = Point(-1.0,-1.0)
morphologyEx(tmp, tmp, MORPH_CLOSE , kernel, point, 30)
//Blur
GaussianBlur(tmp, tmp, Size(5.0, 5.0), 0.0)
//Canny
Canny(tmp,tmp,50.0,150.0)
The resulting image is as follows
Which is a dashed outline of a page instead of a solid one
The images up to the Canny Step are identical across the two.
Python and Android are both using 4.8