# -*- coding:UTF-8 -*- import cv2 import numpy as np import time from cv_interface import videoHandle as myv threshold = 50 count = 0 cam = myv(0) #cam.select_image_color() #cv2.destroyAllWindows() mask_pre = np.zeros((80, 60), np.uint8) x_pre = cam.camerawidth/2 y_pre = cam.cameraheight/2 cam.select_image_color() cam.get_image() bkg = cam.frame while(True): cam.get_image() #line18-19 can be swaped cam.frame = cv2.absdiff(cam.frame, bkg) #cam.frame_resize = cv2.resize(cam.frame, (80, 60)) #cam.mask = cv2.threshold(cam.frame_resize, threshold , 255, cv2.THRESH_BINARY)[1] cam.mask = cv2.cvtColor(cam.frame, cv2.COLOR_BGR2GRAY) ret, cam.mask = cv2.threshold(cam.mask, threshold , 255, cv2.THRESH_BINARY) #cam.mask = cv2.morphologyEx(cam.mask, cv2.MORPH_OPEN, np.ones((7,7), np.uint8)) #cv2.imshow('mask',cam.mask) #cv2.waitKey(1) cam.findcenter_image() #detect the glob if cam.moments['m00'] != 0:
# ---------------------------------- # File Name : mv_blurcatch_diff.py # Purpose : # Creation Date : 16-03-2016 # Last Modified : Thu Mar 17 22:03:30 2016 # Created By : Jeasine Ma # --------------------------------- import numpy as np import cv2 from functools import wraps from cv_interface import videoHandle as myv from move_interface import carHandle as myc from decos_interface import decos #car = myc(0, 9600) cam = myv(1) #cam.select_image_color() #car.send_cmd(0, 0) #mask_pre = np.zeros((cam.cameraheight, cam.camerawidth), np.float32) frame_pre_1 = np.zeros((cam.cameraheight, cam.camerawidth), np.uint8) frame_pre_3 = np.zeros((cam.cameraheight, cam.camerawidth, 3), np.uint8) x_pre = cam.camerawidth/2 y_pre = cam.cameraheight/2 """ 1.尝试背景剪除法,直接剪除背景,不用二值化 效果见/Desktop/1.png 2.尝试黑白帧差法,考虑运动速度,建议用此法,效果见/Desktop/2.png 2+.测试黑白帧差法的速度,注意到网球的颜色较浅,与背景颜色近似,剪除效果不佳 3-.重新尝试现有算法在判断运动方向上的问题,并测量帧率,先把图像压缩一下 3.编写黑白帧差法获得运动方向的算法 使用帧差法作为检测出现的的算法,接下来交由动态阈值二值化处理