Search in sources :

Example 86 with Image

use of com.google.cloud.automl.v1beta1.Image in project hortonmachine by TheHortonMachine.

the class GeopaparazziController method readProjectInfos.

private List<ProjectInfo> readProjectInfos(File[] projectFiles) throws Exception {
    List<ProjectInfo> infoList = new ArrayList<ProjectInfo>();
    for (File geopapDatabaseFile : projectFiles) {
        try (SqliteDb db = new SqliteDb()) {
            db.open(geopapDatabaseFile.getAbsolutePath());
            ProjectInfo resInfo = db.execOnConnection(connection -> {
                String projectInfo = GeopaparazziUtilities.getProjectInfo(connection, true);
                ProjectInfo info = new ProjectInfo();
                info.databaseFile = geopapDatabaseFile;
                info.fileName = geopapDatabaseFile.getName();
                info.metadata = projectInfo;
                List<org.hortonmachine.gears.io.geopaparazzi.geopap4.Image> imagesList = DaoImages.getImagesList(connection);
                info.images = imagesList.toArray(new org.hortonmachine.gears.io.geopaparazzi.geopap4.Image[0]);
                List<Note> notesList = DaoNotes.getNotesList(connection, null);
                info.notes = notesList;
                List<GpsLog> logsList = DaoGpsLog.getLogsList(connection);
                info.logs = logsList;
                return info;
            });
            infoList.add(resInfo);
        }
    }
    return infoList;
}
Also used : SqliteDb(org.hortonmachine.dbs.spatialite.hm.SqliteDb) ArrayList(java.util.ArrayList) LineString(org.locationtech.jts.geom.LineString) Image(org.hortonmachine.gears.io.geopaparazzi.geopap4.Image) Note(org.hortonmachine.gears.io.geopaparazzi.geopap4.Note) File(java.io.File) DaoGpsLog(org.hortonmachine.gears.io.geopaparazzi.geopap4.DaoGpsLog) GpsLog(org.hortonmachine.gears.io.geopaparazzi.geopap4.DaoGpsLog.GpsLog)

Example 87 with Image

use of com.google.cloud.automl.v1beta1.Image in project hortonmachine by TheHortonMachine.

the class GeopaparazziController method loadProjectData.

/**
 * Extract data from the db and add them to the map view.
 *
 * @param projectTemplate
 * @return
 * @throws Exception
 */
public void loadProjectData(ProjectInfo currentSelectedProject, boolean zoomTo) throws Exception {
    if (geopapDataLayer != null)
        geopapDataLayer.removeAllRenderables();
    Envelope bounds = new Envelope();
    File dbFile = currentSelectedProject.databaseFile;
    try (Connection connection = DriverManager.getConnection("jdbc:sqlite:" + dbFile.getAbsolutePath())) {
        // NOTES
        List<String[]> noteDataList = GeopaparazziUtilities.getNotesText(connection);
        StringBuilder sb = new StringBuilder();
        sb.append("\n\n// GP NOTES\n");
        int index = 0;
        PointPlacemarkAttributes notesAttributes = new PointPlacemarkAttributes();
        // notesAttributes.setLabelMaterial(mFillMaterial);
        // notesAttributes.setLineMaterial(mFillMaterial);
        // notesAttributes.setUsePointAsDefaultImage(true);
        notesAttributes.setImage(ImageCache.getInstance().getBufferedImage(ImageCache.NOTE));
        notesAttributes.setLabelMaterial(new Material(Color.BLACK));
        // notesAttributes.setScale(mMarkerSize);
        for (String[] noteData : noteDataList) {
            // [lon, lat, altim, dateTimeString, text, descr]
            double lon = Double.parseDouble(noteData[0]);
            double lat = Double.parseDouble(noteData[1]);
            String altim = noteData[2];
            String date = noteData[3];
            String text = noteData[4];
            String descr = noteData[5];
            PointPlacemark marker = new PointPlacemark(Position.fromDegrees(lat, lon, 0));
            marker.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);
            marker.setLabelText(text + " (" + date + ")");
            marker.setAttributes(notesAttributes);
            if (geopapDataLayer != null)
                geopapDataLayer.addRenderable(marker);
            bounds.expandToInclude(lon, lat);
        }
        /*
             * IMAGES
             */
        PointPlacemarkAttributes imageAttributes = new PointPlacemarkAttributes();
        imageAttributes.setImage(ImageCache.getInstance().getBufferedImage(ImageCache.DBIMAGE));
        imageAttributes.setLabelMaterial(new Material(Color.GRAY));
        for (org.hortonmachine.gears.io.geopaparazzi.geopap4.Image image : currentSelectedProject.images) {
            double lon = image.getLon();
            double lat = image.getLat();
            PointPlacemark marker = new PointPlacemark(Position.fromDegrees(lat, lon, 0));
            marker.setAltitudeMode(WorldWind.CLAMP_TO_GROUND);
            marker.setLabelText(image.getName());
            marker.setAttributes(imageAttributes);
            if (geopapDataLayer != null)
                geopapDataLayer.addRenderable(marker);
            bounds.expandToInclude(lon, lat);
        }
        try (Statement statement = connection.createStatement()) {
            // set timeout to 30 sec.
            statement.setQueryTimeout(30);
            String sql = // 
            "select " + GpsLogsTableFields.COLUMN_ID.getFieldName() + // 
            "," + GpsLogsTableFields.COLUMN_LOG_STARTTS.getFieldName() + // 
            "," + GpsLogsTableFields.COLUMN_LOG_ENDTS.getFieldName() + // 
            "," + // 
            GpsLogsTableFields.COLUMN_LOG_TEXT.getFieldName() + " from " + // 
            TABLE_GPSLOGS;
            boolean useGpsElev = _useGpsElevationsCheckbox.isSelected();
            int altitudeMode = WorldWind.CLAMP_TO_GROUND;
            if (useGpsElev) {
                altitudeMode = WorldWind.ABSOLUTE;
            }
            // first get the logs
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()) {
                long id = rs.getLong(1);
                long startDateTime = rs.getLong(2);
                String startDateTimeString = ETimeUtilities.INSTANCE.TIME_FORMATTER_LOCAL.format(new Date(startDateTime));
                long endDateTime = rs.getLong(3);
                String endDateTimeString = ETimeUtilities.INSTANCE.TIME_FORMATTER_LOCAL.format(new Date(endDateTime));
                String text = rs.getString(4);
                // points
                String query = // 
                "select " + GpsLogsDataTableFields.COLUMN_DATA_LAT.getFieldName() + "," + GpsLogsDataTableFields.COLUMN_DATA_LON.getFieldName() + "," + GpsLogsDataTableFields.COLUMN_DATA_ALTIM.getFieldName() + "," + // 
                GpsLogsDataTableFields.COLUMN_DATA_TS.getFieldName() + " from " + TABLE_GPSLOG_DATA + // 
                " where " + GpsLogsDataTableFields.COLUMN_LOGID.getFieldName() + " = " + id + " order by " + GpsLogsDataTableFields.COLUMN_DATA_TS.getFieldName();
                List<Position> verticesList = new ArrayList<>();
                try (Statement newStatement = connection.createStatement()) {
                    newStatement.setQueryTimeout(30);
                    ResultSet result = newStatement.executeQuery(query);
                    while (result.next()) {
                        double lat = result.getDouble(1);
                        double lon = result.getDouble(2);
                        double elev = 0.0;
                        if (useGpsElev)
                            elev = result.getDouble(3);
                        Position pos = Position.fromDegrees(lat, lon, elev);
                        verticesList.add(pos);
                        bounds.expandToInclude(lon, lat);
                    }
                }
                // color
                String colorQuery = // 
                "select " + GpsLogsPropertiesTableFields.COLUMN_PROPERTIES_COLOR.getFieldName() + "," + GpsLogsPropertiesTableFields.COLUMN_PROPERTIES_WIDTH.getFieldName() + " from " + TABLE_GPSLOG_PROPERTIES + // 
                " where " + GpsLogsPropertiesTableFields.COLUMN_LOGID.getFieldName() + " = " + id;
                String colorStr = RED_HEXA;
                int lineWidth = 3;
                try (Statement newStatement = connection.createStatement()) {
                    newStatement.setQueryTimeout(30);
                    ResultSet result = newStatement.executeQuery(colorQuery);
                    if (result.next()) {
                        colorStr = result.getString(1);
                        lineWidth = result.getInt(2);
                        if (colorStr.equalsIgnoreCase("red")) {
                            colorStr = RED_HEXA;
                        }
                    }
                    if (colorStr == null || colorStr.length() == 0) {
                        colorStr = RED_HEXA;
                    }
                }
                Color color = Color.RED;
                try {
                    color = Color.decode(colorStr);
                } catch (Exception e) {
                // ignore Logger.INSTANCE.insertError("","Could not convert color: " +
                // colorStr, e);
                }
                BasicShapeAttributes lineAttributes = new BasicShapeAttributes();
                lineAttributes.setOutlineMaterial(new Material(color));
                lineAttributes.setOutlineWidth(lineWidth);
                Path path = new Path(verticesList);
                path.setAltitudeMode(altitudeMode);
                path.setFollowTerrain(true);
                path.setAttributes(lineAttributes);
                if (geopapDataLayer != null)
                    geopapDataLayer.addRenderable(path);
            }
        }
    }
    if (zoomTo) {
        bounds.expandBy(0.001);
        Sector sector = NwwUtilities.envelope2Sector(new ReferencedEnvelope(bounds, NwwUtilities.GPS_CRS));
        if (wwjPanel != null)
            wwjPanel.goTo(sector, false);
    }
    currentLoadedProject = currentSelectedProject;
}
Also used : ArrayList(java.util.ArrayList) LineString(org.locationtech.jts.geom.LineString) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Envelope(org.locationtech.jts.geom.Envelope) BasicShapeAttributes(gov.nasa.worldwind.render.BasicShapeAttributes) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) PointPlacemark(gov.nasa.worldwind.render.PointPlacemark) ResultSet(java.sql.ResultSet) IHMResultSet(org.hortonmachine.dbs.compat.IHMResultSet) Path(gov.nasa.worldwind.render.Path) TreePath(javax.swing.tree.TreePath) Position(gov.nasa.worldwind.geom.Position) IHMStatement(org.hortonmachine.dbs.compat.IHMStatement) Statement(java.sql.Statement) Sector(gov.nasa.worldwind.geom.Sector) Color(java.awt.Color) Connection(java.sql.Connection) Material(gov.nasa.worldwind.render.Material) GpsPoint(org.hortonmachine.gears.io.geopaparazzi.geopap4.DaoGpsLog.GpsPoint) Date(java.util.Date) PointPlacemarkAttributes(gov.nasa.worldwind.render.PointPlacemarkAttributes) File(java.io.File) Image(org.hortonmachine.gears.io.geopaparazzi.geopap4.Image)

Example 88 with Image

use of com.google.cloud.automl.v1beta1.Image in project hortonmachine by TheHortonMachine.

the class GeopaparazziController method getProjectForImage.

private ProjectInfo getProjectForImage(Image currentSelectedImage) {
    boolean doBreak = false;
    ProjectInfo selectedProject = null;
    for (ProjectInfo projectInfo : projectInfos) {
        for (org.hortonmachine.gears.io.geopaparazzi.geopap4.Image tmpImage : projectInfo.images) {
            if (tmpImage.equals(currentSelectedImage)) {
                selectedProject = projectInfo;
                doBreak = true;
                break;
            }
        }
        if (doBreak) {
            break;
        }
    }
    return selectedProject;
}
Also used : Image(org.hortonmachine.gears.io.geopaparazzi.geopap4.Image)

Example 89 with Image

use of com.google.cloud.automl.v1beta1.Image in project ovirt-engine by oVirt.

the class OpenStackImageProviderProxy method getImageAsDiskImage.

public DiskImage getImageAsDiskImage(String id) {
    DiskImage diskImage = new DiskImage();
    Image glanceImage;
    try {
        glanceImage = getClient().images().show(id).execute();
    } catch (OpenStackResponseException e) {
        log.debug("Exception:", e);
        throw new OpenStackImageException(OpenStackImageException.ErrorType.IMAGE_NOT_FOUND, "Cannot find the specified image.");
    } catch (RuntimeException rte) {
        log.error("Exception:", rte);
        throw new RuntimeException("Failed to import from the repository.");
    }
    validateContainerFormat(glanceImage);
    String shortHash = glanceImage.getId().substring(0, 7);
    if (glanceImage.getName() != null) {
        diskImage.setDiskDescription(glanceImage.getName() + " (" + shortHash + ")");
    } else {
        diskImage.setDiskDescription("Glance disk: " + shortHash);
    }
    setDiskAttributes(diskImage, glanceImage);
    if (glanceImage.getDiskFormat().equals(GlanceImageFormat.RAW.getValue())) {
        diskImage.setVolumeFormat(VolumeFormat.RAW);
    } else if (glanceImage.getDiskFormat().equals(GlanceImageFormat.COW.getValue())) {
        diskImage.setVolumeFormat(VolumeFormat.COW);
    } else {
        throw new OpenStackImageException(OpenStackImageException.ErrorType.UNSUPPORTED_DISK_FORMAT, "Unknown disk format: " + glanceImage.getDiskFormat());
    }
    return diskImage;
}
Also used : OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Image(com.woorea.openstack.glance.model.v2.Image) RepoImage(org.ovirt.engine.core.common.businessentities.storage.RepoImage) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 90 with Image

use of com.google.cloud.automl.v1beta1.Image in project java-automl by googleapis.

the class VisionClassificationPredict method predict.

static void predict(String projectId, String modelId, String filePath) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (PredictionServiceClient client = PredictionServiceClient.create()) {
        // Get the full path of the model.
        ModelName name = ModelName.of(projectId, "us-central1", modelId);
        ByteString content = ByteString.copyFrom(Files.readAllBytes(Paths.get(filePath)));
        Image image = Image.newBuilder().setImageBytes(content).build();
        ExamplePayload payload = ExamplePayload.newBuilder().setImage(image).build();
        PredictRequest predictRequest = PredictRequest.newBuilder().setName(name.toString()).setPayload(payload).putParams("score_threshold", // [0.0-1.0] Only produce results higher than this value
        "0.8").build();
        PredictResponse response = client.predict(predictRequest);
        for (AnnotationPayload annotationPayload : response.getPayloadList()) {
            System.out.format("Predicted class name: %s\n", annotationPayload.getDisplayName());
            System.out.format("Predicted class score: %.2f\n", annotationPayload.getClassification().getScore());
        }
    }
}
Also used : ModelName(com.google.cloud.automl.v1.ModelName) ByteString(com.google.protobuf.ByteString) PredictResponse(com.google.cloud.automl.v1.PredictResponse) ExamplePayload(com.google.cloud.automl.v1.ExamplePayload) Image(com.google.cloud.automl.v1.Image) PredictRequest(com.google.cloud.automl.v1.PredictRequest) PredictionServiceClient(com.google.cloud.automl.v1.PredictionServiceClient) AnnotationPayload(com.google.cloud.automl.v1.AnnotationPayload)

Aggregations

AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)75 Image (com.google.cloud.vision.v1.Image)75 Feature (com.google.cloud.vision.v1.Feature)73 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)72 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)69 ArrayList (java.util.ArrayList)69 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)66 ByteString (com.google.protobuf.ByteString)52 ImageSource (com.google.cloud.vision.v1.ImageSource)41 FileInputStream (java.io.FileInputStream)32 EntityAnnotation (com.google.cloud.vision.v1.EntityAnnotation)28 WebImage (com.google.cloud.vision.v1.WebDetection.WebImage)26 IOException (java.io.IOException)21 ImageContext (com.google.cloud.vision.v1.ImageContext)14 SafeSearchAnnotation (com.google.cloud.vision.v1.SafeSearchAnnotation)11 WebDetection (com.google.cloud.vision.v1.WebDetection)11 LocationInfo (com.google.cloud.vision.v1.LocationInfo)10 Arrays (java.util.Arrays)10 Image (com.google.cloud.compute.v1.Image)9 ImagesClient (com.google.cloud.compute.v1.ImagesClient)9