Opencv Python : Pyramid Lucas Kanade : Optik Akış

Dün gece bir hatayla uğraştım. tam 6 saat. halen anlamışda değilim. 3 saat uykuyla durmama rağmen didindim uğraştım. sonuç çıktı. Kodları c++ tan pythona çevirdim.

Optik akış denklemi cisimleri hızını yönünü bulabiliriz.

   '''
Created on Nov 15, 2011

@author: barakli.net
'''
#!/usr/bin/python
import cv

MAX_CORNERS = 500
imga=cv.LoadImage("imgc.png",cv.CV_LOAD_IMAGE_GRAYSCALE)
imgb=cv.LoadImage("imgc1.png",cv.CV_LOAD_IMAGE_GRAYSCALE)

img_sz=cv.GetSize(imga)
win_sz=10

imgc=cv.LoadImage("OpticalFlow1.png",cv.CV_LOAD_IMAGE_UNCHANGED)

eig_image=cv.CreateImage(img_sz, cv.IPL_DEPTH_32F, 1)
temp_image=cv.CreateImage(img_sz, cv.IPL_DEPTH_32F, 1)

corner_count=MAX_CORNERS

cornersA=[]

cornersA=cv.GoodFeaturesToTrack(imga, eig_image, temp_image,MAX_CORNERS,0.01, 5.0, None,3,0,0.04)

cornersA=cv.FindCornerSubPix(imga,cornersA,(win_sz,win_sz),(-1,-1),(cv.CV_TERMCRIT_ITER | cv.CV_TERMCRIT_EPS,20,0.03))

pyrA=cv.CreateImage(img_sz,8,1 )
pyrB=cv.CreateImage(img_sz,8,1)

cornersB,features_found,feature_errors=cv.CalcOpticalFlowPyrLK(imga, imgb, pyrA, pyrB, cornersA, (win_sz,win_sz), 5, (cv.CV_TERMCRIT_ITER | cv.CV_TERMCRIT_EPS,20,0.03), 0)

print "features errors count==>>"+str(len(feature_errors))
print "features found count==>>"+str(len(features_found))

for k in range(len(feature_errors)):
    if (features_found[k]==0) or (feature_errors[k]>550):
        print("Error is %f/n",feature_errors[k])
        continue
    print ("Got it /n")
    p0=cv.Round(cornersA[k][0]),cv.Round(cornersA[k][1])
    p1=cv.Round(cornersB[k][0]),cv.Round(cornersB[k][1])
    cv.Line(imgc,p0,p1,cv.CV_RGB(255,0,0),2)

cv.namedWindow("ImageA",0)
cv.namedWindow("ImageB",0)
cv.namedWindow("Opflow",0)

cv.ShowImage("ImageA",imga)
cv.ShowImage("ImageB",imgb)
cv.ShowImage("Opflow",imgc)

cv.WaitKey()
cv.DestroyAllWindows()

şş