2016-04-19 6 views
0

私はOpenCVのとPythonを使って指紋 画像の方位マップを取得する機能を実現していますが、何かが間違っている実装は

def compute_real_orientation(array_I, w=17, h=17, low_pass_filter=cv2.blur,filter_size=(5,5),blur_size=(5,5),**kwargs): 
    row, col = array_I.shape 
    array_I = array_I.astype(np.float) 
    Ox = array_I[0:row-h+1:h,0:col-w+1:w].copy() 
    Ox[:] = 0.0 
    Vx = Ox.copy() 
    Vy = Vx.copy() 
    Oy = Ox.copy() 
    angle = Vx.copy()#array to contain all the 17*17 blocks's orientatons 
    c = r = -1 
    for i in xrange(0, row-h+1, h): 
     r+=1 
     for j in xrange(0, col-w+1, w): 
      c+=1 
      Dx = cv2.Sobel(array_I[i:i+h,j:j+w],-1,1,0)#gradient component x for a 17*17block 
      Dy = cv2.Sobel(array_I[i:i+h,j:j+w],-1,0,1)#gradient component y for 17*17 block 
      for k in range(0,h): 
       for l in range(0,w): 
        Vy[r][c] += ((Dx[k][l])*(Dy[k][l]))**2 
        Vx[r][c] += 2*(Dx[k][l])*(Dy[k][l]) 
     angle[r][c] = 0.5*(math.atan(Vy[r][c]/Vx[r][c]))#get the orientation angle for the given 16*16 block 
    c = -1 
    #smoothing process of the whole array angle 
    row, col = angle.shape 
    for i in range(0, row): 
     for j in range(0, col): 
      Ox[i][j] = math.cos(2*angle[i][j]) 
      Oy[i][j] = math.sin(2*angle[i][j]) 
    Ox = low_pass_filter(Ox, blur_size) 
    Oy = low_pass_filter(Oy, blur_size) 
    for i in range(0, row): 
     for j in range(0, col): 
      angle[i][j] = 0.5*math.atan(Oy[i][j]/Ox[i][j])#take the final orientation of all 17*17 blocks 
    return angle 

algorithmに設定しています。オリエンテーションイメージセクション ですが、コードが正しく機能しないため、正しい方向のマップが得られません。これをトラブルシューティングするのに役立つものはどれですか?

B.R

答えて

0

コードは正しく動作しています。方位マップを視覚化したい場合は、接線の定義を思い出してください。

tan(a) = (y1-y0)/(x1-x0) (1) 
y1 = (x1-x0)*tan(a)+y0 (2) 

ここで(x0、y0)はwxwブロックの中心の座標です。 (x0、y0)から(x1、y1)までの線をプロットして、方向線を描画します。 (2)あなたが持っているから、長さ= X1-X0こと:ここ

y1 = length*tan(a)+y0 (3) 
x1 = x0 + length (4) 
'a' in 'tan(a)' is the orientation angle at the pixel of (x0,y0) coordinates 

は、この使用してmatplotlibの

import cv2 
import numpy as np 
import math 
import matplotlib.pyplot as plt 

def plot_point(point, angle, length, ax): 
''' 
    point - Tuple (x, y) coordinates of the pixel 
    angle - orientation angle at (x,y) pixel. 
    length - Length of the line you want to plot. 

    Will plot the line on a 10 x 10 plot. 
    ''' 

    # unpack the first point 
    x, y = point 
    # find the end point 
    endx = x + length 
    endy = length*math.tan(angle)+y 
    ax.plot([x, endx], [y,endy],color='blue') 

def draw_orientation_map(angles, 
         block_size, 
         center_coordinates, 
         fingerprint_filename, 
         length): 

    img = cv2.imread(fingerprint_filename) 
    row, col = img.shape 
    x_center = y_center = block_size/2#y for rowq and x for columns 
    r,c = angles.shape #note center_coordinates.shape = angles.shape 
    fig = plt.figure() 
    ax = plt.subplot(111) 
    ax.set_ylim([0, row]) # set the bounds to be 10, 10 
    ax.set_xlim([0, col]) 
    plt.imshow(img, zorder=0, extent=[0,col,0,row]) 
    for i in xrange(0,r): 
     for j in xrange(0,c): 
      plot_point((j*w + y_center, i*w + x_center), 
         angles[i][j], 
         length,ax) 
    plt.show()  
を行うにはPythonの関数であります