def gen_rotation_images(objid): rotations = db_session.query(RotationObject.id, RotationObject.ParentDetectionObjectID, \ RotationObject.Location, RotationObject.FileName, RotationObject.RotationAngle) \ .filter(RotationObject.ParentDetectionObjectID == objid) isPositive = db_session.query(DetectionObject).get(objid).IsPosDetect pos_dir = "positive/" if isPositive == 1 or isPositive == None else "negative/" for rotation in rotations: rotationangle = rotation.RotationAngle original_filename = str(db_session().query(DetectionObject.ObjectID, DetectionObject.FileName)\ .filter(DetectionObject.ObjectID == rotation.ParentDetectionObjectID)\ .first().FileName) print original_filename filename = pos_dir + str(rotation.id) + "_rotated_" + original_filename os.system("shell_scripts/rotate_image2.sh " + \ os.path.join(CROPPED_FOLDER, original_filename) + " " +\ os.path.join(ROTATED_FOLDER, filename) + " " + str(rotationangle)) save = RotationObject.query.get(rotation.id) save.FileName = filename save.Location = ROTATED_FOLDER db_session.commit()
def gen_detection_images(obsid = None): detections = db_session().query(DetectionObject.ObjectID, DetectionObject.ParentObsID,\ DetectionObject.Location, DetectionObject.FileName, DetectionObject.XCord,\ DetectionObject.YCord, DetectionObject.Radius) if obsid != None: detections = detections.filter(DetectionObject.ParentObsID == obsid) for detection in detections: radius = detection.Radius*1.4 x = str(detection.XCord - radius) y = str(detection.YCord - radius) radius = radius * 2 original_filename = str(db_session().query(Observation.ObsID, Observation.FileName)\ .filter(Observation.ObsID == detection.ParentObsID).first().FileName) filename = str(detection.ObjectID) + "_cropped_" + original_filename os.system("convert " + os.path.join(app.config['UPLOAD_FOLDER'], original_filename)+ \ " -crop " + str(radius) + "x" + str(radius) + "+" + x + "+" + y \ + " " + os.path.join(CROPPED_FOLDER, filename)) print filename save = DetectionObject.query.get(detection.ObjectID) save.FileName = filename save.Location = CROPPED_FOLDER db_session.commit()