我实现了一个获取指纹方向图的功能 使用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
我在 2.4方向图部分实施以下算法algorithm 但我的代码工作不正常,我没有得到正确的方向图。任何人都可以帮我排除故障吗?
B.R
答案 0 :(得分:0)
代码运行正常。如果要显示方向图,请记住切线定义。
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" x:Name="panel">
<Button Width="100"
Content="Foo"
Click="Button_Click" />
<Button Width="100"
Content="Bar"
Click="Button_Click" />
<Button Width="100"
Content="Baz"
Click="Button_Click" />
</StackPanel>
<ListBox Grid.Row="1"
Name="TheList"
Height="100" Width="{Binding ElementName=panel, Path=ActualWidth}" />
</Grid>
其中(x0,y0)是wxw块中心的坐标。 绘制从(x0,y0)到(x1,y1)的线以绘制方向线。从(2)得到长度= x1-x0:
tan(a) = (y1-y0)/(x1-x0) (1)
y1 = (x1-x0)*tan(a)+y0 (2)
这是一个使用matplotlib
执行此操作的python函数 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