Ejemplo n.º 1
0
def vPrep(fname, saveDir, check=True):
    fileName = va.getFileName(fname)
    aviProps = va.getAVIinfo(fname)
    plt.ion()

    # fBackground frames
    # -----------------
    # Default values
    nFrames = 10

    bgOK = False
    bgFile = saveDir + "/bg.npy"
    if os.path.isfile(bgFile):
        print("Background file exists, loading...")
        bg = np.load(bgFile)
    else:
        print("Generating background with default settings...")
        bg = va.getBg(fname, aviProps, nFrames)
    if check:
        while not bgOK:
            plt.figure()
            plt.imshow(bg)
            plt.set_cmap('gray')
            plt.show()
            uDecision = raw_input("Background OK? [y]es; [n]o ")
            if uDecision == 'y':
                bgOK = True
            else:
                uframes = raw_input("Select number of frames ")
                bg = va.getBg(fname, aviProps, int(uframes))
    np.save(saveDir + 'bg', bg)
    print('Background file saved')

    # Threshold
    # --------------
    # Default values
    ths = 40
    morphDiameter = 10

    pmtsFileExists = False
    thsOK = False
    pmtsFile = saveDir + "/pmts.npy"
    if os.path.isfile(pmtsFile):
        print("Parameters file exists, loading...")
        pmtsFileExists = True
        filePmts = np.load(pmtsFile)
        ths, morphDiameter = va.setThreshold(fname, aviProps, bg,
                                             filePmts[0][0], filePmts[1][0])
    else:
        print("Generating threshold with default settings...")
        ths, morphDiameter = va.setThreshold(fname, aviProps, bg, ths,
                                             morphDiameter)
    if check:
        while not thsOK:
            uDecision = raw_input("Threshold OK? [y]es; [n]o ")
            if uDecision == 'y':
                thsOK = True
            else:
                while True:
                    try:
                        print "Current threshold is", ths
                        uths = int(raw_input("Select new threshold "))
                        print "Current diameter is", morphDiameter
                        umorph = int(
                            raw_input(
                                "Select new diameter to erode and dilate "))
                        break
                    except ValueError:
                        print("Invalid number, please try again ")
                ths, morphDiameter = va.setThreshold(fname, aviProps, bg, uths,
                                                     umorph)

    # Arena areas
    # --------------
    # Default values
    nestPos = [125, 220]
    nestArea = [(1, 320), (225, 320), (120, 125)]
    arenaCenter = [600, 244]
    foodArea = [(785, 360), (960, 360), (860, 185)]

    plt.ioff()
    arenaOk = False
    if pmtsFileExists:
        print("Using parameters file...")
        va.plotArena(aviProps, filePmts, bg)
        pmts = [[ths], [morphDiameter], filePmts[2], filePmts[3], filePmts[4],
                filePmts[5]]
    else:
        print("Generating arena with default settings...")
        pmts = [[ths], [morphDiameter], nestPos, nestArea, arenaCenter,
                foodArea]
        va.plotArena(aviProps, pmts, bg)
    if check:
        while not arenaOk:
            uDecision = raw_input("Arena OK? [y]es; [n]o ")
            if uDecision == 'y':
                arenaOk = True
            else:
                print("Select new arena ")
                points = va.setPoints(fname, aviProps, bg)
                pmts = [[ths], [morphDiameter], points[0], points[1],
                        points[2], points[3]]

    #print pmts[0], pmts[1]
    #fsaveName = saveDir + fileName.rstrip(".avi") + "_pmts"
    np.save(saveDir + 'pmts', pmts)
    print('Parameters file saved')
Ejemplo n.º 2
0
nfile = sys.argv[4]
ncall = sys.argv[5]
if len(nfile) == 1:
    nfile = '00' + nfile
elif len(nfile) == 2:
    nfile = '0' + nfile
if len(ncall) == 1:
    ncall = '00' + ncall
elif len(ncall) == 2:
    ncall = '0' + ncall
secPerCpu = float(sys.argv[6])

nestThreshold = 10
aviProps = va.getAVIinfo(fname)
print fname, aviProps
fileName = va.getFileName(fname)
trackFname = saveDir + 'file' + str(nfile) + '_' + ncall + '.txt'
aviFname = saveDir + 'file' + str(nfile) + '_' + ncall + '.avi'
bgSubFname = saveDir + 'file' + str(nfile) + '_' + ncall

tStart = va.frame2time(startFrame, aviProps) + (int(ncall) - 1) * secPerCpu
tEnd = tStart + secPerCpu
print tStart, tEnd
while True:
    try:
        print(saveDir + "bg.npy")
        bg = np.load(saveDir + "bg.npy")
        print("Background file loaded")
    except IOError:
        print("Cannot find background file ")
        break
Ejemplo n.º 3
0
def vPrep(fname, saveDir, check=True):
  fileName = va.getFileName(fname)
  aviProps = va.getAVIinfo(fname)
  plt.ion()

  # fBackground frames
  # -----------------
  # Default values
  nFrames = 10

  bgOK = False
  bgFile = saveDir + "/bg.npy"
  if os.path.isfile(bgFile):
    print("Background file exists, loading...")
    bg = np.load(bgFile)
  else:
    print("Generating background with default settings...")
    bg  = va.getBg(fname, aviProps, nFrames)
  if check:
    while not bgOK:
      plt.figure()
      plt.imshow(bg)
      plt.set_cmap('gray')
      plt.show()
      uDecision = raw_input("Background OK? [y]es; [n]o ")
      if uDecision=='y': 
          bgOK = True
      else:
          uframes = raw_input("Select number of frames ")
          bg  = va.getBg(fname, aviProps, int(uframes))
  np.save(saveDir + 'bg', bg)
  print('Background file saved')

  # Threshold
  # --------------
  # Default values
  ths = 40
  morphDiameter = 10

  pmtsFileExists = False
  thsOK = False
  pmtsFile = saveDir + "/pmts.npy"
  if os.path.isfile(pmtsFile):
    print("Parameters file exists, loading...")
    pmtsFileExists = True
    filePmts = np.load(pmtsFile)
    ths, morphDiameter = va.setThreshold(fname, aviProps, bg, filePmts[0][0], filePmts[1][0])
  else:
    print("Generating threshold with default settings...")
    ths, morphDiameter = va.setThreshold(fname, aviProps, bg, ths, morphDiameter)
  if check:
    while not thsOK:
      uDecision = raw_input("Threshold OK? [y]es; [n]o ")
      if uDecision=='y': 
          thsOK = True
      else:
          while True:
              try:
                  print "Current threshold is", ths
                  uths = int(raw_input("Select new threshold "))
                  print "Current diameter is", morphDiameter
                  umorph = int(raw_input("Select new diameter to erode and dilate "))
                  break
              except ValueError:
                  print("Invalid number, please try again ")
          ths, morphDiameter = va.setThreshold(fname, aviProps, bg, uths, umorph)

  # Arena areas
  # --------------
  # Default values
  nestPos = [125, 220]
  nestArea = [(1,320),(225,320),(120,125)]
  arenaCenter = [600,244]
  foodArea = [(785,360),(960,360),(860,185)]

  plt.ioff()
  arenaOk = False
  if pmtsFileExists:
    print("Using parameters file...")
    va.plotArena(aviProps, filePmts, bg)
    pmts = [[ths], [morphDiameter], filePmts[2], filePmts[3], filePmts[4], filePmts[5]]
  else:
    print("Generating arena with default settings...")
    pmts = [[ths], [morphDiameter], nestPos, nestArea, arenaCenter, foodArea]
    va.plotArena(aviProps, pmts, bg)
  if check:
    while not arenaOk:
      uDecision = raw_input("Arena OK? [y]es; [n]o ")
      if uDecision=='y':
          arenaOk = True
      else:
          print("Select new arena ")	
          points = va.setPoints(fname, aviProps, bg)
          pmts = [[ths], [morphDiameter], points[0], points[1], points[2], points[3]]

  #print pmts[0], pmts[1]
  #fsaveName = saveDir + fileName.rstrip(".avi") + "_pmts"
  np.save(saveDir + 'pmts', pmts)
  print('Parameters file saved')
Ejemplo n.º 4
0
nfile = sys.argv[4]
ncall = sys.argv[5]
if len(nfile)==1: 
    nfile='00'+nfile
elif len(nfile)==2:
    nfile='0'+nfile
if len(ncall)==1: 
    ncall='00'+ncall
elif len(ncall)==2:
    ncall='0'+ncall
secPerCpu = float(sys.argv[6])

nestThreshold = 10
aviProps = va.getAVIinfo(fname)
print fname, aviProps
fileName = va.getFileName(fname)
trackFname = saveDir + 'file' + str(nfile) + '_' + ncall + '.txt'
aviFname = saveDir + 'file' + str(nfile) + '_' + ncall + '.avi'
bgSubFname = saveDir + 'file' + str(nfile) + '_' + ncall

tStart = va.frame2time(startFrame, aviProps) + (int(ncall)-1)*secPerCpu
tEnd = tStart + secPerCpu
print tStart, tEnd
while True:
  try:
      print(saveDir+"bg.npy")
      bg = np.load(saveDir + "bg.npy")
      print("Background file loaded")
  except IOError:
      print("Cannot find background file ")
      break