PDA

Visualizza la versione completa : [Python] Opencv


fedeg93
19-12-2008, 16:45
Ho scritto questo code



from opencv import *
from opencv.highgui import *

def circle(point,image):
cv.cvCircle(image,point,3, cv.cvScalar (0, 255, 0, 0),-1, 8, 0)

def on_mouse (event, x, y, flags, param):
print event
if event == highgui.CV_EVENT_LBUTTONDOWN:
circle(cv.cvPoint (x, y))

capture = cvCreateCameraCapture(0)
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 640)
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 480)
cvNamedWindow('Tracker',highgui.CV_WINDOW_AUTOSIZE )
#highgui.cvSetMouseCallback('Tracker', on_mouse)
#point = [[], []]
while True:
frame = highgui.cvQueryFrame(capture)
grey = cv.cvCreateImage(cv.cvGetSize(frame), 8, 1)
prev_grey = cv.cvCreateImage (cv.cvGetSize (frame), 8, 1)
eig = cv.cvCreateImage (cv.cvGetSize(grey), 32, 1)
temp = cv.cvCreateImage (cv.cvGetSize(grey), 32, 1)
pyramid = cv.cvCreateImage (cv.cvGetSize (frame), 8, 1)
prev_pyramid = cv.cvCreateImage (cv.cvGetSize (frame), 8, 1)
quality = 0.01
min_distance = 10
point = cv.cvGoodFeaturesToTrack (grey, eig, temp,500,quality, min_distance, None, 3, 0, 0.04)
if point:
break
while True:
win_size = 10
frame = highgui.cvQueryFrame(capture)
image = cv.cvCreateImage (cv.cvGetSize (frame), 8, 3)
cv.cvCopy (frame, image)
new_point,status = cv.cvCalcOpticalFlowPyrLK (prev_grey, grey, prev_pyramid, pyramid,point, len(point),cv.cvSize (win_size, win_size), 3,len(point),None,cv.cvTermCriteria (cv.CV_TERMCRIT_ITER|cv.CV_TERMCRIT_EPS,20, 0.03),0)
#cv.cvReleaseImage (eig)
#cv.cvReleaseImage (temp)
for the_point in new_point:
for towrite in the_point:
if towrite:
circle(towrite,image)
cvShowImage('Tracker', image)
print "Refreshed"
if getKeyPressed() == '\x1b': # escape
cvDestroyWindow('Tracker')
break




I pallini creati dovrebbero seguire i movimenti, invece si ammassano in alto a destra, dove sto sbagliando??
sapete dove posso trovare una guida a opencv per python??
avete qualche code da mostrarmi in modo da capire meglio??

Grazie e buon natale
:ciauz:

Loading