Пример #1
0
		def __init__(self, _logic, _layer = None, _id = None):
			self.images = utils.loadImages('data/gfx/skeleton/', alpha = True)
			for _state in ('walk', 'attack'):
				for _direction in ('ne', 'sw'):
					for _d in _direction:
						self.images[_state][_d] = self.images[_state][_direction]

			super(Skeleton.Sprite, self).__init__(_logic, _layer, _id)
Пример #2
0
        def __init__(self, _logic, _layer=None, _id=None):
            self.images = utils.loadImages('data/gfx/troll/', alpha=True)
            for _state in ('walk', 'attack'):
                for _direction in ('ne', 'sw'):
                    for _d in _direction:
                        self.images[_state][_d] = self.images[_state][
                            _direction]

            super(Troll.Sprite, self).__init__(_logic, _layer, _id)
Пример #3
0
		def __init__(self, _logic, _layer = None, _id = None):
			self.images = utils.loadImages('data/gfx/mage/', alpha = True)
			for _direction in ('ne', 'sw'):
				for _d in _direction:
					self.images['walk'][_d] = self.images['walk'][_direction]

			for _d in 'nswe':
				self.images['attack'][_d]['0'] = self.images['walk'][_d]['0']

			super(Mage.Sprite, self).__init__(_logic, _layer, _id)
Пример #4
0
	def __init__(self, _map, _layer, _id, _direction, _start, _modifier = 1):
		self.images = utils.loadImages('data/gfx/arrow/', alpha = True)
		super(Arrow, self).__init__(self.images[_direction])
		self._modifier = _modifier # Modyfikator siły ataku
		self._map = _map
		self._layer = _layer
		self._id = _id
		self._vec = (_direction == 's' and (0, SPEED)) or (_direction == 'n' and (0, -SPEED)) or (_direction == 'e' and (SPEED, 0)) or (-SPEED, 0) # Wektor ruchu
		self._pos = _start[0] + self._vec[0] / SPEED * 17, _start[1] + self._vec[1] / SPEED * 17 # Aktualna pozycja
		self._start = _start
Пример #5
0
        def __init__(self, _logic, _layer=None, _id=None):
            self.images = utils.loadImages('data/gfx/mage/', alpha=True)
            for _direction in ('ne', 'sw'):
                for _d in _direction:
                    self.images['walk'][_d] = self.images['walk'][_direction]

            for _d in 'nswe':
                self.images['attack'][_d]['0'] = self.images['walk'][_d]['0']

            super(Mage.Sprite, self).__init__(_logic, _layer, _id)
Пример #6
0
    def _loadImage(self):
        """ 载入图片并根据屏幕窗口调整大小 """
        # 跑步状态
        self._runningImageDays = utils.loadImages(Settings.dinoRunningPath, 1, 2, -1, Settings.defaultColorKey,
                                                  Settings.initialWindowSize[0] * Settings.screenDinoRate)
        self._runningImageNights = utils.invertSurfaces(self._runningImageDays)

        # 俯冲状态
        self._divingImageDays = utils.loadImages(Settings.dinoDivingPath, 1, 2, -1, Settings.defaultColorKey,
                                                 Settings.initialWindowSize[0] * Settings.screenDivingDinoRate)
        self._divingImageNights = utils.invertSurfaces(self._divingImageDays)

        # 跳跃状态
        self._jumpingImageDay = utils.loadImage(Settings.dinoJumpingPath, Settings.defaultColorKey,
                                                Settings.initialWindowSize[0] * Settings.screenDinoRate)
        self._jumpingImageNight = utils.invertSurface(self._jumpingImageDay)

        # 死亡状态
        self._dyingImageDay = utils.loadImage(Settings.dinoDyingPath, Settings.defaultColorKey,
                                              Settings.initialWindowSize[0] * Settings.screenDinoRate)
        self._dyingImageNight = utils.invertSurface(self._dyingImageDay)
Пример #7
0
	def __init__(self, _map, _layer, _id, _pos, _modifier = 1):
		self.images = utils.loadImages('data/gfx/fire/', alpha = True)
		super(Fire, self).__init__(self.images['0'])
		self._map = _map
		self._layer = _layer
		self._id = _id
		self._pos = int(_pos[0] / 32) * 32 + 16, int(_pos[1] / 32) * 32 + 16
		self.rect.center = self._pos
		self._modifier = _modifier
		self._frame = 0
		self._counter = 0
		self._last = 60 # Czas spalania
Пример #8
0
	def __init__(self, _map, _layer, _id, _direction, _start, _modifier = 1):
		self.images = utils.loadImages('data/gfx/fireball/', alpha = True)
		super(Fireball, self).__init__(self.images['0'])
		self._sound = utils.loadSound('data/snd/explosion.wav')
		self._map = _map
		self._layer = _layer
		self._id = _id
		self._pos = _start
		self._start = _start
		self._modifier = _modifier
		self._vec = (_direction == 's' and (0, SPEED)) or (_direction == 'n' and (0, -SPEED)) or (_direction == 'e' and (SPEED, 0)) or (-SPEED, 0)
		self._pos = _start[0] + self._vec[0] / SPEED * 17, _start[1] + self._vec[1] / SPEED * 17
		self._frame = 0
		self._counter = 0
Пример #9
0
	def __init__(self, _map, _layer, _id, _direction, _pos, _modifier = 1):
		self.images = utils.loadImages('data/gfx/iceblast/', alpha = True)
		super(Iceblast, self).__init__(self.images[_direction]['0'])
		self._sound = utils.loadSound('data/snd/ice.wav')
		self._map = _map
		self._layer = _layer
		self._id = _id
		self._direction = _direction
		self._pos = int(_pos[0] / 32) * 32 + 16 + ((_direction == 'e' and 1) or (_direction == 'w' and -1) or 0) * 64, int(_pos[1] / 32) * 32 + 16 + ((_direction == 's' and 1) or (_direction == 'n' and -1) or 0) * 64
		self.rect.center = self._pos
		self._modifier = _modifier
		self._frame = 0
		self._counter = 0
		self._last = 40
		self._sound.play()
Пример #10
0
 def __init__(self, _map, _layer, _id, _direction, _start, _modifier=1):
     self.images = utils.loadImages('data/gfx/arrow/', alpha=True)
     super(Arrow, self).__init__(self.images[_direction])
     self._modifier = _modifier  # Modyfikator siły ataku
     self._map = _map
     self._layer = _layer
     self._id = _id
     self._vec = (_direction == 's' and
                  (0, SPEED)) or (_direction == 'n' and
                                  (0, -SPEED)) or (_direction == 'e' and
                                                   (SPEED, 0)) or (
                                                       -SPEED, 0
                                                   )  # Wektor ruchu
     self._pos = _start[0] + self._vec[0] / SPEED * 17, _start[
         1] + self._vec[1] / SPEED * 17  # Aktualna pozycja
     self._start = _start
Пример #11
0
	def __init__(self, _map, _layer, _id, _, _pos, _modifier = 1):
		self.images = utils.loadImages('data/gfx/heal/', alpha = True)
		super(Heal, self).__init__(self.images['0'])
		self._map = _map
		self._layer = _layer
		self._id = _id
		self._pos = _pos
		self.rect.center = self._pos
		self._frame = 1
		self._counter = 0
		self._last = 60
		_field = self._map.getLayer('Fields').get(_pos)
		if _field: # uzdrawianie stwora na danym polu
			_mns = _field.getLogic().getOccupied()
			if _mns:
				_mns.heal(_modifier * 100)
Пример #12
0
 def __init__(self, _map, _layer, _id, _, _pos, _modifier=1):
     self.images = utils.loadImages('data/gfx/heal/', alpha=True)
     super(Heal, self).__init__(self.images['0'])
     self._map = _map
     self._layer = _layer
     self._id = _id
     self._pos = _pos
     self.rect.center = self._pos
     self._frame = 1
     self._counter = 0
     self._last = 60
     _field = self._map.getLayer('Fields').get(_pos)
     if _field:  # uzdrawianie stwora na danym polu
         _mns = _field.getLogic().getOccupied()
         if _mns:
             _mns.heal(_modifier * 100)
Пример #13
0
	def __init__(self, _engine, _map):
		super(Cursor, self).__init__()
		self.images = utils.loadImages('data/gfx/cursor/', alpha = True)

		self._engine = _engine
		self._map = _map
		self._resx, self._resy = _engine.getResolution()

		pygame.mouse.set_pos((self._resx / 2, self._resy / 2))
		pygame.mouse.set_visible(False)

		self._cursor = None
		self._pos = pygame.mouse.get_pos()
		self._direction = map.DIRECTION_NONE
		self._updated = []
		self.updateCursor()
		self.moveCursor()
Пример #14
0
    def __init__(self, _engine, _map):
        super(Cursor, self).__init__()
        self.images = utils.loadImages('data/gfx/cursor/', alpha=True)

        self._engine = _engine
        self._map = _map
        self._resx, self._resy = _engine.getResolution()

        pygame.mouse.set_pos((self._resx / 2, self._resy / 2))
        pygame.mouse.set_visible(False)

        self._cursor = None
        self._pos = pygame.mouse.get_pos()
        self._direction = map.DIRECTION_NONE
        self._updated = []
        self.updateCursor()
        self.moveCursor()
Пример #15
0
 def __init__(self, _map, _layer, _id, _direction, _start, _modifier=1):
     self.images = utils.loadImages('data/gfx/fireball/', alpha=True)
     super(Fireball, self).__init__(self.images['0'])
     self._sound = utils.loadSound('data/snd/explosion.wav')
     self._map = _map
     self._layer = _layer
     self._id = _id
     self._pos = _start
     self._start = _start
     self._modifier = _modifier
     self._vec = (_direction == 's' and
                  (0, SPEED)) or (_direction == 'n' and
                                  (0, -SPEED)) or (_direction == 'e' and
                                                   (SPEED, 0)) or (-SPEED,
                                                                   0)
     self._pos = _start[0] + self._vec[0] / SPEED * 17, _start[
         1] + self._vec[1] / SPEED * 17
     self._frame = 0
     self._counter = 0
Пример #16
0
 def __init__(self, _map, _layer, _id, _direction, _pos, _modifier=1):
     self.images = utils.loadImages('data/gfx/iceblast/', alpha=True)
     super(Iceblast, self).__init__(self.images[_direction]['0'])
     self._sound = utils.loadSound('data/snd/ice.wav')
     self._map = _map
     self._layer = _layer
     self._id = _id
     self._direction = _direction
     self._pos = int(_pos[0] / 32) * 32 + 16 + (
         (_direction == 'e' and 1) or (_direction == 'w' and -1)
         or 0) * 64, int(_pos[1] / 32) * 32 + 16 + (
             (_direction == 's' and 1) or
             (_direction == 'n' and -1) or 0) * 64
     self.rect.center = self._pos
     self._modifier = _modifier
     self._frame = 0
     self._counter = 0
     self._last = 40
     self._sound.play()
        return tf.estimator.EstimatorSpec(mode=mode,
                                          loss=loss,
                                          train_op=train_op)

    # Add evaluation metrics (for EVAL mode)
    eval_metric_ops = {
        "accuracy":
        tf.metrics.accuracy(labels=labels, predictions=predictions["classes"])
    }
    return tf.estimator.EstimatorSpec(mode=mode,
                                      loss=loss,
                                      eval_metric_ops=eval_metric_ops)


train_data, train_labels, train_classes = utils.loadImages(
    name="train",
    imformat=1,
)
num_examples_train = train_labels.shape[0]

test_data, test_labels, test_classes = utils.loadImages(
    name="test",
    imformat=1,
)
num_examples_test = test_labels.shape[0]

# Use 5, 10, 15,...,40 frames of data to train 8 svm predictor
num_frames = 5 * np.arange(1, 9)
# Init best kernel storage
best_layers = np.zeros((8, 2), dtype=int)
# Init highest train score storage
high_score_train = np.zeros(num_frames.shape[0])
Пример #18
0
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--input", required=True, help="path to input directory")
ap.add_argument("-o",
                "--output",
                required=True,
                help="path to output directory")
ap.add_argument("-r",
                "--resize",
                type=int,
                default=0,
                help="resize input images")
args = vars(ap.parse_args())

# caculate execution time
print("Processing....")
start = timeit.default_timer()

# load images
list_images = utils.loadImages(args["input"], args["resize"])

# create panorama, default using ORB with nfeatures=3000, u can change to SIFT, SURF in features.py or add some argument
panorama = stitch.multiStitching(list_images)

# save
cv2.imwrite(args["output"] + "\\panorama.jpg", panorama)

stop = timeit.default_timer()
print("Complete!")
print("Execution time: ", stop - start)
Пример #19
0
 def __init__(self):
     """ 初始化 """
     self._coverImages = utils.loadImages(Settings.coverImagePath, 1, 2)
     self._textImage = utils.loadImage(Settings.coverTextPath)
Пример #20
0
		def __init__(self, _logic, _layer = None, _id = None):
			self.images = utils.loadImages('data/gfx/hero/', alpha = True)
			self.images['attack'] = self.images['walk']
			super(Hero.Sprite, self).__init__(_logic, _layer, _id)
Пример #21
0
 def _loadImage():
     """ 载入图片并根据屏幕窗口调整大小 """
     if not Star.images:
         Star.images = utils.loadImages(Settings.starPath, 1, 2, -1, Settings.defaultColorKey,
                                        Settings.initialWindowSize[0] * Settings.screenStarRate)
Пример #22
0
 def _loadImage():
     """ 载入图片并根据屏幕窗口调整大小 """
     if not Cactus.surfArrays:
         images = utils.loadImages(Settings.cactusPath, 1, 3, -1, None,
                                   Settings.initialWindowSize[0] * Settings.screenCactusRate)
         Cactus.surfArrays = [pygame.surfarray.array3d(image) for image in images]
Пример #23
0
import matplotlib.pyplot as plt
import time
from datetime import datetime
from sklearn import neighbors
from sklearn.metrics import confusion_matrix

import utils

TODAY = datetime.today().strftime("%Y%m%d")
result_path = "/media/linzhank/850EVO_1T/Works/Action_Recognition/Data/result{}".format(
    TODAY)

# Load data
train_data, train_labels, train_classes = utils.loadImages(
    name="train",
    imformat=0,  # grayscale
    scale=0.25  # resize to 1/4
)
num_examples_train = train_labels.shape[0]
test_data, test_labels, test_classes = utils.loadImages(name="test",
                                                        imformat=0,
                                                        scale=0.25)
num_examples_test = test_labels.shape[0]

# Use 5, 10, 15,...,40 frames of data to train 8 knn classifier
num_frames = 5 * np.arange(1, 9)
# Init best k storage
best_k = np.zeros(num_frames.shape).astype(int)
# Init best classifier storage
best_classifier = []
# Init highest train score storage
Пример #24
0
from utils import loadImages
from boostedcascade import BoostedCascade, HaarlikeFeature

GenerateFeatures = False
Database = 'x5large-2'
ModelFile = 'data/' + Database + '/model-100/' + Database

if __name__ == '__main__':
    # boostedCascade = BoostedCascade(0.03, 0.40, 0.99)
    # boostedCascade = BoostedCascade(0.04, 0.20, 0.985)
    # boostedCascade = BoostedCascade(0.07, 0.60, 0.97)

    if GenerateFeatures:
        boostedCascade = BoostedCascade(0.07, 0.60, 0.94)
        faceImages = loadImages('data/' + Database + '/train/faces')
        nonfaceImages = loadImages('data/' + Database + '/train/non-faces')

        boostedCascade.prepare(faceImages, nonfaceImages, shuffle=True, verbose=True)
        boostedCascade.savefeaturesdata('data/' + Database + '/train/features/' + Database)
    else:
        print('Loading model...')
        boostedCascade = BoostedCascade.loadModel(ModelFile)
        print(boostedCascade)
        print('Loading data...')
        boostedCascade.loadfeaturesdata('data/' + Database + '/train/features/' + Database)
        print('Training...')
        boostedCascade.train(is_continue=True, autosnap_filename=ModelFile, verbose=True)
        boostedCascade.saveModel(ModelFile)
Пример #25
0
                filtered_rectangles.append(rect)
                filtered_weights.append(weight)

        return filtered_rectangles, filtered_weights

    def loadModel(self):
        svm_model = cv2.ml.SVM_load("./outputs/svm_model.temp")
        return svm_model

    def saveModel(self, model):
        model.save("./outputs/svm_model.temp")


if __name__ == '__main__':

    positive_samples = np.array(loadImages('outputs/images/buildings.npy'))
    negative_samples = np.array(
        loadImages('outputs/images/non-buildings.npy')[:1700])

    # positive_hog = computeHOG(positive_samples)
    # negative_hog = computeHOG(negative_samples)
    dataset = np.concatenate((positive_samples, negative_samples), axis=0)

    # Create the class labels, i.e. (+1) positive and (-1) negative.
    labels = []
    [labels.append(+1) for _ in range(len(positive_samples))]
    [labels.append(-1) for _ in range(len(negative_samples))]

    X_train, X_test, y_train, y_test = train_test_split(dataset,
                                                        labels,
                                                        test_size=0.3,
Пример #26
0
 def _loadImage():
     """ 载入图片并根据屏幕窗口调整大小 """
     if not Moon.images:
         Moon.images = utils.loadImages(Settings.moonPath, 1, 7, -1, Settings.defaultColorKey,
                                        Settings.initialWindowSize[0] * Settings.screenMoonRate)
Пример #27
0
from boostedcascade import BoostedCascade, HaarlikeFeature, HaarlikeType

RawPredict = False
GenerateFeatures = False
Database = 'x5large'
ModelFile = 'models/model-100-l7/' + 'x5large-2'
FPOutput = 'data/fp-noface'
TNOutput = 'data/tn-noface'

if __name__ == '__main__':
    boostedCascade = BoostedCascade.loadModel(ModelFile)
    print(boostedCascade)
    print(boostedCascade.architecture())

    # faceImages = loadImages('data/' + Database + '/test/faces')
    faceImages = loadImages('data/all/faces')
    # nonfaceImages = loadImages('data/' + Database + '/test/non-faces')
    nonfaceImages = loadImages('data/all/non-faces-ex/', verbose=True)
    # nonfaceImages = loadImages('data/all/facebk-ex/', verbose=True)
    # faceImages = loadImages('data/' + 'large' + '/train/faces')
    # nonfaceImages = loadImages('data/' + 'large' + '/train/non-faces')
    # nonfaceImages = loadImages('data/all/non-faces', verbose=True)

    if RawPredict:
        if GenerateFeatures:
            boostedCascade.preparePredictRaw(faceImages,
                                             nonfaceImages,
                                             verbose=True)
            boostedCascade.savefeaturesdata('data/' + Database +
                                            '/test/features/' + Database)
Пример #28
0
        def __init__(self, _logic, _layer=None, _id=None):
            self.images = utils.loadImages('data/gfx/spider/', alpha=True)
            for _d in 'nswe':
                self.images['attack'][_d]['0'] = self.images['walk'][_d]['0']

            super(Spider.Sprite, self).__init__(_logic, _layer, _id)
Пример #29
0
		def __init__(self, _logic, _layer = None, _id = None):
			self.images = utils.loadImages('data/gfx/spider/', alpha = True)
			for _d in 'nswe':
				self.images['attack'][_d]['0'] = self.images['walk'][_d]['0']

			super(Spider.Sprite, self).__init__(_logic, _layer, _id)
Пример #30
0
 def _loadImage():
     """ 载入图片并根据屏幕窗口调整大小 """
     if not Bird.imageDays:
         Bird.imageDays = utils.loadImages(Settings.birdPath, 1, 2, -1, Settings.defaultColorKey,
                                           Settings.initialWindowSize[0] * Settings.screenBirdRate)
         Bird.imageNights = utils.invertSurfaces(Bird.imageDays)
Пример #31
0
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--input", required=True, help="path to input directory")
ap.add_argument("-o",
                "--output",
                required=True,
                help="path to output directory")
ap.add_argument("-r",
                "--resize",
                type=int,
                default=0,
                help="resize input images")
args = vars(ap.parse_args())

#caculate execution time
print('Processing....')
start = timeit.default_timer()

#load images
list_images = utils.loadImages(args['input'], args['resize'])

#create panorama, default using ORB with nfeatures=3000, u can change to SIFT, SURF in features.py or add some argument
panorama = stitch.multiStitching(list_images)

#save
cv2.imwrite(args['output'] + '\\panorama.jpg', panorama)

stop = timeit.default_timer()
print('Complete!')
print('Execution time: ', stop - start)
Пример #32
0
 def __init__(self, _logic, _layer=None, _id=None):
     self.images = utils.loadImages('data/gfx/hero/', alpha=True)
     self.images['attack'] = self.images['walk']
     super(Hero.Sprite, self).__init__(_logic, _layer, _id)
Пример #33
0
"""Test for DNNClassifier
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import numpy as np

import matplotlib.pyplot as plt
import tensorflow as tf
import utils

img_te, lbl_te = utils.loadImages("test")
Пример #34
0
calibration_path = './camera_cal/'

test_images_path = './test_images/*.jpg'
video_frame_path = './frames/*_1000_*.jpg'

debug = False
test_pipeline = False
test_pipeline_path = test_images_path
#test_pipeline_path = video_frame_path

image_paths = glob.glob(calibration_path + '*.jpg')
camera = Camera()
camera.calibrate(image_paths)

if test_pipeline:
    images = utils.loadImages(test_pipeline_path, cv2.COLOR_BGR2RGB)
    hud = camera.pipeline(images[0], debug=debug, dump_partials=False)
    utils.showImage(hud)
else:
    camera.processVideo('project_video.mp4', debug=debug, live=False)
'''
test_images = list(map(lambda image_path:cv2.imread(image_path),test_images_paths))
test_images = list(map(lambda image:cv2.cvtColor(image,cv2.COLOR_BGR2RGB),test_images))
test_images_grid = list(map(lambda image:utils.drawGrid(image),test_images))

test_images_undist =  list(map(lambda img: camera.unsidtort(img),test_images_grid))

interlaved = []
for i in range(len(test_images)):
    interlaved.append(test_images_grid[i])
    interlaved.append(test_images_undist[i])