Esempio n. 1
0
 def update_obj(cls, args_dict, location_obj):
     if location_obj is None:
         raise ObjectNotExist('Location id is wrong')
     if StereoCalibration.id.name not in args_dict:
         raise ObjectNotExist('StereoCalibration id is wrong')
     ste = StereoCalibration.get_by_id(args_dict[StereoCalibration.id.name])
     if ste is None:
         raise ObjectNotExist('StereoCalibration id is wrong')
     ste.set_location(location_obj)
     # add origin data which are not in req data
     for k in StereoCalibration.__table__.columns:
         if k.name in args_dict and args_dict[k.name] is not None:
             if k.name == cls.l_camera_id.name:
                 ste.set_left_cam(args_dict[k.name])
             elif k.name == cls.r_camera_id.name:
                 ste.set_right_cam(args_dict[k.name])
             elif k.name == cls.l_cam_matrix.name or     \
                  k.name == cls.r_cam_matrix.name or     \
                  k.name == cls.l_dist_coeffs.name or    \
                  k.name == cls.r_dist_coeffs.name or    \
                  k.name == cls.rt_cam_a2_cam_b.name or  \
                  k.name == cls.stereo_E.name or         \
                  k.name == cls.stereo_F.name or         \
                  k.name == cls.stereo_R.name:
                 setattr(ste, k.name, ste.to_uri(args_dict[k.name]))
             else:
                 setattr(ste, k.name, args_dict[k.name])
     return ste
Esempio n. 2
0
    def update_obj(cls, args_dict, loc_obj):

        if SingleCalibration.id.name not in args_dict:
            raise ObjectNotExist('SingleCalibration id is wrong')
        sin = SingleCalibration.get_by_id(args_dict[SingleCalibration.id.name])
        if sin is None:
            raise ObjectNotExist('SingleCalibration id is wrong')
        sin.set_location(loc_obj)
        # add origin data which are not in req data
        for k in SingleCalibration.__table__.columns:
            if k.name in args_dict and args_dict[k.name] is not None:
                if k.name == cls.camera_id.name:
                    sin.set_cam(args_dict[k.name])
                elif k.name == cls.img_size.name:
                    sin.set_size(args_dict[k.name])
                elif k.name == cls.n_camera_args.name or        \
                     k.name == cls.p_camera_args.name or        \
                     k.name == cls.n_distortion_args.name or    \
                     k.name == cls.p_distortion_args.name or    \
                     k.name == cls.n_toc.name or                \
                     k.name == cls.p_toc.name or                \
                     k.name == cls.found_mask.name or           \
                     k.name == cls.img_pts.name or              \
                     k.name == cls.obj_pts.name:
                    setattr(sin, k.name, sin.to_uri(args_dict[k.name]))
                else:
                    setattr(sin, k.name, args_dict[k.name])
        return sin
Esempio n. 3
0
 def post(self, id=None):
     self.logger.info("%s: post" % __name__)
     if id is None:
         return self.make_http_response(
             False,
             'need a location id, single data should be bind to a location item'
         )
     try:
         location_obj = LocationList.get_by_id(id)
         if location_obj is None:
             raise ObjectNotExist('Location id is wrong')
         if OBJECT_DATA_N not in self.req_dict:
             return self.make_http_response(False,
                                            'request data is invalid')
         req_obj = InverseTest.to_obj(self.req_dict[OBJECT_DATA_N],
                                      location_obj)
         if InverseTest.is_exist(req_obj):
             return self.make_http_response(
                 False, 'InverseTest is exist, can not add any more!')
         # commit the data , so id will refresh from database
         InverseTest.add(req_obj, True)
         location_obj.set_inv_id(req_obj.id)
         LocationList.add(location_obj)
     except ObjectNotExist as e:
         self.logger.error(e.what())
         return self.make_http_response(False, e.what())
     return self.make_http_response(True, 'Add InverseTest Success!')
Esempio n. 4
0
 def to_uri(self, filename):
     if filename is None:
         return None
     abs_path = self.location_obj.get_upload_path() + self.__class__.__name__ + '/' + filename
     if not os.path.exists(abs_path):
         print('set uri failed: ', abs_path)
         raise ObjectNotExist("%s file is not exist, please upload first" % filename)
     return DOWNLOAD_ROOT_URI + str(self.location_obj.id) + '/' + self.__class__.__name__ + '/' + filename
Esempio n. 5
0
    def update_obj(cls, args_dict):
        if GenerateData.id.name not in args_dict:
            raise ObjectNotExist('GenerateData id is wrong')
        gen = GenerateData.get_by_id(args_dict[GenerateData.id.name])
        if gen is None:
            raise ObjectNotExist('GenerateData id is wrong')

        # add origin data which are not in req data
        for k in GenerateData.__table__.columns:
            if k.name in args_dict:
                if k.name == GenerateData.robot_id.name:
                    gen.set_robot_id(args_dict[k.name])
                elif k.name == GenerateData.user_id.name:
                    gen.set_user_id(args_dict[k.name])
                else:
                    setattr(gen, k.name, args_dict[k.name])
        return gen
Esempio n. 6
0
    def update_obj(cls, args_dict, location_obj):
        if location_obj is None:
            raise ObjectNotExist('Location id is wrong')
        if InverseTest.id.name not in args_dict:
            raise ObjectNotExist('InverseTest id is wrong')
        inv = InverseTest.get_by_id(args_dict[InverseTest.id.name])
        if inv is None:
            raise ObjectNotExist('InverseTest id is wrong')
        inv.set_location(location_obj)

        # add origin data which are not in req data
        for k in InverseTest.__table__.columns:
            if k.name in args_dict and args_dict[k.name] is not None:
                if k.name == cls.opt_all_ik.name or         \
                     k.name == cls.ik_err.name or           \
                     k.name == cls.l_cam_img_pts.name or    \
                     k.name == cls.r_cam_img_pts.name:
                    setattr(inv, k.name, inv.to_uri(args_dict[k.name]))
                else:
                    setattr(inv, k.name, args_dict[k.name])
        return inv
Esempio n. 7
0
    def update_obj(cls, args_dict):
        if LocationList.id.name not in args_dict:
            raise ObjectNotExist('LocationList id is wrong')
        loc = LocationList.get_by_id(args_dict[LocationList.id.name])
        if loc is None:
            raise ObjectNotExist('LocationList id is wrong')

        # add origin data which are not in req data
        for k in LocationList.__table__.columns:
            if k.name in args_dict:
                if k.name == LocationList.g_id.name:
                    loc.set_gid(args_dict[k.name])
                elif k.name == LocationList.single_ca_id.name:
                    loc.set_single_id(args_dict[k.name])
                elif k.name == LocationList.stereo_ca_id.name:
                    loc.set_stereo_id(args_dict[k.name])
                elif k.name == LocationList.dh_id.name:
                    loc.set_dh_id(args_dict[k.name])
                elif k.name == LocationList.inv_id.name:
                    loc.set_inv_id(args_dict[k.name])
        return loc
Esempio n. 8
0
 def update_obj(cls, args_dict, location_obj):
     if location_obj is None:
         raise ObjectNotExist('Location id is wrong')
     if DH_Optimised.id.name not in args_dict:
         raise ObjectNotExist('DH_Optimised id is wrong')
     dh_obj = DH_Optimised.get_by_id(args_dict[DH_Optimised.id.name])
     if dh_obj is None:
         raise ObjectNotExist('DH_Optimised id is wrong')
     dh_obj.set_location(location_obj)
     # add origin data which are not in req data
     for k in DH_Optimised.__table__.columns:
         if k.name in args_dict and args_dict[k.name] is not None:
             if k.name == cls.model.name:
                 dh_obj.set_model(args_dict[k.name])
             elif k.name == cls.angle_offset_full.name or    \
                  k.name == cls.joint_scale_factor.name or   \
                  k.name == cls.refine_pixel_err.name or     \
                  k.name == cls.robot_param.name or          \
                  k.name == cls.tot.name or                  \
                  k.name == cls.trc.name:
                 setattr(dh_obj, k.name, dh_obj.to_uri(args_dict[k.name]))
             else:
                 setattr(dh_obj, k.name, args_dict[k.name])
     return dh_obj
Esempio n. 9
0
    def to_obj(cls, args_dict, location_obj):
        if location_obj is None:
            raise ObjectNotExist('Location id is wrong')

        for k in InverseTest.__table__.columns:
            if k.name not in args_dict:
                args_dict[k.name] = None

        new_dh = InverseTest(args_dict[InverseTest.opt_all_ik.name],
                             args_dict[InverseTest.ik_err.name],
                             args_dict[InverseTest.l_cam_img_pts.name],
                             args_dict[InverseTest.r_cam_img_pts.name],
                             args_dict[InverseTest.pixel_err.name],
                             args_dict[InverseTest.total_pixel_err.name],
                             location_obj)
        return new_dh
Esempio n. 10
0
 def _save_files(self, files_dict, loc_obj, table_name, is_overwrite):
     if not isinstance(files_dict, dict):
         raise ObjectNotExist("File dict arg is not a type of dict")
     ret_dict = {}
     for k, v in files_dict.items():
         ret_dict[k] = True
         if not is_overwrite and loc_obj.is_own_file(v.filename):
             return self.make_http_response(False, 'file %s has been upload, maybe you want to cover it')
         if not v or not self._filename_check(v.filename):
             ret_dict[k] = False
             continue
         file_path = UPLOAD_FOLDER + str(loc_obj.id) + '/' + table_name
         self._mkdirs(file_path)
         abs_path = file_path + '/' + v.filename
         v.save(abs_path)
     return self.make_http_response(True, 'upload result', msg_obj=ret_dict)
Esempio n. 11
0
    def to_obj(cls, args_dict, location_obj):
        if location_obj is None:
            raise ObjectNotExist('Location id is wrong')

        for k in StereoCalibration.__table__.columns:
            if k.name not in args_dict:
                args_dict[k.name] = None

        new_stereo = StereoCalibration(
            args_dict[StereoCalibration.l_camera_id.name],
            args_dict[StereoCalibration.r_camera_id.name],
            args_dict[StereoCalibration.l_cam_matrix.name],
            args_dict[StereoCalibration.r_cam_matrix.name],
            args_dict[StereoCalibration.l_dist_coeffs.name],
            args_dict[StereoCalibration.r_dist_coeffs.name],
            args_dict[StereoCalibration.rt_cam_a2_cam_b.name],
            args_dict[StereoCalibration.stereo_E.name],
            args_dict[StereoCalibration.stereo_F.name],
            args_dict[StereoCalibration.stereo_R.name],
            args_dict[StereoCalibration.pixel_err.name], location_obj)
        return new_stereo
Esempio n. 12
0
    def to_obj(cls, args_dict, location_obj):
        if location_obj is None:
            raise ObjectNotExist('Location id is wrong')
        for k in SingleCalibration.__table__.columns:
            if k.name not in args_dict:
                args_dict[k.name] = None

        new_single = SingleCalibration(args_dict[SingleCalibration.camera_id.name],
                                       args_dict[SingleCalibration.n_camera_args.name],
                                       args_dict[SingleCalibration.p_camera_args.name],
                                       args_dict[SingleCalibration.n_distortion_args.name],
                                       args_dict[SingleCalibration.p_distortion_args.name],
                                       args_dict[SingleCalibration.n_toc.name],
                                       args_dict[SingleCalibration.p_toc.name],
                                       args_dict[SingleCalibration.n_projection_err.name],
                                       args_dict[SingleCalibration.p_projection_err.name],
                                       args_dict[SingleCalibration.found_mask.name],
                                       args_dict[SingleCalibration.img_pts.name],
                                       args_dict[SingleCalibration.img_size.name],
                                       args_dict[SingleCalibration.obj_pts.name],
                                       location_obj
                                       )
        return new_single
Esempio n. 13
0
 def set_cam(self, cam_id):
     if not Camera.is_exist_id(cam_id):
         raise ObjectNotExist("camera is not exits which id is %s" % cam_id)
     self.camera_id = cam_id
Esempio n. 14
0
 def set_gid(self, id):
     if not GenerateData.is_exist_id(id):
         raise ObjectNotExist('enter generate data id is not exists')
     self.g_id = id
Esempio n. 15
0
 def set_user_id(self, user_id):
     if not User.is_exist_id(user_id):
         raise ObjectNotExist('%s is not exist which id is %s' %
                              (User.__name__, user_id))
     self.user_id = user_id
Esempio n. 16
0
 def set_robot_id(self, robot_id):
     if not Robot.is_exist_id(robot_id):
         raise ObjectNotExist('%s is not exist which id is %s' %
                              (Robot.__name__, robot_id))
     self.robot_id = robot_id
Esempio n. 17
0
 def set_single_id(self, id):
     if id is not None and not SingleCalibration.is_exist_id(id):
         raise ObjectNotExist('enter single data id is not exists')
     self.single_ca_id = id
Esempio n. 18
0
 def set_stereo_id(self, id):
     if id is not None and not StereoCalibration.is_exist_id(id):
         raise ObjectNotExist('enter stereo data id is not exists')
     self.stereo_ca_id = id
Esempio n. 19
0
 def set_dh_id(self, id):
     if id is not None and not DH_Optimised.is_exist_id(id):
         raise ObjectNotExist('enter dh data id is not exists')
     self.dh_id = id
Esempio n. 20
0
 def set_model(self, model):
     if model not in DH_Model.__dict__.keys():
         raise ObjectNotExist("mode should be one of %s" % list(DH_Model))
     self.model = model
Esempio n. 21
0
 def set_inv_id(self, id):
     if id is not None and not InverseTest.is_exist_id(id):
         raise ObjectNotExist('enter inv data id is not exists')
     self.inv_id = id