def get(self): all_languages = select_languages() if all_languages: languages = enumeration_schemas.languages_schema.dump( all_languages) return success(data=languages) return success(data=[])
def get(self): all_countries = select_countries() if all_countries: countries = enumeration_schemas.countries_schema.dump( all_countries) return success(data=countries) return success(data=[])
def set_currency_wallet(request, data, user): currency_name = data['currency'] identifier = data['identifier'] password = data['password'] defaultrate = Decimal(data['defaultrate']) with createsession(engine) as session: try: currency = session.query(Currency).filter_by(name=currency_name).one() except: return error(request, 'Currency error') try: currencywallet = session.query(CurrencyWallet).filter_by(currency=currency).one() except MultipleResultsFound: for currencywallet_item in currencywallet: session.delete(currencywallet_item) currencywallet = CurrencyWallet(currency=currency, identifier=identifier, password=password, defaultrate=defaultrate) except NoResultFound: currencywallet = CurrencyWallet(currency=currency, identifier=identifier, password=password, defaultrate=defaultrate) session.add(currencywallet) session.commit() return success()
def get_size(self): w, h = ctypes.c_long(), ctypes.c_long() result = lib.Toupcam_get_Size(self.cam, ctypes.byref(w), ctypes.byref(h)) if success(result): return w, h
def get_size(self): 'get width and height of image in pixels' w, h = ctypes.c_long(), ctypes.c_long() result = lib.Toupcam_get_Size(self.cam, ctypes.byref(w), ctypes.byref(h)) if success(result): return w, h
def open(self): if self.resolution: self.set_esize(self.resolution) else: self.set_size(*self.size) args = self.get_size() if not args: return h, w = args[1].value, args[0].value shape = (h, w) if self.bits == 8: dtype = uint8 else: dtype = uint32 # Users have to make sure that the data buffer capacity is enough to save the image data. self._data = zeros(shape, dtype=dtype) bits = ctypes.c_int(self.bits) def get_frame(nEvent, ctx): if nEvent == TOUPCAM_EVENT_IMAGE: w, h = ctypes.c_uint(), ctypes.c_uint() ''' :param HToupCam: handle to cam :param pImageData: (void*) Data buffer. :param bits: (int) 24, 32 or 8, means RGB24, RGB32 or 8 bits grey images. This parameter is ignored in RAW mode. :param pnWidth: (unsigned*) width of image. :param pnWidth: (unsigned*) height of image. ''' lib.Toupcam_PullImage(self.cam, ctypes.c_void_p(self._data.ctypes.data), bits, ctypes.byref(w), ctypes.byref(h)) print( f"TOUPCAM_IMAGE_EVENT- width:{w.value}, height:{h.value}; data-length:{len(self._data)}; data-shape:{self._data.shape}; bitdepth:{bits.value}; dtype:{dtype}" ) elif nEvent == TOUPCAM_EVENT_STILLIMAGE: w, h = self.get_size() h, w = h.value, w.value still = zeros((h, w), dtype=uint32) lib.Toupcam_PullStillImage(self.cam, ctypes.c_void_p(still.ctypes.data), bits, None, None) self._do_save(still) callback = ctypes.CFUNCTYPE(None, ctypes.c_uint, ctypes.c_void_p) self._frame_fn = callback(get_frame) result = lib.Toupcam_StartPullModeWithCallback(self.cam, self._frame_fn) return success(result)
def get_raw_format(self): 'get raw format' nFourCC = ctypes.c_uint(0) bitsPerPixel = ctypes.c_uint(0) result = lib.Toupcam_get_RawFormat(self.cam, ctypes.byref(nFourCC), ctypes.byref(bitsPerPixel)) if success(result): print(bitsPerPixel.value) print(nFourCC.value) return nFourCC.value
def set_with_callback(self): #self.set_esize(self.resolution) args = self.get_size() if not args: return h, w = args[1].value, args[0].value shape = (h, w) if self.bits == 8: dtype = uint8 else: dtype = uint32 self._data = zeros(shape, dtype=dtype) bits = ctypes.c_int(self.bits) #print("opened") def get_frame(nEvent, ctx): #print("getting frame") if nEvent == TOUPCAM_EVENT_IMAGE: w, h = ctypes.c_uint(), ctypes.c_uint() lib.Toupcam_PullImage(self.cam, ctypes.c_void_p(self._data.ctypes.data), bits, ctypes.byref(w), ctypes.byref(h)) if self._master is not None: self._master.update_image() elif nEvent == TOUPCAM_EVENT_STILLIMAGE: w, h = self.get_size() h, w = h.value, w.value still = zeros((h, w), dtype=uint32) lib.Toupcam_PullStillImage(self.cam, ctypes.c_void_p(still.ctypes.data), bits, None, None) self._do_save(still) if self._master is not None: self._master.update_image() callback = ctypes.CFUNCTYPE(None, ctypes.c_uint, ctypes.c_void_p) self._frame_fn = callback(get_frame) result = lib.Toupcam_StartPullModeWithCallback(self.cam, self._frame_fn) return success(result)
def open(self): if self.resolution: self.set_esize(self.resolution) else: self.set_size(*self.size) args = self.get_size() if not args: print('Failed opening camera') return h, w = args[1].value, args[0].value shape = (h, w) if self.bits == 8: dtype = uint8 else: dtype = uint32 self._data = zeros(shape, dtype=dtype) bits = ctypes.c_int(self.bits) def get_frame(nEvent, ctx): if nEvent == TOUPCAM_EVENT_IMAGE: w, h = ctypes.c_uint(), ctypes.c_uint() lib.Toupcam_PullImage(self.cam, ctypes.c_void_p(self._data.ctypes.data), bits, ctypes.byref(w), ctypes.byref(h)) elif nEvent == TOUPCAM_EVENT_STILLIMAGE: w, h = self.get_size() h, w = h.value, w.value still = zeros((h, w), dtype=uint32) lib.Toupcam_PullStillImage(self.cam, ctypes.c_void_p(still.ctypes.data), bits, None, None) self._do_save(still) callback = ctypes.CFUNCTYPE(None, ctypes.c_uint, ctypes.c_void_p) self._frame_fn = callback(get_frame) result = lib.Toupcam_StartPullModeWithCallback(self.cam, self._frame_fn) return success(result)
def post(self): username = request.json.get('username', None) password = request.json.get('password', None) if not check_student_by_username_password(username, password): return failure(message="Bad username or password") student = check_student_by_username(username) if not student.verified: return failure(message='Your account has not been verified') expires = datetime.timedelta(hours=10) token = create_access_token(username, expires_delta=expires) from flask_jwt_extended import create_refresh_token ret = { 'access_token': token, 'refresh_token': create_refresh_token(identity=username) } return success(data=ret)
def open(self): if self.resolution: self.set_esize(self.resolution) else: self.set_size(*self.size) args = self.get_size() if not args: return h, w = args[1].value, args[0].value shape = (h, w) if self.bits == 8: dtype = uint8 else: dtype = uint32 self._data = zeros(shape, dtype=dtype) bits = ctypes.c_int(self.bits) def get_frame(nEvent, ctx): if nEvent == TOUPCAM_EVENT_IMAGE: w, h = ctypes.c_uint(), ctypes.c_uint() lib.Toupcam_PullImage(self.cam, ctypes.c_void_p(self._data.ctypes.data), bits, ctypes.byref(w), ctypes.byref(h)) elif nEvent == TOUPCAM_EVENT_STILLIMAGE: w, h = self.get_size() h, w = h.value, w.value still = zeros((h, w), dtype=uint32) lib.Toupcam_PullStillImage(self.cam, ctypes.c_void_p(still.ctypes.data), bits, None, None) self._do_save(still) callback = ctypes.CFUNCTYPE(None, ctypes.c_uint, ctypes.c_void_p) self._frame_fn = callback(get_frame) result = lib.Toupcam_StartPullModeWithCallback(self.cam, self._frame_fn) return success(result)
def put(self): current_user = get_jwt_identity() # print(current_user) student = check_student_by_username(current_user) # print(student.id) profile = db.session.query(Profile).filter_by( student_id=student.id).first() print(profile.student_id) if 'image' in request.files: file = request.files['image'] profile_image = upload_profile(file) print(profile_image) update_image = update_profile_image(profile_image, student_id=profile.student_id) if update_image: return success(message="Profile image uploaded successfully") return failure("Unable to upload") return failure("Please upload an image")
def cam_open(self): 'Open camera' self.set_esize(self.resolution) args = self.get_size() if not args: print('Camera not open!') return def get_frame(nEvent, ctx): 'callback function, to be stored in _frame_fn' #ctx is not used if nEvent == TOUPCAM_EVENT_STILLIMAGE: w, h = self.get_size() h, w = h.value, w.value still = np.zeros((h, w), dtype=np.uint32) lib.Toupcam_PullStillImage(self.cam, ctypes.c_void_p(still.ctypes.data), None, None, None) # lib.Toupcam_PullStillImage(handle,void_pointer_pImageData, # int bits,unsigned pointer pnWidth,unsigned pointer pnHeight) self._do_save(still) # converts get_frame into a C function # with None returned, and arguments (int, void*) callback = ctypes.CFUNCTYPE(None, ctypes.c_uint, ctypes.c_void_p) self._frame_fn = callback(get_frame) # try to set camera to raw output result1 = lib.Toupcam_put_option(self.cam, ctypes.c_uint(0x04), ctypes.c_uint(0x1)) print('set to raw? result = {}'.format(result1)) # Start Camera Pull Mode result = lib.Toupcam_StartPullModeWithCallback(self.cam, self._frame_fn) return success(result)
def get_firmware_version(self): fw = ctypes.create_string_buffer(16) result = lib.Toupcam_get_FwVersion(self.cam, fw) if success(result): return fw.value
def get_serial(self): sn = ctypes.create_string_buffer(32) result = lib.Toupcam_get_SerialNumber(self.cam, sn) if success(result): sn = sn.value return sn
def get_auto_exposure(self): expo_enabled = ctypes.c_bool() result = lib.Toupcam_get_AutoExpoEnable(self.cam, ctypes.byref(expo_enabled)) if success(result): return expo_enabled.value
def _lib_func(self, func, *args, **kw): ff = getattr(lib, 'Toupcam_{}'.format(func)) result = ff(self.cam, *args, **kw) return success(result)
def post(self): current_user = get_jwt_identity() new_token = create_access_token(identity=current_user, fresh=False) ret = {'access_token': new_token} return success(data=ret)
def get_hardware_version(self): hw = ctypes.create_string_buffer(16) result = lib.Toupcam_get_HwVersion(self.cam, hw) if success(result): return hw.value
def get_esize(self): res = ctypes.c_long() result = lib.Toupcam_get_eSize(self.cam, ctypes.byref(res)) if success(result): return res
def get(self): all_states = select_states() if all_states: states = enumeration_schemas.states_schema.dump(all_states) return success(data=states) return success(data=[])
def get(self): return success(data=select_onboard_images(), message='List of onboarding images')
def get(self, country_id): all_states = select_country_states(country_id) if all_states: states = enumeration_schemas.states_schema.dump(all_states) return success(data=states) return success(data=[])
def get(self, state_id): all_cities = select_state_cities(state_id) if all_cities: cities = enumeration_schemas.cities_schema.dump(all_cities) return success(data=cities) return success(data=[])