import cv2 import os from nms import non_max_suppression from util import get_svm_vector rects = {'01.avi': (884, 87, 80, 80), '01.mov': (505, 275, 48, 48), '02.avi': (951, 227, 74, 74), '02.mov': (475, 296, 42, 42), '03.avi': ( 664, 97, 71, 71), '03.mov': (472, 297, 40, 40), '04.avi': (1196, 251, 72, 72), '04.mov': (473, 296, 43, 43)} win_size = (40, 40) block_size = (10, 10) block_stride = (5, 5) cell_size = (5, 5) nbins = 9 # 设置HoG描述子参数 hog = cv2.HOGDescriptor(win_size, block_size, block_stride, cell_size, nbins) hog.setSVMDetector(get_svm_vector('svm_data.xml')) path = '/home/xsyin/videos/' step = 200 count = 0 for file in os.listdir(path): file = file.lower() if file not in rects: continue print "Now is get hard example from " + file rect = rects[file] video_path = path + file file = file[0:2] + file[3:] capture = cv2.VideoCapture(video_path) frame_cout = capture.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT) pos = 15
import cv2 from util import draw_detections, get_svm_vector import os if __name__ == "__main__": detect_path = "./test_performance/" win_size = (40, 40) block_size = (10, 10) block_stride = (5, 5) cell_size = (5, 5) nbins = 9 hog = cv2.HOGDescriptor(win_size, block_size, block_stride, cell_size, nbins) vect = get_svm_vector("data_pos_3496_neg_11777.xml") hog.setSVMDetector(vect) img_name = "03.MOV-3.jpg" # for img_name in os.listdir(detect_path): img = cv2.imread(detect_path + img_name) if img_name.find("avi") >= 0: img = cv2.resize(img, (img.shape[1] / 2, img.shape[0] / 2)) found, w = hog.detectMultiScale(img, winStride=(8, 8), scale=1.05) draw_detections(img, found) cv2.imshow("test", img) if cv2.waitKey(0) & 0xFF == 27: cv2.destroyAllWindows()
from util import draw_detections, get_svm_vector path = '/home/xsyin/video/' if __name__ == '__main__': win_size = (40, 40) block_size = (10, 10) block_stride = (5, 5) cell_size = (5, 5) nbins = 9 hog = cv2.HOGDescriptor(win_size, block_size, block_stride, cell_size, nbins) video_path = path + '02.mp4' vector = get_svm_vector('svm_data.xml') hog.setSVMDetector(vector) cap = cv2.VideoCapture(video_path) i = 0 while True: _, frame = cap.read() if i%100 == 0: found, w = hog.detectMultiScale(frame, winStride=(8, 8), scale=1.02) draw_detections(frame, found) cv2.imshow('video', frame) i += 1 ch = 0xFF & cv2.waitKey(1) if ch == 27: break cap.release()