def setup_cortex(self, cortex_left, cortex_right): #Create and prepare cortex self.C = Cortex() lp = join(datadir, "cortices", "{0}loc.pkl".format(cortex_left)) rp = join(datadir, "cortices", "{0}loc.pkl".format(cortex_right)) self.C.loadLocs(lp, rp) self.C.loadCoeffs( join(datadir, "cortices", "{0}coeff.pkl".format(cortex_left)), join(datadir, "cortices", "{0}coeff.pkl".format(cortex_right)))
class CorticalMapping: def __init__(self): self.R = None self.C = None self.fixation = None def setup_cortex(self, cortex_left, cortex_right): #Create and prepare cortex self.C = Cortex() lp = join(datadir, "cortices", "{0}loc.pkl".format(cortex_left)) rp = join(datadir, "cortices", "{0}loc.pkl".format(cortex_right)) self.C.loadLocs(lp, rp) self.C.loadCoeffs( join(datadir, "cortices", "{0}coeff.pkl".format(cortex_left)), join(datadir, "cortices", "{0}coeff.pkl".format(cortex_right))) def setup_retina(self, retina_resolution): #Create and load retina self.R = Retina() self.R.info() self.R.loadLoc( join(datadir, "retinas", "{0}_loc.pkl".format(retina_resolution))) self.R.loadCoeff( join(datadir, "retinas", "{0}_coeff.pkl".format(retina_resolution))) # img = cv2.imread("{}/examples/mario.png".format(os.getcwd()), cv2.IMREAD_COLOR) # print(os.getcwd()) # print(type(img)) #Prepare retina # x = img.shape[1]/2 # y = img.shape[0]/2 # print("X: ", x) # print("Y: ", y) # print("Retina shape: ", img.shape) x = 120.0 y = 112.0 self.fixation = (y, x) self.R.prepare((224, 240, 3), self.fixation) def cortical_transform(self, im_array): V = self.R.sample(im_array, self.fixation) cimg = self.C.cort_img(V) # print("Cimg type: ", type(cimg)) return cimg def backproject_transform(self, im_array): V = self.R.sample(im_array, self.fixation) tight = self.R.backproject_tight_last() # print("Cimg type: ", type(cimg)) return tight def arr_to_img(self, img_arr, index): cv2.imwrite( "{}/test_images/test_image_{}.jpg".format(os.getcwd(), index), img_arr)
def createCortex(): """Instantiates Cortex object and loads necessary files""" cortex = Cortex(isGPUAvailable()) lp = join(datadir, "cortices", "50k_Lloc_tight.pkl") rp = join(datadir, "cortices", "50k_Rloc_tight.pkl") cortex.loadLocs(lp, rp) cortex.loadCoeffs(join(datadir, "cortices", "50k_Lcoeff_tight.pkl"), join(datadir, "cortices", "50k_Rcoeff_tight.pkl")) return cortex
ret, campic = cap.read() #Create and load retina R = Retina() R.info() R.loadLoc(join(datadir, "retinas", "ret50k_loc.pkl")) R.loadCoeff(join(datadir, "retinas", "ret50k_coeff.pkl")) #Prepare retina x = campic.shape[1] / 2 y = campic.shape[0] / 2 fixation = (y, x) R.prepare(campic.shape, fixation) #Create and prepare cortex C = Cortex() lp = join(datadir, "cortices", "50k_Lloc_tight.pkl") rp = join(datadir, "cortices", "50k_Rloc_tight.pkl") C.loadLocs(lp, rp) C.loadCoeffs(join(datadir, "cortices", "50k_Lcoeff_tight.pkl"), join(datadir, "cortices", "50k_Rcoeff_tight.pkl")) while True: ret, img = cap.read() if ret is True: img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) V = R.sample(img, fixation) #tight = R.backproject_tight_last() tight = R.backproject_last()
from retinavision.retina import Retina from retinavision.cortex import Cortex from retinavision import datadir, utils from os.path import join import datetime beforeTime = datetime.datetime.now() # Create and load retina R = Retina(gpu=False) R.info() R.loadLoc(join(datadir, "retinas", "ret50k_loc.pkl")) R.loadCoeff(join(datadir, "retinas", "ret50k_coeff.pkl")) # R.loadLoc(join(datadir, "retinas", "8k_loc.pkl")) # R.loadCoeff(join(datadir, "retinas", "8k_coeff.pkl")) # Create and prepare cortex C = Cortex(gpu=False) lp = join(datadir, "cortices", "50k_Lloc_tight.pkl") rp = join(datadir, "cortices", "50k_Rloc_tight.pkl") # lp = join(datadir, "cortices", "8k_cort_leftloc.pkl") # rp = join(datadir, "cortices", "8k_cort_rightloc.pkl") C.loadLocs(lp, rp) C.loadCoeffs(join(datadir, "cortices", "50k_Lcoeff_tight.pkl"), join(datadir, "cortices", "50k_Rcoeff_tight.pkl")) # C.loadCoeffs(join(datadir, "cortices", "8k_cort_leftcoeff.pkl"), # join(datadir, "cortices", "8k_cort_rightcoeff.pkl")) # fixation=None cap = cv2.VideoCapture(0) # cap is the capture object (global) ret, campic = cap.read() # Prepare retina