示例#1
0
def tstInvert(db,img):
    ' inverted images have a horizontal line at .3 instead of .7 '
    height, width = img.shape[:2]
    lines = findLines(img,300,30)#(img,300,30)    
    v7 =  0 ; v3 = 0;   # maxA = 0 ; skew = []; mxlen =0
    if not lines.any: return(180) 
    for line in lines:
        for x1,y1,x2,y2  in line :
            ##    angle =  np.arctan2( y2-y1 ,  x2-x1 ) * 180 /  np.pi   #  in deg
            yh = round( y2 / float(height),1 )  # % dist on y axis
            #if db: print 'yh is ' , yh
            if   yh == 0.3: v3 = v3 + 1
            elif yh == 0.7: v7 = v7 + 1
        # end for in line
    #end for line in lines    
 
    if db:
        print 'V3 {} V7 {}   lines found {} '.format(v3, v7,  len(lines))
        cvs(db,img)

    if( v3 > v7):
        return( 180)
    else:
        return(0 )  #  largest < 2 deg
示例#2
0
    cv2.imshow('image',img)
    k = cv2.waitKey(1) & 0xFF
    if k == 27:
        cvd()
        break
    if k == ord('s'):
    #        hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
        print 'minline {}  maxgap {} '.format(r,g)

        fil = "img3c.png"
        #fil = 'lineTest.png'
        db = False
        img = cv2.imread(fil)
        minline = r
        maxgap = g
        lines = findLines(img,minline,maxgap,v)      # 300  30
        if lines is not None and lines.any:
            print '{} lines found  '.format(len(lines))
            for i,xx in enumerate (lines):
                if i > 10: break
                for x1,y1,x2,y2 in xx:
                    angle =  np.arctan2( y2-y1 ,  x2-x1 ) * 180 /  np.pi   # angle in deg
                    #print 'x1,y1 {},{}\t x2,y2 {},{} \tangle {}'.format(x1,y1,x2,y2,angle)
                    cv2.line(img,(x1,y1),(x2,y2),(0,255,255),2)
           
        else: print 'no lines found',

    r = cv2.getTrackbarPos('minline','image')
    g = cv2.getTrackbarPos('maxgap','image')
    v = cv2.getTrackbarPos('votes','image')