Beispiel #1
0
def photoClassifyThread(linename,voltage,date,fileNames,imagePaths):
    classify = UAVPhotoClassify()
    towers = classify.GetTowerPosition(linename)
    photoDao = PhotoDao()

    classifyTowerRs=[]
    # 进行分类并获取缩略图
    for i in range(len(fileNames)):
        classifyRs = classify.ClassifyPhoto(towers, imagePaths[i], date, save_folder)
        if classifyRs==None:
            return None

        basePath = classifyRs[0]
        paththunmnail=thumbnail_folder+basePath
        dirthumbnail=os.path.dirname(paththunmnail)
        if not os.path.isdir(dirthumbnail):
            os.makedirs(dirthumbnail)
        generateThumbnail(os.path.join(save_folder+basePath),paththunmnail)
        # 添加到数据库中
        towerIdx = classifyRs[1]
        lineid = classifyRs[2]
        rs = photoDao.add_photo(voltage, lineid, towers[towerIdx]['tower_id'], '未分类', database_folder+basePath,
                                  thumbnail_database_folder+ basePath, datetime.datetime.strptime(date,'%Y-%m-%d').date())

        idxTower = int(int(towers[towerIdx]['tower_idx'])*100)
        idxLevel1 = int(idxTower//100)
        idxLevel2 = int((idxTower%100)//10)
        idxLevel3 = int((idxTower%10))
        strIdxTower = str(idxLevel1)
        if(idxLevel2 != 0):
            strIdxTower+='+'+str(idxLevel2)
        if (idxLevel3 != 0):
            strIdxTower += '+' + str(idxLevel3)
        classifyTowerRs.append(strIdxTower)
    return classifyTowerRs
Beispiel #2
0
class PwoerLinePhotoIdxRoute(Resource):
    def __init__(self):
        self.dao = PhotoDao()
        self.userDao = UserDAO

    def post(self):
        # if (request.data != ""):
        #     data = json.loads(request.data)
        #     token = data['token']
        #     toweridx = data['toweridx']
        #     user = self.userDao.verify_token(token, '')
        #     if (not user):
        #          return make_response(jsonify({'error': 'Unauthorized access'}), 401)
        args = parser.parse_args()
        lineidx = args.get('towerid')
        rs = self.dao.query_photos(lineidx)
        if rs == None:
            return make_response(jsonify({'error': 'Unauthorized access'}),
                                 401)
        else:
            return rs
        # else:
        #     return  make_response(jsonify({'error': 'Unauthorized access'}), 401)

    def get(self):
        return self.post()
Beispiel #3
0
class PowerPhotoIdx(Resource):
    def __init__(self):
        self.dao = PhotoDao()
        self.userDao = UserDAO()

    def post(self):
        # if (request.data != ""):
        #     data = json.loads(request.data)
        #     token = data['token']
        #     toweridx = data['toweridx']
        #     user = self.userDao.verify_token(token, '')
        #     if (not user):
        #          return make_response(jsonify({'error': 'Unauthorized access'}), 401)
        args = parser.parse_args()
        photoid = args.get('photoid')
        rs = self.dao.query_photo_idx(photoid)
        if rs == None:
            return make_response(
                jsonify({
                    'error': '根据照片id查询杆塔照片失败',
                    'errorcode': 10000000
                }), 401)
        else:
            return rs
        # else:
        #     return  make_response(jsonify({'error': 'Unauthorized access'}), 401)

    def get(self):
        return self.post()
Beispiel #4
0
class PowerPhotoSearch(Resource):
    def __init__(self):
        self.dao = PhotoDao()
        self.userDao = UserDAO()

    def post(self):
        # if (request.data != ""):
        #     data = json.loads(request.data)
        #     token = data['token']
        #     toweridx = data['toweridx']
        #     user = self.userDao.verify_token(token, '')
        #     if (not user):
        #          return make_response(jsonify({'error': 'Unauthorized access'}), 401)
        args = parser.parse_args()
        toweridx = args.get('towerid')
        start_time = datetime.strptime(args.get('start_time'),
                                       '%Y-%m-%d').date()
        end_time = datetime.strptime(args.get('end_time'), '%Y-%m-%d').date()
        rs = self.dao.query_photo_condition(start_time, end_time, toweridx)
        if rs == None:
            return make_response(
                jsonify({
                    'error': '查询杆塔照片失败',
                    'errorcode': 10000000
                }), 401)
        else:
            return rs
        # else:
        #     return  make_response(jsonify({'error': 'Unauthorized access'}), 401)

    def get(self):
        return self.post()
Beispiel #5
0
class FileUpload(Resource):
    def __init__(self):
        self.photoDao = PhotoDao()
        self.userDao = UserDAO()

    #检查文件后缀是否符合要求(是否是照片数据)
    #param filename:照片文件的文件名
    def allowed_file(self,filename):
        return '.' in filename and \
               filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
    #生成缩略图
    #param pathSrc:输入图片文件路径
    #param pathThumbnail:输入缩略图路径
    def generateThumbnail(self,pathSrc,pathThumbnail):
        im = Image.open(pathSrc)
        factor=0.2
        w, h = im.size
        im.thumbnail((w *factor, h*factor))
        im.save(pathThumbnail,'jpeg')

    def post(self):
        if (request.form != ""):
            data = request.form
            #token = data['token'] #要不要登录
            line_id = data['lineid']
            tower_id = data['towerid']
            voltage = data['voltage']
            classify = data['classify']
            date=datetime.datetime.strptime(data['date'],'%Y-%m-%d').date()
            image = request.files['image']

            #获取文件存储路径
            file_folder = save_folder+'/'+voltage+'/'+line_id+'/'+tower_id+'/'+data['date']+'/'+classify
            thumbnail =thumbnail_folder+'/'+voltage+'/'+line_id+'/'+tower_id+'/'+data['date']+'/'+classify
            if not os.path.isdir(file_folder):
                os.makedirs(file_folder)
            if not os.path.isdir(thumbnail):
                os.makedirs(thumbnail)
            if image and self.allowed_file(image.filename):
                filename = secure_filename(image.filename)
                image.save(os.path.join(file_folder, filename))
                self.generateThumbnail(os.path.join(file_folder, filename),os.path.join(thumbnail, filename))
                #文件服务器浏览路径
                db_folder=database_folder+'/'+voltage+'/'+line_id+'/'+tower_id+'/'+data['date']+'/'+classify
                db_thumbnail=thumbnail_database_folder+'/'+voltage+'/'+line_id+'/'+tower_id+'/'+data['date']+'/'+classify
                rs = self.photoDao.add_photo(voltage,line_id,tower_id,classify,os.path.join(db_folder, filename),os.path.join(db_thumbnail, filename),date)
                if rs == 1:
                    return make_response(jsonify({'seccess': '照片上传成功'}), 200)
            else:
                return make_response(jsonify({'error': '照片参数输入错误','errorcode':10000000}), 401)
        else:
            return make_response(jsonify({'error': '照片参数输入错误','errorcode':10000000}), 401)

    def get(self):
        return self.post()
Beispiel #6
0
class PowerTowerPhotoIdxRoute(Resource):
    def __init__(self):
        self.dao = PhotoDao()
        self.userDao = UserDAO()

    def post(self):
        # if (request.data != ""):
        #     data = json.loads(request.data)
        #     token = data['token']
        #     toweridx = data['toweridx']
        #     user = self.userDao.verify_token(token, '')
        #     if (not user):
        #          return make_response(jsonify({'error': 'Unauthorized access'}), 401)
        args = parser.parse_args()
        toweridx = args.get('towerid')
        strDate = args.get('photo_date')

        rs = None
        if strDate == None:
            rs = self.dao.query_photos_towerid(toweridx)
        else:
            photodate = datetime.strptime(strDate, '%Y-%m-%d')
            rs = self.dao.query_photos_time(toweridx, photodate)

        if rs == None:
            return make_response(
                jsonify({
                    'error': '查询杆塔照片失败',
                    'errorcode': 10000000
                }), 401)
        else:
            return rs
        # else:
        #     return  make_response(jsonify({'error': 'Unauthorized access'}), 401)

    def get(self):
        return self.post()
Beispiel #7
0
 def __init__(self):
     self.dao = PhotoDao()
     self.userDao = UserDAO