Exemplo n.º 1
0
 def getImageAtScale(self, scale):
     return ftext.getImageAtScale(scale)
Exemplo n.º 2
0
def draw_keypoints(img, keypoints, threshold, inter = True, color = 1):
    
    scales = ftext.getImageScales()
    #s = 100
    
    octaves = np.unique( keypoints[:, 2])
    if octaves.shape[0] == 0:
        return
    maxOctave = np.max(octaves)
    images = []
    selectors = []
    drawers = []
    for i in range(int(maxOctave) + 1):
        scale = scales[i]
        dst = ftext.getImageAtScale(i)
        cv2.imwrite("/tmp/pycv-{0}.png".format(i), dst)
        if color == 1:
            images.append(cv2.cvtColor(dst, cv2.COLOR_BGR2RGB))
        else:
            '''
            shape = img.shape
            shapet = ( shape[0] * scale, shape[1] * scale) 
            dst = np.zeros(shapet, dtype=np.uint8)
            dst = cv2.resize(img, (0,0), fx=scale, fy=scale)
            images.append(cv2.cvtColor(dst, cv2.COLOR_BGR2RGB))
            '''
            images.append(dst)
            
            #cv2.imshow("img", dst)
            #cv2.waitKey(0)
        
    
    ax_tuple = []
       
    for i in range(int(maxOctave) + 1):
        f = plt.figure(num = i)
        ax = f.add_subplot(111)
        ax_tuple.append(ax)
        
        plt.subplots_adjust(top = 1, bottom = 0, right = 1, left = 0, hspace = 0, wspace = 0)
        plt.margins(0,0)
        
        #tmp = cv2.cvtColor(, cv2.COLOR_GRAY2RGB)
        ax_tuple[i].imshow(images[i], interpolation='nearest', cmap=mpl.cm.gray)
        ax_tuple[i].grid(True)
        ax_tuple[i].axis('off') 
        ax_tuple[i].set_xlim([0, images[i].shape[1]])
        ax_tuple[i].set_ylim([images[i].shape[0], 0])
        ax_tuple[i].axes.get_xaxis().set_ticks([])
        ax_tuple[i].axes.get_yaxis().set_ticks([])
        
        maskOct = keypoints[:, 2] == i
        octIdx = np.nonzero(maskOct)
        octavePoints = keypoints[keypoints[:, 2] == i, :]
        octavePoints[:, 0] *= scales[i]
        octavePoints[:, 1] *= scales[i]
        octavePoints[:, 5] *= scales[i]
        octavePoints[:, 6] *= scales[i]
        octavePoints[:, 7] *= scales[i]
        octavePoints[:, 8] *= scales[i]
        style = 'rx'
        c = 'red'
        if len(octavePoints) > 0 and octavePoints.shape[1] > 9:
            for k in range(6):
                maski = octavePoints[:, 9] == k + 1
                if k == 1:
                    style = "rv"
                if k == 2:
                    style = "ro"
                if k == 4:
                    style = "bo"
                    c = 'blue'
                if k == 5:
                    style = "yo"
                    continue
                
                if drawGrayScale:
                    style = 'wv'
                    if k == 1:
                        style = "wv"
                    if k == 2:
                        style = "wv"
                    if k == 4:
                        style = "wo"
                        c = 'blue'
                    c = style
                
                ax_tuple[i].scatter(octavePoints[maski, 0], octavePoints[maski, 1],c=c, s=s )
                #ax_tuple[i].plot(octavePoints[maski, 0], octavePoints[maski, 1], style, markersize = 10) 
        else:
            ax_tuple[i].plot(octavePoints[:, 0], octavePoints[:, 1], style)
        #ax_tuple[i].plot(octavePoints[:, 6] * scales[i], octavePoints[:, 7] * scales[i], 'bo')
        #for j in range( octavePoints.shape[0] ):
        #    ax_tuple[i].plot([octavePoints[j,0] * scales[i], octavePoints[j,6]* scales[i]], [octavePoints[j,1] * scales[i], octavePoints[j,7]* scales[i]], 'r-')
        if inter:
            rs = RectangleSelector(ax_tuple[i], line_select_callback,
                                       drawtype='box', useblit=True,
                                       button=[1,3], # don't use middle button
                                       minspanx=5, minspany=5,
                                       spancoords='pixels')
            rs.keypoints = octavePoints
            rs.octIdx = octIdx
            rs.image = images[i]
            rs.threshold = threshold
            selectors.append(rs)
            drawer = FastDrawer(ax_tuple[i], images[i], threshold)
            drawers.append(drawer)
    
    if inter:
        toggle_selector.RS = selectors
        plt.show() 
        plt.show(block=False)
    else:
        plt.show()
Exemplo n.º 3
0
def draw_keypoints(img, keypoints, threshold, inter=True, color=1):

    scales = ftext.getImageScales()
    #s = 100

    octaves = np.unique(keypoints[:, 2])
    if octaves.shape[0] == 0:
        return
    maxOctave = np.max(octaves)
    images = []
    selectors = []
    drawers = []
    for i in range(int(maxOctave) + 1):
        scale = scales[i]
        dst = ftext.getImageAtScale(i)
        cv2.imwrite("/tmp/pycv-{0}.png".format(i), dst)
        if color == 1:
            images.append(cv2.cvtColor(dst, cv2.COLOR_BGR2RGB))
        else:
            '''
            shape = img.shape
            shapet = ( shape[0] * scale, shape[1] * scale) 
            dst = np.zeros(shapet, dtype=np.uint8)
            dst = cv2.resize(img, (0,0), fx=scale, fy=scale)
            images.append(cv2.cvtColor(dst, cv2.COLOR_BGR2RGB))
            '''
            images.append(dst)

            #cv2.imshow("img", dst)
            #cv2.waitKey(0)

    ax_tuple = []

    for i in range(int(maxOctave) + 1):
        f = plt.figure(num=i)
        ax = f.add_subplot(111)
        ax_tuple.append(ax)

        plt.subplots_adjust(top=1,
                            bottom=0,
                            right=1,
                            left=0,
                            hspace=0,
                            wspace=0)
        plt.margins(0, 0)

        #tmp = cv2.cvtColor(, cv2.COLOR_GRAY2RGB)
        ax_tuple[i].imshow(images[i],
                           interpolation='nearest',
                           cmap=mpl.cm.gray)
        ax_tuple[i].grid(True)
        ax_tuple[i].axis('off')
        ax_tuple[i].set_xlim([0, images[i].shape[1]])
        ax_tuple[i].set_ylim([images[i].shape[0], 0])
        ax_tuple[i].axes.get_xaxis().set_ticks([])
        ax_tuple[i].axes.get_yaxis().set_ticks([])

        maskOct = keypoints[:, 2] == i
        octIdx = np.nonzero(maskOct)
        octavePoints = keypoints[keypoints[:, 2] == i, :]
        octavePoints[:, 0] *= scales[i]
        octavePoints[:, 1] *= scales[i]
        octavePoints[:, 5] *= scales[i]
        octavePoints[:, 6] *= scales[i]
        octavePoints[:, 7] *= scales[i]
        octavePoints[:, 8] *= scales[i]
        style = 'rx'
        c = 'red'
        if len(octavePoints) > 0 and octavePoints.shape[1] > 9:
            for k in range(6):
                maski = octavePoints[:, 9] == k + 1
                if k == 1:
                    style = "rv"
                if k == 2:
                    style = "ro"
                if k == 4:
                    style = "bo"
                    c = 'blue'
                if k == 5:
                    style = "yo"
                    continue

                if drawGrayScale:
                    style = 'wv'
                    if k == 1:
                        style = "wv"
                    if k == 2:
                        style = "wv"
                    if k == 4:
                        style = "wo"
                        c = 'blue'
                    c = style

                ax_tuple[i].scatter(octavePoints[maski, 0],
                                    octavePoints[maski, 1],
                                    c=c,
                                    s=s)
                #ax_tuple[i].plot(octavePoints[maski, 0], octavePoints[maski, 1], style, markersize = 10)
        else:
            ax_tuple[i].plot(octavePoints[:, 0], octavePoints[:, 1], style)
        #ax_tuple[i].plot(octavePoints[:, 6] * scales[i], octavePoints[:, 7] * scales[i], 'bo')
        #for j in range( octavePoints.shape[0] ):
        #    ax_tuple[i].plot([octavePoints[j,0] * scales[i], octavePoints[j,6]* scales[i]], [octavePoints[j,1] * scales[i], octavePoints[j,7]* scales[i]], 'r-')
        if inter:
            rs = RectangleSelector(
                ax_tuple[i],
                line_select_callback,
                drawtype='box',
                useblit=True,
                button=[1, 3],  # don't use middle button
                minspanx=5,
                minspany=5,
                spancoords='pixels')
            rs.keypoints = octavePoints
            rs.octIdx = octIdx
            rs.image = images[i]
            rs.threshold = threshold
            selectors.append(rs)
            drawer = FastDrawer(ax_tuple[i], images[i], threshold)
            drawers.append(drawer)

    if inter:
        toggle_selector.RS = selectors
        plt.show()
        plt.show(block=False)
    else:
        plt.show()
Exemplo n.º 4
0
Arquivo: ft.py Projeto: AAAyag/FASText
 def getImageAtScale(self, scale):
     return ftext.getImageAtScale(scale)