diff --git a/exp/hough.py b/exp/hough.py --- a/exp/hough.py +++ b/exp/hough.py @@ -41,52 +41,57 @@ def filterDiag(edges): return edges1+edges2 +def houghLines(bwImg): + colorImg=cv.cvtColor(bwImg,cv.COLOR_GRAY2BGR) + lines = cv.HoughLinesP(bwImg,1,np.pi/180,10,minLineLength=10,maxLineGap=40) + if lines is None: lines=[] + for line in lines: + x1,y1,x2,y2 = line[0] + cv.line(colorImg,(x1,y1),(x2,y2),(0,255,0),1) -i=sys.argv[1] -annotations=DataFile("/home/laman/Projekty/python/oneEye/images/annotations.json.gz") -filename="{0}.jpg".format(i) -img=cv.imread(os.path.join("/home/laman/Projekty/python/oneEye/images/",filename)) -(x1,y1,x2,y2)=computeBoundingBox(annotations[filename][0]) -img=img[y1:y2, x1:x2, :] -# blurred=cv.GaussianBlur(img,(5,5),0) -# small=cv.resize(img,None,fx=0.5,fy=0.5,interpolation=cv.INTER_AREA) -small=img -clahe = cv.createCLAHE(clipLimit=2.0, tileGridSize=(8,8)) -gray=cv.cvtColor(small,cv.COLOR_BGR2GRAY) -# gray=clahe.apply(gray) -show(gray) -edges=cv.Canny(gray,70,130) -show(edges) -edges=filterHor(edges)+filterVert(edges)+filterDiag(edges) -show(edges) + show(colorImg) -# kernel = np.ones((2,2),np.uint8) -# edges = cv.morphologyEx(edges, cv.MORPH_DILATE, kernel) -# show(edges) -# edges=cv.morphologyEx(edges,cv.MORPH_ERODE,kernel) -# show(edges) -colorEdges=cv.cvtColor(edges,cv.COLOR_GRAY2BGR) -# show(blurred) -# show(small) +if __name__=="__main__": + i=sys.argv[1] + annotations=DataFile("/home/laman/Projekty/python/oneEye/images/annotations.json.gz") + filename="{0}.jpg".format(i) + img=cv.imread(os.path.join("/home/laman/Projekty/python/oneEye/images/",filename)) + (x1,y1,x2,y2)=computeBoundingBox(annotations[filename][0]) + img=img[y1:y2, x1:x2, :] + # blurred=cv.GaussianBlur(img,(5,5),0) + # small=cv.resize(img,None,fx=0.5,fy=0.5,interpolation=cv.INTER_AREA) + small=img + clahe = cv.createCLAHE(clipLimit=2.0, tileGridSize=(8,8)) + gray=cv.cvtColor(small,cv.COLOR_BGR2GRAY) + # gray=clahe.apply(gray) + show(gray) + edges=cv.Canny(gray,70,130) + show(edges) + edges=filterHor(edges)+filterVert(edges)+filterDiag(edges) + show(edges) + -# lines = cv.HoughLines(edges,1,np.pi/180,200) -# if lines is None: lines=[] -# for line in lines: -# rho,theta = line[0] -# a = np.cos(theta) -# b = np.sin(theta) -# x0 = a*rho -# y0 = b*rho -# x1 = int(x0 + 1000*(-b)) -# y1 = int(y0 + 1000*(a)) -# x2 = int(x0 - 1000*(-b)) -# y2 = int(y0 - 1000*(a)) -# cv.line(colorEdges,(x1,y1),(x2,y2),(0,0,255),1) -lines = cv.HoughLinesP(edges,1,np.pi/180,80,minLineLength=50,maxLineGap=20) -if lines is None: lines=[] -for line in lines: - x1,y1,x2,y2 = line[0] - cv.line(colorEdges,(x1,y1),(x2,y2),(0,255,0),1) + # kernel = np.ones((2,2),np.uint8) + # edges = cv.morphologyEx(edges, cv.MORPH_DILATE, kernel) + # show(edges) + # edges=cv.morphologyEx(edges,cv.MORPH_ERODE,kernel) + # show(edges) + colorEdges=cv.cvtColor(edges,cv.COLOR_GRAY2BGR) + # show(blurred) + # show(small) -show(colorEdges) + # lines = cv.HoughLines(edges,1,np.pi/180,200) + # if lines is None: lines=[] + # for line in lines: + # rho,theta = line[0] + # a = np.cos(theta) + # b = np.sin(theta) + # x0 = a*rho + # y0 = b*rho + # x1 = int(x0 + 1000*(-b)) + # y1 = int(y0 + 1000*(a)) + # x2 = int(x0 - 1000*(-b)) + # y2 = int(y0 - 1000*(a)) + # cv.line(colorEdges,(x1,y1),(x2,y2),(0,0,255),1) + houghLines(edges)