def addBlob(self): '''Creates the enemy blobs with random colors, starting points, sizes, and speeds''' # Width between 1 and 200 inclusive is chosen randomly width = random.randint(1, 200) # Height of enemy blob is always half the width height = width / 2 # Blobs have a 50% chance to appear from the left if random.randint(0, 1) == 0: # Adds blob to canvas with random starting position from the left, with random width, height, color, and speed self.canvas.addItem( blob.Blob(self.canvas, self.player, self, (-800, random.randrange(HEIGHT)), (width, height), random.choice(colors), random.randint(2, 7))) # Adds the blob every 1500 milliseconds self.canvas.after(1500, self.addBlob) # Blobs have a 50% chance to appear from the right else: # Adds blob to canvas with random starting position from the right, with random width, height, color, and speed self.canvas.addItem( blob.Blob(self.canvas, self.player, self, (805, random.randrange(HEIGHT)), (width, height), random.choice(colors), random.randint(-7, -2))) # Adds the blob every 1500 milliseconds self.canvas.after(1500, self.addBlob)
def find_blobs(self, minsize=0, maxsize=10000000): blobs = [] contours, hyerarchy = cv2.findContours(self._data, cv2.cv.CV_RETR_TREE, cv2.cv.CV_CHAIN_APPROX_SIMPLE) for c in contours: area = cv2.contourArea(c) if area > minsize and area < maxsize: if len(blobs) and area > blobs[0].area: blobs.insert(0, blob.Blob(c)) else: blobs.append(blob.Blob(c)) return blobs
def content_from_string(repo, text): """ Parse a content item and create the appropriate object ``repo`` is the Repo ``text`` is the single line containing the items data in `git ls-tree` format Returns ``git.Blob`` or ``git.Tree`` """ try: mode, typ, id, name = text.expandtabs(1).split(" ", 4) except: return None if typ == "tree": return Tree(repo, id=id, mode=mode, name=name) elif typ == "blob": return blob.Blob(repo, id=id, mode=mode, name=name) elif typ == "commit": return None else: raise(TypeError, "Invalid type: %s" % typ)
def __init__(self, number_producers=1, number_consumers=50, **kwargs): super(WriteBlob, self).__init__(number_producers, number_consumers, **kwargs) self._blob = kwargs.get('blob', blob.Blob(Subspace(('bulk_blob', )))) self._clear = kwargs.get('clear', False) if self._clear: self._blob.delete(db)
def content_from_string(repo, text, commit_context=None, path=''): """ Parse a content item and create the appropriate object ``repo`` is the Repo ``text`` is the single line containing the items data in `git ls-tree` format Returns ``git.Blob`` or ``git.Tree`` """ try: mode, typ, id, name = text.expandtabs(1).split(" ", 3) except: return None if typ == "tree": return Tree(repo, id=id, mode=mode, name=name, commit_context=commit_context, path='/'.join([path, name])) elif typ == "blob": return blob.Blob(repo, id=id, mode=mode, name=name) elif typ == "commit" and mode == '160000': return submodule.Submodule(repo, id=id, name=name, commit_context=commit_context, path='/'.join([path, name])) else: raise (TypeError, "Invalid type: %s" % typ)
def find_blobs(self, minsize=0, maxsize=10000000): blobs = [] image = contours = hyerarchy = None if "2.4" in cv2.__version__: contours, hyerarchy = cv2.findContours(self._data, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) else: image, contours, hyerarchy = cv2.findContours(self._data, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) for c in contours: area = cv2.contourArea(c) if area > minsize and area < maxsize: if len(blobs) and area > blobs[0].area: blobs.insert(0, blob.Blob(c)) else: blobs.append(blob.Blob(c)) return blobs
def _iter_from_data(self): """ Reads the binary non-pretty printed representation of a tree and converts it into Blob, Tree or Commit objects. Note: This method was inspired by the parse_tree method in dulwich. Returns list(IndexObject, ...) """ ord_zero = ord('0') data = self.data len_data = len(data) i = 0 while i < len_data: mode = 0 # read mode # Some git versions truncate the leading 0, some don't # The type will be extracted from the mode later while data[i] != ' ': # move existing mode integer up one level being 3 bits # and add the actual ordinal value of the character mode = (mode << 3) + (ord(data[i]) - ord_zero) i += 1 # END while reading mode type_id = mode >> 12 # byte is space now, skip it i += 1 # parse name, it is NULL separated ns = i while data[i] != '\0': i += 1 # END while not reached NULL name = data[ns:i] path = join_path(self.path, name) # byte is NULL, get next 20 i += 1 sha = data[i:i+20] i = i + 20 hexsha = sha_to_hex(sha) if type_id == self.blob_id or type_id == self.symlink_id: yield blob.Blob(self.repo, hexsha, mode, path) elif type_id == self.tree_id: yield Tree(self.repo, hexsha, mode, path) elif type_id == self.commit_id: # submodules yield None else: raise TypeError( "Unknown type found in tree data %i for path '%s'" % (type_id, path))
def create_blob(self, x, y): newBlob = blob.Blob() newBlob.level = self newBlob.player = self.player newBlob.rect.x = x newBlob.rect.y = y self.impList.add(newBlob)
import paho.mqtt.client as mqtt import blob import json import uuid SERVER = "infmqtt.westeurope.azurecontainer.io" TOPIC = "smartbin" blob = blob.Blob(TOPIC) def send_to_blob(data): print("Send to blob: " + data) blob.write_data_to_blob(data) def on_connect(client, userdata, flags, rc): print("Connected with result code " + str(rc)) client.subscribe(TOPIC) def on_message(client, userdata, msg): b = str(msg.payload.decode("utf-8")) print(msg.topic + " " + b) send_to_blob(b) # Main if __name__ == '__main__': try: client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message
import numpy as np import cv2 as cv import blob as b import csv as cs import math as m arrytemp1 = cv.imread("img/hw3_leaf_training_1.jpg", 0) arrytemp2 = cv.imread("img/hw3_leaf_training_2.jpg", 0) arrytemp3 = cv.imread("img/hw3_leaf_training_3.jpg", 0) arrytemp4 = cv.imread("img/hw3_leaf_training_4.jpg", 0) arrytemp5 = cv.imread("img/hw3_leaf_training_5.jpg", 0) assignment = cv.imread("img/hw3_leaf_testing_1.jpg", 0) obj1 = b.Blob() obj2 = b.Blob() obj3 = b.Blob() obj4 = b.Blob() obj5 = b.Blob() data1 = obj1.extractfeature(arrytemp1) data2 = obj2.extractfeature(arrytemp2) data3 = obj3.extractfeature(arrytemp3) data4 = obj4.extractfeature(arrytemp4) data5 = obj4.extractfeature(arrytemp5) array1 = obj1.features() array2 = obj2.features() array3 = obj3.features() array4 = obj4.features() array5 = obj5.features()
height = bg.shape[0] rectangles = {"1": list(), "2": list(), "3": list()} filenames = [ "generated_sample_" + counter + "_" + str(x) for x in range(1, 4) ] filepaths = list(map(lambda name: os.path.join(generated, name), filenames)) new_img = [bg, bg, bg] for k in range(blob_no): for l in range(3): if l == 0: b = blob.Blob([height, width]) else: b = b.genarete_rotated() texture_b, blob_pos = blob.blob_texture( texture, b, pos=None if l == 0 else blob_pos) new_img[l], rectangle, pos = blob.join_blob( new_img[l], texture_b, b, prev_pos=None if l == 0 else pos) if isinstance(rectangle, list): rectangles[str(l + 1)].append(rectangle) texture = mpimg.imread(pair_list[random.randint(-i, 0)][1]) if texture.shape[0] > 1000 or texture.shape[1] > 1500: texture = cv2.resize(texture, (640, 480)) for l in range(3): mpimg.imsave(filepaths[l] + '.jpg', new_img[l]) to_txt(filepaths[l], rectangles[str(l + 1)], new_img[l].shape)
parser.add_argument( '--root', nargs=1, help= "Root directory of the project. Use absolute path, or relative path to XML file." ) parser.add_argument('--exclude', nargs='*', help="Names of XML entries to ignore when parsing.") parser.add_argument( '--timestamp', help="Sets the timestanp to be used when naming the output.") args = parser.parse_args() if args.info is not None: b = blob.Blob() b.load_from_file(args.info[0]) b.disp() if args.unpack is not None: blob_path = args.unpack[0] blob_output_dir = args.unpack[1] if not os.path.exists(blob_output_dir): os.makedirs(blob_output_dir) b = blob.Blob() b.load_from_file(blob_path) b.unpack(os.path.basename(blob_path), blob_output_dir) if args.pack is not None:
#!/usr/bin/env python import paho.mqtt.client as mqtt import blob import cosmos import json import uuid SERVER = "infmqtt.westeurope.azurecontainer.io" blob = blob.Blob('devices', '.\Data') cosmos_client = cosmos.create_cosmos_client() def send_to_blob(data): print("Send to blob : " + data) blob.write_data_to_blob(data) def send_to_cosmos(data): json_d = json.loads(data) print("Send to cosmos : " + json_d) cosmos.DocumentManagement.CreateDocument(cosmos_client, json_d) def on_connect(client, userdata, flags, rc): print("Connected with result code " + str(rc)) client.subscribe("iotro/mt/devices")
import random #init pygame, view constants init() mixer.init() MU = 100.0 viewportSize = (800, 600) screen = display.set_mode((viewportSize[0], viewportSize[1])) cenaBoost = None c = False #init map myMap = map.Map(100.0,100.0) #init myBlob myBlob = blob.Blob([3.0,3.0]) myMap.addBlob(myBlob) #init other blobs blobs = []; blobs.append(myBlob) blobs.append(blob.Blob([6.31,3.51], 0.1)) blobs.append(blob.Blob([5.26,3.41], 0.1)) blobs.append(blob.Blob([3.0,7.5], 0.1)) blobs.append(blob.Blob([2.0,3.5], 0.1)) myMap.addBlobs(blobs) #init resources rf = ResourceFactory(myMap, 2000) rf.createInitialResources()
# importing training images training_imgs = [] training_dir = './train' img_paths = os.listdir(training_dir) for img_path in img_paths: t = cv.imread(training_dir + '/' + img_path, 0) training_imgs.append(t) # importing testing image test = cv.imread("test/test.png", 0) # extracting features features = [] for img in training_imgs: # creating class objects obj = b.Blob() # extracting features from training images obj.extractfeature(img) # function returning the array of features it extracted f = obj.features() features.append(f) # writing features in csv, so that we do not need to train again csvinputdata = features with open('features.csv', 'w') as csvfile: writer = cs.writer(csvfile) writer.writerows(csvinputdata) csvfile.close() def add_column_in_csv(input_file, output_file, transform_row):