Esempio n. 1
0
def process_images(imglist, eventfile, ppname, imgdir, plotdir):

  # check if the image directory exists
  if not os.path.isdir(imgdir):
    raise Exception("ERROR: no image directory found; path '%s' does not exist!" % imgdir)

  # check if output directorie exist; if not, create it
  if not os.path.isdir(plotdir):
    os.mkdir(plotdir)

  # EXPERIMENT SPECS
  DISPSIZE = (1920,1080) # (px,px)
  SCREENSIZE = (39.9,29.9) # (cm,cm)
  SCREENDIST = 61.0 # cm
  PXPERCM = numpy.mean([DISPSIZE[0]/SCREENSIZE[0],DISPSIZE[1]/SCREENSIZE[1]]) # px/cm

  # read the file
  smidata = read_smioutput(eventfile, None, ag_mode=SMIModes.LEFT_ONLY, stop=None, debug=False)

  nokey = 0
  processed = 0

  # loop through trials
  for trialnr in range(len(imglist)):
    # load image name, saccades, and fixations
    imgname = imglist[int(trialnr)]
    try:
      saccades = smidata[trialnr]['events']['Esac'] # [starttime, endtime, duration, startx, starty, endx, endy]
      fixations = smidata[trialnr]['events']['Efix'] # [starttime, endtime, duration, endx, endy]
    except KeyError:
      print "No eyetracking data for trial %s (image: %s)" % (trialnr + 1, imgname)
      nokey += 1
      continue
    except IndexError:
      print "No eyetracking data for trial %s (image: %s)" % (trialnr + 1, imgname)
      nokey += 1
      continue

    processed += 1
    
    # paths
    imagefile = os.path.join(imgdir, imgname)

    # rawplotfile = os.path.join(plotdir, "raw_data_%s_%d" % (ppname,trialnr))
    scatterfile = os.path.join(plotdir, "fixations_%s_%d" % (ppname,trialnr))
    scanpathfile =  os.path.join(plotdir, "scanpath_%s_%d" % (ppname,trialnr))
    heatmapfile = os.path.join(plotdir, "heatmap_%s_%d" % (ppname,trialnr))
    
    # raw data points
    # draw_raw(smidata[trialnr]['x'], smidata[trialnr]['y'], DISPSIZE, imagefile=imagefile, savefilename=rawplotfile)

    # fixations
    draw_fixations(fixations, DISPSIZE, imagefile=imagefile, durationsize=True, durationcolour=False, alpha=0.5, savefilename=scatterfile)
    
    # scanpath
    draw_scanpath(fixations, saccades, DISPSIZE, imagefile=imagefile, alpha=0.5, savefilename=scanpathfile)

    # heatmap   
    draw_heatmap(fixations, DISPSIZE, imagefile=imagefile, durationweight=True, alpha=0.75, savefilename=heatmapfile)
  print "%s images processed.  %s sections without eyetracker data." % (processed, nokey)
Esempio n. 2
0
def generate_plots(IMGDIR, PLOTDIR, filename, fixations, saccades, data,
                   DISPSIZE, trialnr):

    # cognitive load
    if int(filename[4:5]) == 1:
        cognitive_load = "LOW"
    else:
        cognitive_load = "HIGH"

    #imgname = "screenshot.jpg"
    #imagefile = os.path.join(IMGDIR,imgname)

    # paths
    rawplotfile = os.path.join(
        PLOTDIR, "raw_data_%s_%s" % (filename[:3], cognitive_load))
    scatterfile = os.path.join(
        PLOTDIR, "fixations_%s_%s" % (filename[:3], cognitive_load))
    scanpathfile = os.path.join(
        PLOTDIR, "scanpath_%s_%s" % (filename[:3], cognitive_load))
    heatmapfile = os.path.join(
        PLOTDIR, "heatmap_%s_%s" % (filename[:3], cognitive_load))

    # raw data points
    draw_raw(data[trialnr]['x'],
             data[trialnr]['y'],
             DISPSIZE,
             imagefile=None,
             savefilename=rawplotfile)

    # fixations
    draw_fixations(fixations,
                   DISPSIZE,
                   imagefile=None,
                   durationsize=True,
                   durationcolour=False,
                   alpha=0.5,
                   savefilename=scatterfile)

    # scanpath
    draw_scanpath(fixations,
                  saccades,
                  DISPSIZE,
                  imagefile=None,
                  alpha=0.5,
                  savefilename=scanpathfile)

    # heatmap
    draw_heatmap(fixations,
                 DISPSIZE,
                 imagefile=None,
                 durationweight=True,
                 alpha=0.5,
                 savefilename=heatmapfile)
Esempio n. 3
0
 def save_all_scanpath(self, bar):
     """
     Saves all scanpaths, due to the number of positions, it applies clustering methods to have a better and more viewable image
     :return: None
     """
     rgb_im = self.image.convert('RGB')
     rgb_im.save('converted_image.jpg')
     dir = self.image_dir + "scanpath_images/"
     if not os.path.exists(dir):
         os.makedirs(dir)
     for u_id in self.user_positions:
         out = dir + u_id + "_scanpath.png"
         pos = self.user_positions[u_id]
         tmp = cluster_points(pos)
         draw_scanpath(tmp, (self.rescaled_width, self.rescaled_height), imagefile='converted_image.jpg', savefilename=out)
         bar.next()
     gc.collect()
     os.remove('converted_image.jpg')
Esempio n. 4
0
        heatmapfile = os.path.join(pplotdir,
                                   "heatmap_%s_%d" % (ppname, trialnr))

        ##raw data points
        #draw_raw(edfdata[trialnr]['x'], edfdata[trialnr]['y'],edfdata[trialnr]['size'], DISPSIZE, imagefile=imagefile, savefilename=rawplotfile)

        #fixations
        draw_fixations(fixations,
                       DISPSIZE,
                       imagefile=imagefile,
                       durationsize=True,
                       durationcolour=True,
                       alpha=0.5,
                       savefilename=scatterfile)

        ##scanpath
        draw_scanpath(fixations,
                      saccades,
                      DISPSIZE,
                      imagefile=imagefile,
                      alpha=0.5,
                      savefilename=scanpathfile)

        # heatmap
        draw_heatmap(fixations,
                     DISPSIZE,
                     imagefile=imagefile,
                     durationweight=True,
                     alpha=0.5,
                     savefilename=heatmapfile)
Esempio n. 5
0
	# PLOTS
	
	print("plotting gaze data")

	# loop through trials
	for trialnr in range(len(data)):
		
		# load image name, saccades, and fixations
		imgname = data[trialnr][header.index("image")]
		saccades = edfdata[trialnr]['events']['Esac'] # [starttime, endtime, duration, startx, starty, endx, endy]
		fixations = edfdata[trialnr]['events']['Efix'] # [starttime, endtime, duration, endx, endy]
		
		# paths
		imagefile = os.path.join(IMGDIR,imgname)
		rawplotfile = os.path.join(pplotdir, "raw_data_%s_%d" % (ppname,trialnr))
		scatterfile = os.path.join(pplotdir, "fixations_%s_%d" % (ppname,trialnr))
		scanpathfile =  os.path.join(pplotdir, "scanpath_%s_%d" % (ppname,trialnr))
		heatmapfile = os.path.join(pplotdir, "heatmap_%s_%d" % (ppname,trialnr))
		
		# raw data points
		draw_raw(edfdata[trialnr]['x'], edfdata[trialnr]['y'], DISPSIZE, imagefile=imagefile, savefilename=rawplotfile)

		# fixations
		draw_fixations(fixations, DISPSIZE, imagefile=imagefile, durationsize=True, durationcolour=False, alpha=0.5, savefilename=scatterfile)
		
		# scanpath
		draw_scanpath(fixations, saccades, DISPSIZE, imagefile=imagefile, alpha=0.5, savefilename=scanpathfile)

		# heatmap		
		draw_heatmap(fixations, DISPSIZE, imagefile=imagefile, durationweight=True, alpha=0.5, savefilename=heatmapfile)
Esempio n. 6
0
def read_files(reduced, csvonly):

    # Loop through all files
    for ppname in PPS:
        print("loading gaze data")

        # path
        fp = os.path.join(DATADIR, '%s.tsv' % ppname)

        # check if the path exist
        if not os.path.isfile(fp):
            raise Exception(
                "No eye data file file found for participant '%s'" % (ppname))

        # read the file
        tobiidata = read_tobii(fp, reduced, missing=0.0, debug=True)

        #save_csv(tobiidata)

        pplotdir = os.path.join(PLOTDIR, ppname[:3])

        if not csvonly:
            print("plotting gaze data")

        # Loop through trials
        for trialnr in range(len(tobiidata)):

            # Load image name, saccades, and fixations
            imgname = "screenshot.jpg"
            imagefile = os.path.join(IMGDIR, imgname)
            print(imagefile)
            # [starttime, endtime, duration, startx, starty, endx, endy]
            saccades = tobiidata[trialnr]['events']['Esac']
            # [starttime, endtime, duration, endx, endy]
            fixations = tobiidata[trialnr]['events']['Efix']

            # cognitive load
            if int(ppname[4:5]) == 1:
                cognitive_load = "LOW"
            else:
                cognitive_load = "HIGH"
            if reduced:
                suffix = "_reduced"
            else:
                suffix = ""

            # Save the fixation and saccades in csv format for MATLAB
            save_csv(fixations, saccades, ppname, suffix)

            if not csvonly:
                # paths
                rawplotfile = os.path.join(
                    pplotdir,
                    "raw_data_%s_%s%s" % (ppname[:3], cognitive_load, suffix))
                scatterfile = os.path.join(
                    pplotdir,
                    "fixations_%s_%s%s" % (ppname[:3], cognitive_load, suffix))
                scanpathfile = os.path.join(
                    pplotdir,
                    "scanpath_%s_%s%s" % (ppname[:3], cognitive_load, suffix))
                heatmapfile = os.path.join(
                    pplotdir,
                    "heatmap_%s_%s%s" % (ppname[:3], cognitive_load, suffix))

                # raw data points
                draw_raw(tobiidata[trialnr]['x'],
                         tobiidata[trialnr]['y'],
                         DISPSIZE,
                         imagefile=None,
                         savefilename=rawplotfile)

                # fixations
                draw_fixations(fixations,
                               DISPSIZE,
                               imagefile=None,
                               durationsize=True,
                               durationcolour=False,
                               alpha=0.5,
                               savefilename=scatterfile)

                # scanpath
                draw_scanpath(fixations,
                              saccades,
                              DISPSIZE,
                              imagefile=None,
                              alpha=0.5,
                              savefilename=scanpathfile)

                # heatmap
                draw_heatmap(fixations,
                             DISPSIZE,
                             imagefile=None,
                             durationweight=True,
                             alpha=0.5,
                             savefilename=heatmapfile)