Corners and lines detection in hand drawn pictures in Python
I'm working on a project and at some point I have to detect corners and lines in a hand drawn picture. I am doing the work in Python but the result I get is not that good.
The code I wrote is the following:
import sys
from math import sin, cos, sqrt, pi
import cv
src = cv.LoadImage('draw.jpg')
cv.NamedWindow("Source", 1)
cv.NamedWindow("Result", 1)
dst = cv.CreateImage(cv.GetSize(src), 8, 1)
color_dst = cv.CreateImage(cv.GetSize(src), 8, 3)
storage = cv.CreateMemStorage(0)
lines = 0
cv.Canny(src, dst, 1.0, 4.0, aperture_size=3)
cv.CvtColor(dst, color_dst, cv.CV_GRAY2BGR)
lines = cv.HoughLines2(dst, storage, cv.CV_HOUGH_PROBABILISTIC, 1, pi / 180, 10, 0, 10)
for line in lines:
cv.Line(color_dst, line[0], line[1], cv.CV_RGB(0, 255, 0), 2, 8)
cornerMap = cv.CreateMat(dst.height, dst.width, cv.CV_32FC1)
cv.CornerHarris(dst,cornerMap,3)
for y in range(0,dst.height):
for x in range (0, dst.width):
harris = cv.Get2D(cornerMap, y, x)
if harris[0] >10e-06:
cv.Circle(color_dst, (x,y),2,cv.RGB(115,0,25))
cv.ShowImage("Source", src)
cv.ShowImage("Hough", color_dst)
cv.SaveImage("draw_det.png", color_dst)
cv.WaitKey()
The input picture can be seen here:
While the resultant picture can be seen here:
The result is not what I am expecting. What I want as output is to see the corner points detected in red and the lines connecting them in green. While what I get is something that does not make sense by looking at the pictures. What am I doing wrong?