OpenCV3.2 編譯extra & Python模塊

這裏寫圖片描述
這裏寫圖片描述
這裏寫圖片描述
這裏寫圖片描述




Python 下用調用opencv KCF進行目標跟蹤

  1. 將OpenCV_Source\lib\python3\Release\cv2.cp35-win_amd64.pyd 文件更名爲: cv2.pyd,然後複製到 Anaconda3\Lib\site-packages 文件夾下

  2. 運行以下代碼:

import cv2
import sys

if __name__ == '__main__':

    # Set up tracker.
    # Instead of MIL, you can also use
    # BOOSTING, KCF, TLD, MEDIANFLOW or GOTURN

    tracker = cv2.Tracker_create("KCF")

    # Read video
    video = cv2.VideoCapture("egtest01.avi")

    # Exit if video not opened.
    if not video.isOpened():
        print("Could not open video")
        sys.exit()

    # Read first frame.
    ok, frame = video.read()
    if not ok:
        print('Cannot read video file')
        sys.exit()

    # Define an initial bounding box
    bbox = (137, 176, 40, 41)

    # Uncomment the line below to select a different bounding box
    # bbox = cv2.selectROI(frame, False)

    # Initialize tracker with first frame and bounding box
    ok = tracker.init(frame, bbox)

    while True:
        # Read a new frame
        ok, frame = video.read()
        if not ok:
            break

        # Update tracker
        ok, bbox = tracker.update(frame)

        # Draw bounding box
        if ok:
            p1 = (int(bbox[0]), int(bbox[1]))
            p2 = (int(bbox[0] + bbox[2]), int(bbox[1] + bbox[3]))
            cv2.rectangle(frame, p1, p2, (0, 0, 255))

        # Display result
        cv2.imshow("Tracking", frame)

        # Exit if ESC pressed
        k = cv2.waitKey(1) & 0xff
        if k == 27: break

這裏寫圖片描述

  1. 不知爲何 GOTURN 目前跑有bug,提示
    Requested blob “.data1” not found in function cv::dnn::Net::setBlob

而在openCV源碼中有以下代碼:

net.setBlob(".data1", targetBlob);
net.setBlob(".data2", searchBlob);


Reference

  1. http://www.learnopencv.com/
  2. GOTURN模型下載
    https://github.com/opencv/opencv_extra/tree/c4219d5eb3105ed8e634278fad312a1a8d2c182d/testdata/tracking
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章