def test_frame(self): # test rendering of text frames f1 = Frame.objects.create(title='Text Page', format='text', content="page <i>content</i>") r1 = f1.draw() self.failUnlessStringContains(r1, "page <i>content</i>") self.failUnless(isinstance(r1, SafeData)) # test rendering of html frames f2 = Frame(format='html', content="page <i>content</i>") r2 = f2.draw() self.failUnlessStringContains(r2, "page <i>content</i>") self.failUnless(isinstance(r2, SafeData)) # test rendering of template frames f3 = Frame(format='template', content="page {% if 1 %}<i>content</i>{% else %}NO{% endif %}") r3 = f3.draw() self.failUnlessStringContains(r3, "<i>content</i>") self.failIfStringContains(r3, "NO") self.failUnless(isinstance(r3, SafeData)) # test the standalone "draw" function r1_2 = draw("Text Page") self.failUnless(r1_2 == r1) # test rendering of non-existent frames def make_bad_frame(): Frame(title="BadFormat Page", content="page <i>content</i>", format='no_such_format').draw() self.failUnlessRaises(TypeError, make_bad_frame)
def post(self): """ Save a frame """ json_data, error = get_data(request) if not error: device_data, error = validate_json_payload(json_data, self.fields) if not error: error = self.validate_jetson_data( device_data, data_dict={ 'alert_id': device_data['alert_id'], 'date_': device_data['frame_timestamp'] }) if not error: try: frame_data = self.frame_schema.load({ 'alert_id': device_data['alert_id'], 'frame_timestamp': device_data['frame_timestamp'], 'frame_index': device_data.get('frame_index', 0) }) except marshmallow.exceptions.ValidationError as errors: return response(400, str(errors)) frame = Frame(**frame_data, frame_image=bytes(device_data['frame'], 'utf-8')) error = frame.save() if not error: return response(200, data={'frame_id': frame.id}) return error
def post(self): name = self.request.get('name') frame = Frame(name=name, created_by_user_id=users.get_current_user().user_id(), access_key=self.generate_random_string(40)) frame.put() self.response.out.write("ok")
def create_frame(f,video_obj): df = Frame() df.video = video_obj df.name = f['name'] df.frame_index = f['frame_index'] df.subdir = f['subdir'] df.h = f.get('h',0) df.w = f.get('w',0) df.t = f.get('t',0) df.segment_index = f.get('segment_index',0) df.keyframe = f.get('keyframe',False) return df
def process_frame(self, thresholded_frame): if self.area and self.area.is_complete: thresholded_frame = thresholded_frame[self.area.y1:self.area.y2, self.area.x1:self.area.x2] processed_frame = Frame() points = numpy.transpose(thresholded_frame.nonzero()) if not len(points): return # Precalculations tan_half_fov_x = math.tan(self.fov_x/2) tan_half_fov_y = math.tan(self.fov_y/2) # m is the vector from the camera position to the origin m = self.camera_position * -1 w = self.width/2 h = self.height/2 for point in points: img_y, img_x = point if self.area and self.area.is_complete: img_y += self.area.y1 img_x += self.area.x1 # Horizontal angle between platform middle (in image) and point delta_x = float(img_x - self.platform_middle[0])/2 tau = math.atan(delta_x/w*tan_half_fov_x) # Vertical angle delta_y = float(img_y - self.platform_middle[1])/2 rho = math.atan(delta_y/h*tan_half_fov_y) # Rotate vector m around tau and rho to point towards 'point' v = m v = rotate('z', v, tau) # Rotate around z axis for horizontal angle v = rotate('x', v, rho) # Rotate around x axis for vertical angle v = self.get_laser_plane_intersection(v) # Ignore any vertices that have negative z coordinates (pre scaling) if v[2] < 0: continue x,y,z = v*self.scale x,y,z = rotate('z', v, self.rotation_angle) vertex = Vertex(x, y, z) processed_frame.append(vertex) self.processed_frames.append(processed_frame)
def import_frame(f, video_obj): df = Frame() df.video = video_obj df.name = f['name'] df.frame_index = f['frame_index'] df.subdir = f['subdir'] df.save() return df
def preprocessing_frame(self, frame): frame_resize = cv2.resize(frame, dsize=(self.frame_width, self.frame_height)) kps, des = self.feature_extractor.feature_detecting(frame_resize, mode='feat') kps = np.array([item.pt for item in kps]) print('changing keypoints to np array') model = Frame(kps, des) return frame_resize, model
def get(self): owner_frames = Frame.query_by_owner( users.get_current_user().user_id()).fetch() self.response.headers['Content-Type'] = 'application/json' self.response.out.write( json.dumps([g.serialize() for g in owner_frames], default=default_json_serializer))
def handle_suggestion_response(result, current_asset_id, asset_metas): for asset_meta in asset_metas: asset_id = asset_meta.asset_id # skip if it is the same id as the classified image if current_asset_id == asset_id: continue cropped_id = asset_meta.cropped_id path = fetch_cropped_path(asset_id, cropped_id) if asset_id not in result.suggestions: result.suggestions[asset_id] = Suggestion([Frame(cropped_id, asset_meta.faiss_idx, path)]) else: contains = False for frame in result.suggestions[asset_id].frames: if frame.frame_id == cropped_id: contains = True break if not contains: result.suggestions[asset_id].frames += [Frame(cropped_id, asset_meta.faiss_idx, path)]
def import_frame_json(f, frame_index, event_id, video_id, w, h): regions = [] df = Frame() df.video_id = video_id df.event_id = event_id df.w = w df.h = h df.frame_index = frame_index df.name = f['path'] for r in f.get('regions', []): regions.append(import_region_json(r, frame_index, video_id, event_id)) return df, regions
def import_frame(f, video_obj, detection_to_pk, vdn_dataset=None): df = Frame() df.video = video_obj df.name = f['name'] df.frame_index = f['frame_index'] df.subdir = f['subdir'] df.save() for d in f['detection_list']: dd = import_detection(d, video_obj, df, vdn_dataset) detection_to_pk[d['id']] = dd.pk for a in f['annotation_list']: da = import_annotation(a, video_obj, df, vdn_dataset) return df
def create_frame(f, video_obj): df = Frame() df.video = video_obj df.name = f['name'] df.frame_index = f['frame_index'] df.subdir = f['subdir'] return df
def load_annotation(self, drivename, fname, dtype='object'): fname = fname.split('.')[0] + '.json' try: with open(join(self.OUTPUT_ANN_DIR, drivename, fname), "r") as read_file: print("file: ", read_file) try: frame = json.load(read_file) if dtype == 'object': return Frame.parse_json(frame) else: return frame except json.JSONDecodeError: return "" except: return ""
def add(request): if request.method == 'GET': return render_to_response("add_frame.html", {}, context_instance=RequestContext(request)) elif request.method == 'POST': movie, created = TMDBMovie.objects.get_or_create(tmdb_id=request.POST['movie_id'], tmdb_name=request.POST['movie_name']) file = request.FILES['file'] frame = Frame() frame.file = file frame.movie = movie frame.owner = request.user.userprofile frame.save() return render_to_response("add_frame.html", {'result': u'Файл был успешно загружен'}, context_instance=RequestContext(request))
def load_annotation( self, drivename, fname, settingsControls, dtype='object', ): fname = settingsControls['AnnotatorId'] + '.' + fname.split('.' )[0] + '.json' try: with open(join(self.OUTPUT_ANN_DIR, drivename, fname), 'r' ) as read_file: #print ('file: ', read_file) try: frame = json.load(read_file) if dtype == 'object': return Frame.parse_json(frame) else: return frame except json.JSONDecodeError: return '' except: return ''
def import_frame_json(f, frame_index, event_id, video_id): regions = [] df = Frame() df.video_id = video_id df.event_id = event_id df.frame_index = frame_index df.name = f['path'] for r in f.get('regions', []): dr = Region() dr.frame_index = frame_index dr.video_id = video_id dr.event_id = event_id dr.object_name = r['object_name'] dr.region_type = r.get('region_type', Region.ANNOTATION) dr.full_frame = r.get('full_frame', False) dr.x = r.get('x', 0) dr.y = r.get('y', 0) dr.w = r.get('w', 0) dr.h = r.get('h', 0) dr.confidence = r.get('confidence', 0.0) dr.text = r.get('text', None) dr.metadata = r.get('metadata', None) regions.append(dr) return df, regions
def create_frame(self, f): df = Frame() df.video_id = self.video.pk df.name = f['name'] df.frame_index = f['frame_index'] df.subdir = f['subdir'] df.h = f.get('h', 0) df.w = f.get('w', 0) df.t = f.get('t', 0) if f.get('event', None): df.event_id = self.event_to_pk[f['event']] df.segment_index = f.get('segment_index', 0) df.keyframe = f.get('keyframe', False) return df
from models import Wheel, Frame, Bicycle, Manufacturer, BikeShop, Customer # Raw materials w1 = Wheel(weight=1050, cost=50, name="Vuelta 37mm") w2 = Wheel(weight=900, cost=100, name="Vuelta Corsa Lite") w3 = Wheel(weight=850, cost=150, name="Reynolds Eighty One") f1 = Frame(material="steel", weight=8000, cost=100) f2 = Frame(material="aluminum", weight=6000, cost=200) f3 = Frame(material="carbon", weight=5000, cost=300) # Manufacturers m1 = Manufacturer(20, "Trek") m2 = Manufacturer(15, "Navarro") m1.add_inventory(w1, f1, "transportation") m1.add_inventory(w2, f1, "transportation+") m1.add_inventory(w3, f1, "transportation super") m2.add_inventory(w1, f2, "comp") m2.add_inventory(w2, f2, "comp extra") m2.add_inventory(w3, f3, "elite max") # Shop s1 = BikeShop(name="Sam's Bikes", margin=20) s1.restock(m1.ship(3)) s1.restock(m2.ship(3)) s1.print_stock() #Customer
def test_create_frame(self): p1 = Player('Mario Mario') f1 = Frame(p1) assert f1.score == 0 assert f1.player == p1 assert f1.shots == [Frame.Shot.notyet, Frame.Shot.notyet]