Example #1
0
    def test_imagevector_integrity(self):
        print(
            "Testing imagevector integrity over storing in model and storing in file..."
        )
        cap = utils.camopen()
        ret, campic = cap.read()

        R = Retina()
        R.info()
        R.loadLoc(os.path.join(datadir, "retinas", "ret50k_loc.pkl"))
        R.loadCoeff(os.path.join(datadir, "retinas", "ret50k_coeff.pkl"))

        x = campic.shape[1] / 2
        y = campic.shape[0] / 2
        fixation = (y, x)
        R.prepare(campic.shape, fixation)

        ret, img = cap.read()
        if ret:
            V = R.sample(img, fixation)

        originalvector = ImageVector(V,
                                     framenum=1,
                                     timestamp="HH:MM:SS.SS",
                                     label="dummy",
                                     fixationy=y,
                                     fixationx=x,
                                     retinatype="50k")
        self.assertTrue(np.array_equal(V, originalvector._vector),
                        'Vector has been modified by storage in model')

        vectors = [originalvector]
        ip.saveHDF5(os.path.join("testdata", "integritytest.h5"), vectors)
        newvectors = ip.loadhdf5(os.path.join("testdata", "integritytest.h5"),
                                 None)
        newvector = newvectors[0]
        self.assertTrue(np.array_equal(V, originalvector._vector),
                        'Vector has been modified by storage in HDF5')

        ip.saveCSV(os.path.join("testdata", "integritytest.csv"), vectors)
        newvectors = ip.loadCsv(os.path.join("testdata", "integritytest.csv"),
                                None)
        newvector = newvectors[0]
        self.assertTrue(np.array_equal(V, originalvector._vector),
                        'Vector has been modified by storage in CSV')

        print("Vector has not been modified by the system")
Example #2
0
    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)
Example #3
0

def visualize(BI, title, pyr, dog=False):
    for i in range(len(BI[:-1])):
        if dog: im = np.true_divide(BI[i], pyr.norm_maps[i])
        else: im = BI[i]
        cv2.namedWindow(title + str(i), cv2.WINDOW_AUTOSIZE)
        cv2.imshow(title + str(i), im)


#Open webcam
cap = utils.camopen()  #cap is the capture object (global)
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)

#Prepare pyramid
pyr_path = join(datadir, "pyramid")
L = utils.loadPickle(join(pyr_path, "50K_pyr_narrow_tessellations.pkl"))
L2 = utils.loadPickle(join(pyr_path, "50K_pyr_wide_tessellations.pkl"))
N = utils.loadPickle(join(pyr_path, "50K_pyr_narrow_normmaps.pkl"))
def startRetina():
    """Instantiates Retina object and loads necessary files"""
    retina = Retina(isGPUAvailable())
    retina.loadLoc(join(datadir, "retinas", "ret50k_loc.pkl"))
    retina.loadCoeff(join(datadir, "retinas", "ret50k_coeff.pkl"))
    return retina
Example #5
0
import numpy as np
import cv2
from os.path import join
import os
from retinavision.retina import Retina
from retinavision.cortex import Cortex
from retinavision import datadir, utils

R = Retina(gpu=False)
R.info()
R.loadLoc(join(datadir, "retinas", "ret50k_loc.pkl"))
R.loadCoeff(join(datadir, "retinas", "ret50k_coeff.pkl"))

#open cap and set resolution as 1280*720, the default is 640*320 which
#is too small for 50k node, so, we need change the resolution
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

ret, campic = cap.read()
x = campic.shape[1] / 2
y = campic.shape[0] / 2
fixation = (y, x)
R.prepare(campic.shape, fixation)
ret, img = cap.read()
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
V = R.sample(img, fixation)
#back project
tight = R.backproject_last()
tight = cv2.cvtColor(tight, cv2.COLOR_BGR2RGB)
cv2.imwrite("tight.jpg", tight)