control_mode = 'run' returMode = 'continue' count = 0 control_uptdatePos = 48 currentSelectionIndex = 0 def movedPosSlided(index, cam): global control_mode oldControl = control_mode control_mode = 'pause' cam.set(cv2.CAP_PROP_POS_FRAMES, index) control_mode = oldControl jasf_cv.setTrackbar('pos', 0, frameCount, onCallBack=lambda i: movedPosSlided(i, cam)) jasf_cv.setTrackbar('start', 0, frameCount) jasf_cv.setTrackbar('end', frameCount, frameCount) jasf_cv.setTrackbar('l/r', 0, 1) def switchLR(): LR = jasf.cv.readTrackbar('l/r') LR = 1 if LR == 0 else 0 jasf.cv.setTrackbarPos('l/r', LR) pos, start, end = -1, -1, -1 while True: waitTime = 50 if control_mode == 'run' else 50 ch = cv2.waitKey(waitTime) & 0xFF
from jasf import jasf_ratFinder import jasf from devika import devika_cv import util from config import video2load cam = cv2.VideoCapture(video2load) jasf.cv.getManyWindows(['G', 'B', 'R', 'H', 'S', 'V'], dim = (180,150), n=(6,6)) jasf.cv.getManyWindows(['Go', 'Bo', 'Ro', 'Ho', 'So', 'Vo'], dim = (180,150), n=(6,6)) jasf.cv.getManyWindows(['out'], dim = (180,150), n=(6,6)) jasf_cv.getSettingsWindow(n=(6,6)) control_filterType = 'free' jasf_cv.setTrackbar('free/band pass', 0, 1) jasf_cv.setTrackbar('l/c', 0, 255) jasf_cv.setTrackbar('u/b', 100, 255) def readSettings(): global control_filterType control_filterType = 'free' if jasf.cv.readTrackbar('free/band pass') == 0 else 'band' lowerb, upperb = -1,-1 if control_filterType == 'free': lowerb = jasf.cv.readTrackbar('l/c') upperb = jasf.cv.readTrackbar('u/b') else: center = jasf.cv.readTrackbar('l/c') band = jasf.cv.readTrackbar('u/b') lowerb = center - band
from devika import devika_cv from util import DetectMovement from config import video2load cam = cv2.VideoCapture('../video/mp4/selected/camereMoves.mp4') cam = cv2.VideoCapture('../video/mp4/selected/notMoving.mp4') cam = cv2.VideoCapture('../video/mp4/selected/walkingInTheBack.mp4') cam = cv2.VideoCapture('../video/mp4/selected/camereMoves2.mp4') cam = cv2.VideoCapture('../video/avi/myFavoriteVideo.avi') cam = cv2.VideoCapture(video2load) jasf_cv.getNewWindow('input') jasf_cv.getNewWindow('output') jasf_cv.getNewWindow('settings') jasf_cv.setTrackbar('movingTh', 2, 10) jasf_cv.setTrackbar('warningTh', 15, 100) jasf_cv.setTrackbar('dangerTh', 85, 100) jasf_cv.setTrackbar('waitTime', 200, 360) jasf_cv.setTrackbar('sx', 40, 100) jasf_cv.setTrackbar('sy', 40, 100) def readSettings(): th1 = cv2.getTrackbarPos('movingTh', 'settings') th2 = cv2.getTrackbarPos('warningTh', 'settings')*0.01 th3 = cv2.getTrackbarPos('dangerTh', 'settings')*0.01 time = cv2.getTrackbarPos('waitTime', 'settings') sx = max(1,cv2.getTrackbarPos('sx', 'settings')) sy = max(1,cv2.getTrackbarPos('sy', 'settings')) return th1, th2,th3,time, sx, sy
"""Function to be called when video trackbar is moved. It will re initializate the global variable cam""" global cam, control_mode control_mode = 'pause' cam.release() fn = videoFiles[index].absolute().as_posix() print 'opening', fn cam = cv2.VideoCapture(fn) control_mode = 'run' jasf_cv.getNewWindow('input') jasf_cv.getNewWindow('output') jasf_cv.getNewWindow('settings') ##################################### #set trackbars ##################################### jasf_cv.setTrackbar('video file', 0, len(videoFiles)-1, onCallBack = onVideoChange, window_name='settings') while cam.isOpened(): waitTime = 5 if control_mode == 'run' else 50 ch = cv2.waitKey(waitTime) & 0xFF if ch == ord('q'): print 'finishing due to user input' break if ch == ord('p'): control_mode = 'run' if control_mode == 'pause' else 'pause' if control_mode == 'run': ret,frame = cam.read() if ret == False: control_mode = 'pause' continue
##################################### def onVideoChange(index): """Function to be called when video trackbar is moved. It will re initializate the global variable cam""" global cam, control_mode control_mode = 'pause' cam.release() fn = videoFiles[index].absolute().as_posix() print 'opening', fn cam = cv2.VideoCapture(fn) control_mode = 'run' ##################################### #set trackbars ##################################### jasf_cv.setTrackbar('video file', 0, len(videoFiles)-1, onCallBack = onVideoChange, window_name='settings2') jasf_cv.setTrackbar('pause', 0, 1, window_name='settings2') jasf_cv.setTrackbar('l/r', 0, 1,window_name = 'settings2') jasf.cv.setManyTrackbars(['h_step', 'v_step'], [100,100], [500,500],windowName = 'settings2') #create one trackbar for each bar(horizontal and vertical) jasf.cv.setManyTrackbars(['horizontal'+str(i) for i in (1,2,3,4)], startList=[int(x*1000) for x in (0.2,0.4,0.6,0.8)], maxList=[1000 for _ in (1,2,3,4)]) jasf.cv.setManyTrackbars(['vertical' +str(i) for i in (1,2,3,4)], startList=[int(x*1000) for x in (0.2,0.4,0.6,0.8)], maxList=[1000 for _ in (1,2,3,4)]) ##################################### #required variables ##################################### input = 0 horizontalsColors = [(0,0,255),(0,0,255), (0,255,255),(0,255,255) ] verticalColors = [(255,0,0),(255,0,0), (255,255,0),(255,255,0) ]
global cam, control_mode control_mode = 'pause' cam.release() fn = videoFiles[index].absolute().as_posix() print 'opening', fn cam = cv2.VideoCapture(fn) control_mode = 'run' jasf_cv.getNewWindow('input') jasf_cv.getNewWindow('output') jasf_cv.getNewWindow('settings') ##################################### #set trackbars ##################################### w,h = jasf.cv.getVideoCaptureFrameHeightWidth(cam) jasf_cv.setTrackbar('video file', 0, len(videoFiles)-1, onCallBack = onVideoChange, window_name='settings') jasf.cv.setManyTrackbars(['row', 'column', 's'], [133, 100,5], [h-1, w-1,20]) jasf_cv.setTrackbar('th', 32, 120) def readSettings(): return jasf.cv.readManyTrackbars(['row', 'column', 's', 'th']) bGetter = getGBR_componentOperation('b') ######################################### #Initialize plot for data ######################################### import matplotlib.pyplot as plt plot, ax = plt.subplots(2,4) ax[0][0].set_xlabel('index in row') ax[1][0].set_xlabel('index in column')
templates[TCB+LCR].addTemplate(tpl) #show selected template on screen img2show = cv2.cvtColor(input, cv2.COLOR_GRAY2BGR) cv2.rectangle(img2show,(x-winSize, y-winSize), (x+winSize, y+winSize), templateColorMap[TCB+LCR], 2) cv2.imshow('output', img2show) jasf_cv.getNewWindow('output') jasf_cv.getNewWindow('settings') cv2.namedWindow('output') cv2.setMouseCallback('output', onMouseDblClk) def doNothing(val): pass TCB_track = jasf_cv.setTrackbar('Top/Bottom', 0, 1) LCR_track = jasf_cv.setTrackbar('Left/Center/Rght', 0, 2) jasf_cv.setTrackbar('th', 40, 500) TCB_map = {0:'T', 1:'B'} LCR_map = {0:'L', 1:'C', 2:'R'} TCB_map_inverse = {a[1]:a[0] for a in TCB_map.items()} LCR_map_inverse = {a[1]:a[0] for a in LCR_map.items()} def readSettings(): TCB = TCB_map[cv2.getTrackbarPos(TCB_track, 'settings')] LCR = LCR_map[cv2.getTrackbarPos(LCR_track, 'settings')] return TCB, LCR
#create windows to display results window_input, window_trackbar, window_output = jasf_cv.getBasicWindows() def nothing(x): pass #create track bars to stabilish color limits mode = 'manual' def onModeChange(opt): global mode mode = 'manual' if opt == 0 else 'mouse' print 'mode changed to', mode jasf_cv.setTrackbar('manual/mouse mode', 0,1, onCallBack = onModeChange) jasf_cv.setTrackbar('Hu', 50, 180) jasf_cv.setTrackbar('Su', 50, 255) jasf_cv.setTrackbar('Vu', 50, 255) jasf_cv.setTrackbar('Hl', 0, 180) jasf_cv.setTrackbar('Sl', 0, 255) jasf_cv.setTrackbar('Vl', 0, 255) jasf_cv.setTrackbar('delta H', 40, 100) jasf_cv.setTrackbar('delta S', 40, 100) jasf_cv.setTrackbar('delta V', 20, 100)
#control variables control_mode = 'run' def onVideoChange(index): """Function to be called when video trackbar is moved. It will re initializate the global variable cam""" global cam, control_mode control_mode = 'pause' cam.release() fn = videoFiles[index].absolute().as_posix() print 'opening', fn cam = cv2.VideoCapture(fn) control_mode = 'run' jasf_cv.setTrackbar('video file', 0, len(videoFiles)-1, onCallBack = onVideoChange) jasf_cv.setTrackbar('pause', 0, 1) jasf_cv.setTrackbar('positive', 0, 1) jasf_cv.setTrackbar('width', 0, 50) jasf_cv.setTrackbar('height', 0, 50) input = 0 lastPositiveSaved = len(list(p for p in pathlib.Path('./samples/positive/').iterdir() if p.suffix == '.png')) lastNegativeSaved = len(list(p for p in pathlib.Path('./samples/negative/').iterdir() if p.suffix == '.png')) def readSettings(): settings = dict() settings['w'] = jasf.cv.readTrackbar('width') settings['h'] = jasf.cv.readTrackbar('height') settings['positive'] = True if jasf.cv.readTrackbar('positive') == 1 else 0
outputWindow = jasf_cv.getNewWindow('Probabilistic Hough Line') track_window = jasf_cv.getNewWindow('settings') cannyWindow = jasf_cv.getNewWindow('Canny') houghSettings_window = jasf_cv.getNewWindow('HoughLineSettings') def onControlChange(opt): if opt == 0: print 'changing mode to Probabilistic Hough Transform' else: print 'changing mode to Standard Hough Transform' control_hough_mode = opt #general settings jasf_cv.setTrackbar('blur_size', 3, 17) jasf_cv.setTrackbar('th_min', 100, 255) jasf_cv.setTrackbar('th_max', 150, 255) jasf_cv.setTrackbar('Prob/Standard Hough', 1, 1, onCallBack = onControlChange) jasf_cv.setTrackbar('th', 80, 255) jasf_cv.setTrackbar('minLength', 50, 200) jasf_cv.setTrackbar('maxLineGap', 5, 20) #settings for hough transform jasf_cv.setTrackbar('minAngle', 0, 30, window_name = houghSettings_window) jasf_cv.setTrackbar('maxAngle', 5, 30, window_name = houghSettings_window) jasf_cv.setTrackbar('myFilter?', 1, 1, window_name = houghSettings_window) jasf_cv.setTrackbar('myFilter_max', 54, 100, window_name = houghSettings_window) def readSettings():
from config import video2load cam = cv2.VideoCapture(video2load) Bwindow = jasf_cv.getNewWindow('Blue Component') Gwindow = jasf_cv.getNewWindow('Green component') Rwindow = jasf_cv.getNewWindow('Red component') Hwindow = jasf_cv.getNewWindow('Hue Component') Swindow = jasf_cv.getNewWindow('Saturation component') Vwindow = jasf_cv.getNewWindow('Value component') jasf_cv.getNewWindow('canny') jasf_cv.getNewWindow('settings') jasf_cv.setTrackbar('canny_min') jasf_cv.setTrackbar('canny_max') while cam.isOpened(): canny_min = cv2.getTrackbarPos('canny_min', 'settings') canny_max = cv2.getTrackbarPos('canny_max', 'settings') ret, frame = cam.read() B, G, R = cv2.split(frame) hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) H, S, V = cv2.split(hsv) canny = cv2.Canny(cv2.equalizeHist(V), canny_min, canny_max)
import util from config import video2load cam = cv2.VideoCapture(video2load) jasf.cv.getManyWindows(['G', 'B', 'R', 'H', 'S', 'V'], dim=(180, 150), n=(6, 6)) jasf.cv.getManyWindows(['Go', 'Bo', 'Ro', 'Ho', 'So', 'Vo'], dim=(180, 150), n=(6, 6)) jasf.cv.getManyWindows(['out'], dim=(180, 150), n=(6, 6)) jasf_cv.getSettingsWindow(n=(6, 6)) control_filterType = 'free' jasf_cv.setTrackbar('free/band pass', 0, 1) jasf_cv.setTrackbar('l/c', 0, 255) jasf_cv.setTrackbar('u/b', 100, 255) def readSettings(): global control_filterType control_filterType = 'free' if jasf.cv.readTrackbar( 'free/band pass') == 0 else 'band' lowerb, upperb = -1, -1 if control_filterType == 'free': lowerb = jasf.cv.readTrackbar('l/c') upperb = jasf.cv.readTrackbar('u/b') else: center = jasf.cv.readTrackbar('l/c') band = jasf.cv.readTrackbar('u/b')
from devika import devika_cv from util import DetectMovement from config import video2load cam = cv2.VideoCapture('../video/mp4/selected/camereMoves.mp4') cam = cv2.VideoCapture('../video/mp4/selected/notMoving.mp4') cam = cv2.VideoCapture('../video/mp4/selected/walkingInTheBack.mp4') cam = cv2.VideoCapture('../video/mp4/selected/camereMoves2.mp4') cam = cv2.VideoCapture('../video/avi/myFavoriteVideo.avi') cam = cv2.VideoCapture(video2load) jasf_cv.getNewWindow('input') jasf_cv.getNewWindow('output') jasf_cv.getNewWindow('settings') jasf_cv.setTrackbar('movingTh', 2, 10) jasf_cv.setTrackbar('warningTh', 15, 100) jasf_cv.setTrackbar('dangerTh', 85, 100) jasf_cv.setTrackbar('waitTime', 200, 360) jasf_cv.setTrackbar('sx', 40, 100) jasf_cv.setTrackbar('sy', 40, 100) def readSettings(): th1 = cv2.getTrackbarPos('movingTh', 'settings') th2 = cv2.getTrackbarPos('warningTh', 'settings') * 0.01 th3 = cv2.getTrackbarPos('dangerTh', 'settings') * 0.01 time = cv2.getTrackbarPos('waitTime', 'settings') sx = max(1, cv2.getTrackbarPos('sx', 'settings')) sy = max(1, cv2.getTrackbarPos('sy', 'settings'))
cv2.rectangle(img2show, (x - 10, y - 10), (x + 10, y + 10), templateColorMap[TCB + LCR], 2) cv2.imshow('output', img2show) jasf_cv.getNewWindow('output') jasf_cv.getNewWindow('settings') cv2.namedWindow('output') cv2.setMouseCallback('output', onMouseDblClk) def doNothing(val): pass TCB_track = jasf_cv.setTrackbar('Top/Bottom', 0, 1) LCR_track = jasf_cv.setTrackbar('Left/Center/Rght', 0, 2) jasf_cv.setTrackbar('th', 40, 500) TCB_map = {0: 'T', 1: 'B'} LCR_map = {0: 'L', 1: 'C', 2: 'R'} def readSettings(): TCB = TCB_map[cv2.getTrackbarPos(TCB_track, 'settings')] LCR = LCR_map[cv2.getTrackbarPos(LCR_track, 'settings')] return TCB, LCR while cam.isOpened():
print 'opening', fn cam = cv2.VideoCapture(fn) control_mode = 'run' def onVideoPositionChange(index, cam): control_mode = 'pause' cam.set(cv2.CAP_PROP_POS_FRAMES, index) control_mode = 'run' jasf_cv.getNewWindow('input') jasf_cv.getNewWindow('output') jasf_cv.getNewWindow('settings') ##################################### #set trackbars ##################################### jasf_cv.setTrackbar('video file', 0, len(videoFiles)-1, onCallBack = onVideoChange, window_name='settings') jasf_cv.setTrackbar('pos', 0, int(cam.get(cv2.CAP_PROP_FRAME_COUNT)), onCallBack = lambda i: onVideoPositionChange(i, cam)) counter = 0 control_FPS = int(cam.get(cv2.CAP_PROP_FPS)) while cam.isOpened(): waitTime = 5 if control_mode == 'run' else 50 ch = cv2.waitKey(waitTime) & 0xFF if ch == ord('q'): print 'finishing due to user input' break if ch == ord('p'): control_mode = 'run' if control_mode == 'pause' else 'pause' if control_mode == 'run': ret,frame = cam.read() counter += 1
def nothing(x): pass #create track bars to stabilish color limits mode = 'manual' def onModeChange(opt): global mode mode = 'manual' if opt == 0 else 'mouse' print 'mode changed to', mode jasf_cv.setTrackbar('manual/mouse mode', 0, 1, onCallBack=onModeChange) jasf_cv.setTrackbar('Hu', 50, 180) jasf_cv.setTrackbar('Su', 50, 255) jasf_cv.setTrackbar('Vu', 50, 255) jasf_cv.setTrackbar('Hl', 0, 180) jasf_cv.setTrackbar('Sl', 0, 255) jasf_cv.setTrackbar('Vl', 0, 255) jasf_cv.setTrackbar('delta H', 40, 100) jasf_cv.setTrackbar('delta S', 40, 100) jasf_cv.setTrackbar('delta V', 20, 100) window_trackbar = 'settings'
if 0 in control_settings['listOfKnownFrames_with_input']: #read current video file name currentVideoFileName_aux = control_settings['currentVideoFileName'] #find in the user input the one corresponding to the current frame; the returned type is a list userInputForThisFrame = filter(lambda x: x['frame'] == control_settings['framesSinceStart'], userInputData[currentVideoFileName_aux]) askUserForInput(frame, True, userInputForThisFrame[0]) #print a silly msg so we know something was done print 'aha! we avoided that!' else: askUserForInput(frame) resetPlotData() jasf_cv.setTrackbar('video file', 0, len(videoFiles)-1, onCallBack = onVideoChange, window_name='settings') #first load a dictionary with the current configuration and then set all trackbars at once paramDict = dict() with open('./paramDict.json', 'r') as f: paramDict = json.load(f) def onWindowFlowSizeChanged(val): global flowComputerOption, flowComputer if 'windowFlow' in flowComputerOption: print 'changing window size for flow averaging to', val flowComputer.setWindowSize(max(val,1)) for item in paramDict.items(): itemName = item[0] itemVal = item[1]