Search in sources :

Example 21 with Image

use of com.woorea.openstack.glance.model.v2.Image in project ovirt-engine by oVirt.

the class OpenStackImageProviderProxy method setCowVirtualSizeAndQcowCompat.

private void setCowVirtualSizeAndQcowCompat(DiskImage diskImage, Image glanceImage) {
    // For the qcow2 format we need to download the image header and read the virtual size from there
    byte[] imgContent = new byte[72];
    ImageDownload downloadImage = getClient().images().download(glanceImage.getId()).execute();
    try (InputStream inputStream = downloadImage.getInputStream()) {
        int bytesRead = inputStream.read(imgContent, 0, imgContent.length);
        if (bytesRead != imgContent.length) {
            throw new OpenStackImageException(OpenStackImageException.ErrorType.UNABLE_TO_DOWNLOAD_IMAGE, "Unable to read image header: " + bytesRead);
        }
    } catch (IOException e) {
        throw new OpenStackImageException(OpenStackImageException.ErrorType.UNABLE_TO_DOWNLOAD_IMAGE, "Unable to download image");
    }
    ByteBuffer b = ByteBuffer.wrap(imgContent);
    int qcow2Signature = b.getInt();
    int qcow2Version = b.getInt();
    QcowCompat qcowCompat = QcowCompat.forQcowHeaderVersion(qcow2Version);
    if (qcow2Signature == QCOW2_SIGNATURE && qcowCompat != null && qcowCompat != QcowCompat.Undefined) {
        b.position(QCOW2_SIZE_OFFSET);
        diskImage.setSize(b.getLong());
        diskImage.setQcowCompat(qcowCompat);
    } else {
        throw new OpenStackImageException(OpenStackImageException.ErrorType.UNRECOGNIZED_IMAGE_FORMAT, "Unable to recognize QCOW2 format");
    }
}
Also used : QcowCompat(org.ovirt.engine.core.common.businessentities.storage.QcowCompat) InputStream(java.io.InputStream) ImageDownload(com.woorea.openstack.glance.model.v2.ImageDownload) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 22 with Image

use of com.woorea.openstack.glance.model.v2.Image in project ovirt-engine by oVirt.

the class OpenStackImageProviderProxy method getAllImagesAsRepoImages.

public List<RepoImage> getAllImagesAsRepoImages(Integer listSize, Integer totalListSize) {
    ArrayList<RepoImage> repoImages = new ArrayList<>();
    long currentTime = System.currentTimeMillis();
    Images images = null;
    do {
        OpenStackRequest<Images> listRequest = getClient().images().list(true).queryParam("limit", listSize).queryParam("sort_key", "name").queryParam("sort_dir", "asc");
        if (images != null) {
            listRequest.queryParam("marker", images.getList().get(images.getList().size() - 1).getId());
        }
        images = listRequest.execute();
        for (Image glanceImage : images) {
            RepoImage repoImage = imageToRepoImage(glanceImage);
            repoImage.setLastRefreshed(currentTime);
            repoImages.add(repoImage);
        }
    } while (images.getList().size() >= listSize && totalListSize != null && repoImages.size() < totalListSize);
    return repoImages;
}
Also used : RepoImage(org.ovirt.engine.core.common.businessentities.storage.RepoImage) Images(com.woorea.openstack.glance.model.v2.Images) ArrayList(java.util.ArrayList) 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)

Example 23 with Image

use of com.woorea.openstack.glance.model.v2.Image in project hortonmachine by TheHortonMachine.

the class GeopaparazziController method init.

@SuppressWarnings({ "serial" })
private void init() {
    _infoArea = new JTextPane();
    // _infoArea.setDocument(new SqlDocument());
    _infoArea.setContentType("text/html");
    _infoArea.setEditable(false);
    _infoScroll.setViewportView(_infoArea);
    // _infoScroll.setMinimumSize(new Dimension(10, 200));
    _chartHolder.setLayout(new BorderLayout());
    _loadFolderButton.setIcon(ImageCache.getInstance().getImage(ImageCache.REFRESH));
    _loadFolderButton.setText("");
    _loadFolderButton.setPreferredSize(preferredButtonSize);
    _loadFolderButton.addActionListener(e -> {
        final File geopaparazziFolder = new File(_projectsFolderTextfield.getText());
        if (!geopaparazziFolder.exists()) {
            GuiUtilities.showWarningMessage(this, null, "The projects folder doesn't exist.");
            return;
        }
        File[] projectFiles = GeopaparazziUtilities.getGeopaparazziFiles(geopaparazziFolder);
        try {
            projectInfos = readProjectInfos(projectFiles);
            layoutTree(projectInfos, false);
            _filterTextfield.setText("");
        } catch (Exception e1) {
            Logger.INSTANCE.insertError("", "error", e1);
        }
    });
    _projectsFolderBrowseButton.setPreferredSize(preferredButtonSize);
    _projectsFolderBrowseButton.addActionListener(e -> {
        File[] openFiles = guiBridge.showOpenDirectoryDialog("Open projects folder", PreferencesHandler.getLastFile());
        if (openFiles != null && openFiles.length > 0) {
            try {
                PreferencesHandler.setLastPath(openFiles[0].getAbsolutePath());
            } catch (Exception e1) {
                Logger.INSTANCE.insertError("", "ERROR", e1);
            }
        } else {
            return;
        }
        _projectsFolderTextfield.setText(openFiles[0].getAbsolutePath());
    });
    String lastSavedPath = prefsMap.get(GuiBridgeHandler.LAST_GP_PROJECTS_PATH);
    _projectsFolderTextfield.setText(lastSavedPath);
    _filterTextfield.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            String filterText = _filterTextfield.getText().toLowerCase();
            final List<ProjectInfo> filtered = new ArrayList<ProjectInfo>();
            if (filterText == null) {
                filtered.addAll(projectInfos);
            } else {
                for (ProjectInfo projectInfo : projectInfos) {
                    if (projectInfo.fileName.toLowerCase().contains(filterText) || projectInfo.metadata.toLowerCase().contains(filterText)) {
                        filtered.add(projectInfo);
                    }
                }
            }
            layoutTree(filtered, false);
        }
    });
    addComponentListener(new ComponentListener() {

        public void componentShown(ComponentEvent e) {
        }

        public void componentResized(ComponentEvent e) {
        }

        public void componentMoved(ComponentEvent e) {
        }

        public void componentHidden(ComponentEvent e) {
            onClose();
        }
    });
    try {
        _databaseTreeView.setMinimumSize(new Dimension(300, 200));
        addJtreeDragNDrop();
        addJtreeContextMenu();
        _databaseTree.setRootVisible(false);
        _databaseTree.setCellRenderer(new DefaultTreeCellRenderer() {

            @Override
            public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
                super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
                if (value instanceof ProjectInfo) {
                    setIcon(ImageCache.getInstance().getImage(ImageCache.DATABASE));
                } else if (value instanceof Image) {
                    setIcon(ImageCache.getInstance().getImage(ImageCache.DBIMAGE));
                } else if (value instanceof GpsLog) {
                    setIcon(ImageCache.getInstance().getImage(ImageCache.GEOM_LINE));
                } else if (value instanceof Note) {
                    setIcon(ImageCache.getInstance().getImage(ImageCache.NOTE));
                }
                return this;
            }
        });
        _databaseTree.addTreeSelectionListener(new TreeSelectionListener() {

            public void valueChanged(TreeSelectionEvent evt) {
                TreePath[] paths = evt.getPaths();
                currentSelectedProject = null;
                currentSelectedImage = null;
                currentSelectedNote = null;
                currentSelectedGpsLog = null;
                _chartHolder.removeAll();
                if (paths.length > 0) {
                    Object selectedItem = paths[0].getLastPathComponent();
                    if (selectedItem instanceof ProjectInfo) {
                        currentSelectedProject = (ProjectInfo) selectedItem;
                        selectProjectInfo(currentSelectedProject);
                        Logger.INSTANCE.insertDebug("", "Selected project: " + currentSelectedProject.fileName);
                    }
                    if (selectedItem instanceof Image) {
                        currentSelectedImage = (Image) selectedItem;
                        currentSelectedProject = getProjectForImage(currentSelectedImage);
                        selectImage(currentSelectedImage);
                        Logger.INSTANCE.insertDebug("", "Selected image: " + currentSelectedImage.getName() + " of project " + currentSelectedProject.fileName);
                    }
                    if (selectedItem instanceof GpsLog) {
                        currentSelectedGpsLog = (GpsLog) selectedItem;
                        currentSelectedProject = getProjectForGpsLog(currentSelectedGpsLog);
                        selectGpsLog(currentSelectedGpsLog);
                        Logger.INSTANCE.insertDebug("", "Selected gpslog: " + currentSelectedGpsLog.text + " of project " + currentSelectedProject.fileName);
                    }
                    if (selectedItem instanceof Note) {
                        currentSelectedNote = (Note) selectedItem;
                        currentSelectedProject = getProjectForNote(currentSelectedNote);
                        selectNote(currentSelectedNote);
                        Logger.INSTANCE.insertDebug("", "Selected note: " + currentSelectedNote.simpleText + " of project " + currentSelectedProject.fileName);
                    }
                }
            }
        });
        _databaseTree.setVisible(false);
    } catch (Exception e1) {
        Logger.INSTANCE.insertError("", "Error", e1);
    }
    layoutTree(null, false);
    Component wwjPanelComponent = null;
    try {
        wwjPanelComponent = NwwPanel.createNwwPanel(true);
    } catch (UnsatisfiedLinkError e1) {
    // ignore
    }
    if (wwjPanelComponent instanceof NwwPanel) {
        _nwwHolder.setLayout(new BorderLayout());
        _nwwHolder.add(wwjPanelComponent, BorderLayout.CENTER);
        wwjPanel = (NwwPanel) wwjPanelComponent;
        wwjPanel.addOsmLayer();
        geopapDataLayer = new RenderableLayer();
        wwjPanel.addLayer(geopapDataLayer);
    } else {
        _nwwHolderFrame.setVisible(false);
        _chartHolderFrame.setVisible(false);
        setPreferredSize(new Dimension(400, 600));
    }
}
Also used : RenderableLayer(gov.nasa.worldwind.layers.RenderableLayer) ComponentListener(java.awt.event.ComponentListener) KeyAdapter(java.awt.event.KeyAdapter) TreeSelectionListener(javax.swing.event.TreeSelectionListener) LineString(org.locationtech.jts.geom.LineString) Image(org.hortonmachine.gears.io.geopaparazzi.geopap4.Image) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) KeyEvent(java.awt.event.KeyEvent) JTextPane(javax.swing.JTextPane) BorderLayout(java.awt.BorderLayout) EventListenerList(javax.swing.event.EventListenerList) List(java.util.List) ArrayList(java.util.ArrayList) Component(java.awt.Component) JComponent(javax.swing.JComponent) DaoGpsLog(org.hortonmachine.gears.io.geopaparazzi.geopap4.DaoGpsLog) GpsLog(org.hortonmachine.gears.io.geopaparazzi.geopap4.DaoGpsLog.GpsLog) Dimension(java.awt.Dimension) GpsPoint(org.hortonmachine.gears.io.geopaparazzi.geopap4.DaoGpsLog.GpsPoint) NwwPanel(org.hortonmachine.nww.gui.NwwPanel) JTree(javax.swing.JTree) Note(org.hortonmachine.gears.io.geopaparazzi.geopap4.Note) ComponentEvent(java.awt.event.ComponentEvent) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) File(java.io.File)

Example 24 with Image

use of com.woorea.openstack.glance.model.v2.Image in project hortonmachine by TheHortonMachine.

the class OmsGeopaparazzi4Converter method media2FeatureCollection.

public static SimpleFeatureCollection media2FeatureCollection(IHMConnection connection, File mediaFolderFile, IHMProgressMonitor pm) throws Exception, IOException, FileNotFoundException {
    DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
    try {
        GeometryFactory gf = GeometryUtilities.gf();
        /*
             * create the points shapefile
             */
        newCollection = new DefaultFeatureCollection();
        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("geopaparazzimediapoints");
        b.setCRS(DefaultGeographicCRS.WGS84);
        b.add("the_geom", Point.class);
        String altimFN = ImageTableFields.COLUMN_ALTIM.getFieldName();
        String tsFN = ImageTableFields.COLUMN_TS.getFieldName();
        String azimFN = ImageTableFields.COLUMN_AZIM.getFieldName();
        String imageNameFN = ImageTableFields.COLUMN_TEXT.getFieldName();
        b.add(altimFN, String.class);
        b.add(tsFN, String.class);
        b.add(azimFN, Double.class);
        b.add(imageNameFN, String.class);
        SimpleFeatureType featureType = b.buildFeatureType();
        List<Image> imagesList = DaoImages.getImagesList(connection);
        pm.beginTask("Importing media...", imagesList.size());
        for (Image image : imagesList) {
            File newImageFile = new File(mediaFolderFile, image.getName());
            byte[] imageData = DaoImages.getImageData(connection, image.getImageDataId());
            try (OutputStream outStream = new FileOutputStream(newImageFile)) {
                outStream.write(imageData);
            }
            Point point = gf.createPoint(new Coordinate(image.getLon(), image.getLat()));
            long ts = image.getTs();
            String dateTimeString = ETimeUtilities.INSTANCE.TIME_FORMATTER_LOCAL.format(new Date(ts));
            String imageRelativePath = mediaFolderFile.getName() + "/" + image.getName();
            Object[] values = new Object[] { point, image.getAltim(), dateTimeString, image.getAzim(), imageRelativePath };
            SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
            builder.addAll(values);
            SimpleFeature feature = builder.buildFeature(null);
            newCollection.add(feature);
            pm.worked(1);
        }
    } finally {
        pm.done();
    }
    return newCollection;
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Point(org.locationtech.jts.geom.Point) GpsPoint(org.hortonmachine.gears.io.geopaparazzi.geopap4.DaoGpsLog.GpsPoint) BufferedImage(java.awt.image.BufferedImage) Image(org.hortonmachine.gears.io.geopaparazzi.geopap4.Image) Date(java.util.Date) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(org.locationtech.jts.geom.Coordinate) FileOutputStream(java.io.FileOutputStream) JSONObject(org.json.JSONObject) File(java.io.File) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 25 with Image

use of com.woorea.openstack.glance.model.v2.Image in project hortonmachine by TheHortonMachine.

the class OmsGeopaparazzi4Converter method media2IdBasedFeatureCollection.

public static SimpleFeatureCollection media2IdBasedFeatureCollection(IHMConnection connection, IHMProgressMonitor pm) throws Exception, IOException, FileNotFoundException {
    try {
        GeometryFactory gf = GeometryUtilities.gf();
        /*
             * create the points fc
             */
        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
        SimpleFeatureType featureType = GeopaparazziUtilities.getMediaFeaturetype();
        List<Image> imagesList = DaoImages.getImagesList(connection);
        pm.beginTask("Importing media...", imagesList.size());
        for (Image image : imagesList) {
            Point point = gf.createPoint(new Coordinate(image.getLon(), image.getLat()));
            long ts = image.getTs();
            String dateTimeString = ETimeUtilities.INSTANCE.TIME_FORMATTER_LOCAL.format(new Date(ts));
            Object[] values = new Object[] { point, image.getAltim(), dateTimeString, image.getAzim(), image.getImageDataId() };
            SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
            builder.addAll(values);
            SimpleFeature feature = builder.buildFeature(null);
            newCollection.add(feature);
            pm.worked(1);
        }
        return newCollection;
    } finally {
        pm.done();
    }
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Point(org.locationtech.jts.geom.Point) GpsPoint(org.hortonmachine.gears.io.geopaparazzi.geopap4.DaoGpsLog.GpsPoint) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) BufferedImage(java.awt.image.BufferedImage) Image(org.hortonmachine.gears.io.geopaparazzi.geopap4.Image) Date(java.util.Date) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(org.locationtech.jts.geom.Coordinate) JSONObject(org.json.JSONObject) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

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