python裡使用cv2.goodFeaturesToTrack()函數追蹤映像裡的關鍵點__函數

來源:互聯網
上載者:User

    首先需要對cv2.goodFeaturesToTrack函數有一個基本的瞭解:

    詳細的介紹在這裡:http://baike.baidu.com/link?url=zPK3iMJJfkKO0k2bniENAvksIRY0-Ci7weIcpE9AdFybc5tyUsbPT9cUTx4-vBDmhAnCsSKToS3QP8n4JaInfa

    我要處理的視頻是熱成像儀拍攝的,目的是追蹤高溫的地區:

代碼如下:

#!/usr/bin/env python# -*- coding: utf-8 -*-"""作者:功能:跟蹤溫度高的地區。"""import numpy as npimport cv2import cv2.cv as cvcap=cv2.VideoCapture("my.mp4")feasize=1max=200qua=0.05mindis=7blocksize=10usehaar=Truek=0.04paras=dict(maxCorners=200,           qualityLevel=0.05,           minDistance=7,           blockSize=10,           useHarrisDetector=True,           k=0.04)keypoints=list()mask=Nonemarker=Nonedef 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.shape    try:        w,h=imag.shape        #w=w/2        #h=h/2        #print w,h    except:        return None    mask1[y:y+h,x:x+w]=255    keypoints=list()    #kp=cv2.goodFeaturesToTrack(input1,                                #mask1,                                #**paras)    #input1=input1.fromarray    kp=cv2.goodFeaturesToTrack(input1,200,0.04,7)                                      #cv2.goodFeaturesToTrack(image, maxCorners, qualityLevel, minDistance)    if kp is not None and len(kp)>0:        for x,y in np.float32(kp).reshape(-1,2):            keypoints.append((x,y))    return keypointsdef process(image):    grey1=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)    grey=cv2.equalizeHist(grey1)    keypoints=getkpoints(grey,grey1)    #print keypoints    #print image.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.imshow('my',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()
   


    追蹤效果如下:


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.