First you need to have a basic understanding of the Cv2.goodfeaturestotrack function:
Detailed introduction here: http://baike.baidu.com/link?url= Zpk3imjjfkko0k2bnienavksiry0-ci7weicpe9adfybc5tyusbpt9cutx4-vbdmhancssktos3qp8n4jainfa
The video I'm dealing with is a thermal imager, designed to track hot areas:
The code is as follows:
#!/usr/bin/env python #-*-coding:utf-8-*-"" "Author: function: Track high temperature area. "" "Import NumPy as NP import CV2 import CV2.CV as CV Cap=cv2.
Videocapture ("My.mp4") feasize=1 max=200 qua=0.05 mindis=7 blocksize=10 usehaar=true k=0.04 paras=dict (maxCorners=200,
qualitylevel=0.05, mindistance=7, blocksize=10, Useharrisdetector=true, k=0.04) keypoints=list () Mask=none marker=none def getkpoints (IMAG,INPUT1): Mask1=np.zeros_like (INPUT1) x= 0 y=0 w1,h1=input1.shape #print 666 #print input1.shape input1=input1[0:w1,200:h1] #print input1.s
Hape try:w,h=imag.shape #w =w/2 #h =h/2 #print w,h None mask1[y:y+h,x:x+w]=255 keypoints=list () #kp =cv2.goodfeaturestotrack (INPUT1, #m Ask1, #**paras) #input1 =input1.fromarray kp=cv2.goodfeaturestotrack (input1,200,0.0 4,7)
#cv2. Goodfeaturestotrack (Image, Maxcorners, Qualitylevel, mindistance) if KP is not None
nd len (KP) >0:for x,y in Np.float32 (KP). Reshape ( -1,2): Keypoints.append ((x,y)) return keypoints def process (image): Grey1=cv2.cvtcolor (Image,cv2. Color_bgr2gray) grey=cv2.equalizehist (grey1) keypoints=getkpoints (grey,grey1) #print keypoints #print ima
Ge.shape if keypoints is not None and Len (keypoints) >0:for x,y in keypoints: Cv2.circle (image, (int (x+200), y), 3, (255,255,0)) return image #p =cv2.imread (' 1.png ') #p2 =process (P) #cv2. IMS How (' i ', p2) #cv2. Waitkey (0) #cv2. Destroyallwindows () while (cap.isopened ()): Ret,frame=cap.read () frame=process (frame) cv2.imshow (' frame ', frame) if Cv2.waitkey (1) &0xff==ord (' Q '): Break Cv2.waitkey (0) Cv2.
Destroyallwindows ()
The tracking effect is as follows: