Search in sources :

Example 76 with Block

use of net.minecraft.server.v1_13_R2.Block in project java-vision by googleapis.

the class DetectBeta method detectHandwrittenOcrGcs.

// [END vision_handwritten_ocr_beta]
// [START vision_handwritten_ocr_gcs_beta]
/**
 * Performs handwritten text detection on a remote image on Google Cloud Storage.
 *
 * @param gcsPath The path to the remote file on Google Cloud Storage to detect handwritten text
 *     on.
 * @param out A {@link PrintStream} to write the results to.
 * @throws Exception on errors while closing the client.
 * @throws IOException on Input/Output errors.
 */
public static void detectHandwrittenOcrGcs(String gcsPath, PrintStream out) throws Exception {
    List<AnnotateImageRequest> requests = new ArrayList<>();
    ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
    Image img = Image.newBuilder().setSource(imgSource).build();
    Feature feat = Feature.newBuilder().setType(Type.DOCUMENT_TEXT_DETECTION).build();
    // Set the parameters for the image
    ImageContext imageContext = ImageContext.newBuilder().addLanguageHints("en-t-i0-handwrit").build();
    AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).setImageContext(imageContext).build();
    requests.add(request);
    try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
        BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
        List<AnnotateImageResponse> responses = response.getResponsesList();
        client.close();
        for (AnnotateImageResponse res : responses) {
            if (res.hasError()) {
                out.printf("Error: %s\n", res.getError().getMessage());
                return;
            }
            // For full list of available annotations, see http://g.co/cloud/vision/docs
            TextAnnotation annotation = res.getFullTextAnnotation();
            for (Page page : annotation.getPagesList()) {
                String pageText = "";
                for (Block block : page.getBlocksList()) {
                    String blockText = "";
                    for (Paragraph para : block.getParagraphsList()) {
                        String paraText = "";
                        for (Word word : para.getWordsList()) {
                            String wordText = "";
                            for (Symbol symbol : word.getSymbolsList()) {
                                wordText = wordText + symbol.getText();
                                out.format("Symbol text: %s (confidence: %f)\n", symbol.getText(), symbol.getConfidence());
                            }
                            out.format("Word text: %s (confidence: %f)\n\n", wordText, word.getConfidence());
                            paraText = String.format("%s %s", paraText, wordText);
                        }
                        // Output Example using Paragraph:
                        out.println("\nParagraph: \n" + paraText);
                        out.format("Paragraph Confidence: %f\n", para.getConfidence());
                        blockText = blockText + paraText;
                    }
                    pageText = pageText + blockText;
                }
            }
            out.println("\nComplete annotation:");
            out.println(annotation.getText());
        }
    }
}
Also used : Word(com.google.cloud.vision.v1p3beta1.Word) Symbol(com.google.cloud.vision.v1p3beta1.Symbol) ImageAnnotatorClient(com.google.cloud.vision.v1p3beta1.ImageAnnotatorClient) ArrayList(java.util.ArrayList) Page(com.google.cloud.vision.v1p3beta1.Page) ByteString(com.google.protobuf.ByteString) Image(com.google.cloud.vision.v1p3beta1.Image) Feature(com.google.cloud.vision.v1p3beta1.Feature) Paragraph(com.google.cloud.vision.v1p3beta1.Paragraph) AnnotateImageRequest(com.google.cloud.vision.v1p3beta1.AnnotateImageRequest) AnnotateImageResponse(com.google.cloud.vision.v1p3beta1.AnnotateImageResponse) Block(com.google.cloud.vision.v1p3beta1.Block) ImageSource(com.google.cloud.vision.v1p3beta1.ImageSource) TextAnnotation(com.google.cloud.vision.v1p3beta1.TextAnnotation) ImageContext(com.google.cloud.vision.v1p3beta1.ImageContext) BatchAnnotateImagesResponse(com.google.cloud.vision.v1p3beta1.BatchAnnotateImagesResponse)

Example 77 with Block

use of net.minecraft.server.v1_13_R2.Block in project java-vision by googleapis.

the class BatchAnnotateFiles method batchAnnotateFiles.

public static void batchAnnotateFiles(String filePath) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
        // You can send multiple files to be annotated, this sample demonstrates how to do this with
        // one file. If you want to use multiple files, you have to create a `AnnotateImageRequest`
        // object for each file that you want annotated.
        // First read the files contents
        Path path = Paths.get(filePath);
        byte[] data = Files.readAllBytes(path);
        ByteString content = ByteString.copyFrom(data);
        // Specify the input config with the file's contents and its type.
        // Supported mime_type: application/pdf, image/tiff, image/gif
        // https://cloud.google.com/vision/docs/reference/rpc/google.cloud.vision.v1#inputconfig
        InputConfig inputConfig = InputConfig.newBuilder().setMimeType("application/pdf").setContent(content).build();
        // Set the type of annotation you want to perform on the file
        // https://cloud.google.com/vision/docs/reference/rpc/google.cloud.vision.v1#google.cloud.vision.v1.Feature.Type
        Feature feature = Feature.newBuilder().setType(Feature.Type.DOCUMENT_TEXT_DETECTION).build();
        // Build the request object for that one file. Note: for additional file you have to create
        // additional `AnnotateFileRequest` objects and store them in a list to be used below.
        // Since we are sending a file of type `application/pdf`, we can use the `pages` field to
        // specify which pages to process. The service can process up to 5 pages per document file.
        // https://cloud.google.com/vision/docs/reference/rpc/google.cloud.vision.v1#google.cloud.vision.v1.AnnotateFileRequest
        AnnotateFileRequest fileRequest = AnnotateFileRequest.newBuilder().setInputConfig(inputConfig).addFeatures(feature).addPages(// Process the first page
        1).addPages(// Process the second page
        2).addPages(// Process the last page
        -1).build();
        // Add each `AnnotateFileRequest` object to the batch request.
        BatchAnnotateFilesRequest request = BatchAnnotateFilesRequest.newBuilder().addRequests(fileRequest).build();
        // Make the synchronous batch request.
        BatchAnnotateFilesResponse response = imageAnnotatorClient.batchAnnotateFiles(request);
        // sample.
        for (AnnotateImageResponse imageResponse : response.getResponsesList().get(0).getResponsesList()) {
            System.out.format("Full text: %s%n", imageResponse.getFullTextAnnotation().getText());
            for (Page page : imageResponse.getFullTextAnnotation().getPagesList()) {
                for (Block block : page.getBlocksList()) {
                    System.out.format("%nBlock confidence: %s%n", block.getConfidence());
                    for (Paragraph par : block.getParagraphsList()) {
                        System.out.format("\tParagraph confidence: %s%n", par.getConfidence());
                        for (Word word : par.getWordsList()) {
                            System.out.format("\t\tWord confidence: %s%n", word.getConfidence());
                            for (Symbol symbol : word.getSymbolsList()) {
                                System.out.format("\t\t\tSymbol: %s, (confidence: %s)%n", symbol.getText(), symbol.getConfidence());
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) Word(com.google.cloud.vision.v1.Word) BatchAnnotateFilesRequest(com.google.cloud.vision.v1.BatchAnnotateFilesRequest) ByteString(com.google.protobuf.ByteString) Symbol(com.google.cloud.vision.v1.Symbol) ImageAnnotatorClient(com.google.cloud.vision.v1.ImageAnnotatorClient) Page(com.google.cloud.vision.v1.Page) Feature(com.google.cloud.vision.v1.Feature) Paragraph(com.google.cloud.vision.v1.Paragraph) BatchAnnotateFilesResponse(com.google.cloud.vision.v1.BatchAnnotateFilesResponse) AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) AnnotateFileRequest(com.google.cloud.vision.v1.AnnotateFileRequest) Block(com.google.cloud.vision.v1.Block) InputConfig(com.google.cloud.vision.v1.InputConfig)

Example 78 with Block

use of net.minecraft.server.v1_13_R2.Block in project concourse by cinchapi.

the class Upgrade0_11_0_1 method doTask.

@Override
protected void doTask() {
    Environments.iterator(GlobalState.BUFFER_DIRECTORY, GlobalState.DATABASE_DIRECTORY).forEachRemaining(environment -> {
        logInfoMessage("Upgrading Storage Format v2 data files to Storage Format v3 in environment {}", environment);
        Path directory = Paths.get(GlobalState.DATABASE_DIRECTORY).resolve(environment);
        Database db = new Database(directory);
        db.start();
        try {
            Path cpb = directory.resolve("cpb");
            Iterable<Block<Identifier, Text, Value>> blocks = StorageFormatV2.load(cpb, TableRevision.class);
            for (Block<Identifier, Text, Value> block : blocks) {
                for (Revision<Identifier, Text, Value> revision : block) {
                    Write write = Reflection.newInstance(Write.class, revision.getType(), revision.getKey(), revision.getValue(), revision.getLocator(), // (authorized)
                    revision.getVersion());
                    db.accept(write);
                }
                db.sync();
                logInfoMessage("Finished transferring v2 data Block {} to v3 Segment format", block.getId());
            }
        } finally {
            db.stop();
        }
    });
}
Also used : Path(java.nio.file.Path) Write(com.cinchapi.concourse.server.storage.temp.Write) Identifier(com.cinchapi.concourse.server.model.Identifier) Database(com.cinchapi.concourse.server.storage.db.Database) Value(com.cinchapi.concourse.server.model.Value) Block(com.cinchapi.concourse.server.storage.format.StorageFormatV2.Block) Text(com.cinchapi.concourse.server.model.Text)

Example 79 with Block

use of net.minecraft.server.v1_13_R2.Block in project dynmap by webbukkit.

the class BukkitVersionHelperSpigot116 method initializeBlockStates.

/**
 * Initialize block states (org.dynmap.blockstate.DynmapBlockState)
 */
@Override
public void initializeBlockStates() {
    dataToState = new IdentityHashMap<IBlockData, DynmapBlockState>();
    HashMap<String, DynmapBlockState> lastBlockState = new HashMap<String, DynmapBlockState>();
    int cnt = Block.REGISTRY_ID.a();
    DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
    // Loop through block data states
    for (int i = 0; i < cnt; i++) {
        IBlockData bd = Block.getByCombinedId(i);
        Block b = bd.getBlock();
        String bname = IRegistry.BLOCK.getKey(bd.getBlock()).toString();
        // See if we have seen this one
        DynmapBlockState lastbs = lastBlockState.get(bname);
        int idx = 0;
        if (lastbs != null) {
            // Yes
            // Get number of states so far, since this is next
            idx = lastbs.getStateCount();
        }
        // Build state name
        String sb = "";
        String fname = bd.toString();
        int off1 = fname.indexOf('[');
        if (off1 >= 0) {
            int off2 = fname.indexOf(']');
            sb = fname.substring(off1 + 1, off2);
        }
        Material mat = bd.getMaterial();
        // getLightBlock
        int lightAtten = b.f(bd, BlockAccessAir.INSTANCE, BlockPosition.ZERO);
        // Log.info("statename=" + bname + "[" + sb + "], lightAtten=" + lightAtten);
        // Fill in base attributes
        bld.setBaseState(lastbs).setStateIndex(idx).setBlockName(bname).setStateName(sb).setMaterial(mat.toString()).setAttenuatesLight(lightAtten);
        if (mat.isSolid()) {
            bld.setSolid();
        }
        if (mat == Material.AIR) {
            bld.setAir();
        }
        if ((bd.getBlock() instanceof BlockRotatable) && (bd.getMaterial() == Material.WOOD)) {
            bld.setLog();
        }
        if (mat == Material.LEAVES) {
            bld.setLeaves();
        }
        if ((!bd.getFluid().isEmpty()) && ((bd.getBlock() instanceof BlockFluids) == false)) {
            // Test if fluid type for block is not empty
            bld.setWaterlogged();
        }
        // Build state
        DynmapBlockState dbs = bld.build();
        dataToState.put(bd, dbs);
        lastBlockState.put(bname, (lastbs == null) ? dbs : lastbs);
        Log.verboseinfo("blk=" + bname + ", idx=" + idx + ", state=" + sb + ", waterlogged=" + dbs.isWaterlogged());
    }
}
Also used : BlockRotatable(net.minecraft.server.v1_16_R1.BlockRotatable) HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) BukkitMaterial(org.dynmap.bukkit.helper.BukkitMaterial) Material(net.minecraft.server.v1_16_R1.Material) IBlockData(net.minecraft.server.v1_16_R1.IBlockData) Block(net.minecraft.server.v1_16_R1.Block) BlockFluids(net.minecraft.server.v1_16_R1.BlockFluids)

Example 80 with Block

use of net.minecraft.server.v1_13_R2.Block in project dynmap by webbukkit.

the class BukkitVersionHelperSpigot116_2 method initializeBlockStates.

/**
 * Initialize block states (org.dynmap.blockstate.DynmapBlockState)
 */
@Override
public void initializeBlockStates() {
    dataToState = new IdentityHashMap<IBlockData, DynmapBlockState>();
    HashMap<String, DynmapBlockState> lastBlockState = new HashMap<String, DynmapBlockState>();
    int cnt = Block.REGISTRY_ID.a();
    DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
    // Loop through block data states
    for (int i = 0; i < cnt; i++) {
        IBlockData bd = Block.getByCombinedId(i);
        Block b = bd.getBlock();
        String bname = IRegistry.BLOCK.getKey(bd.getBlock()).toString();
        // See if we have seen this one
        DynmapBlockState lastbs = lastBlockState.get(bname);
        int idx = 0;
        if (lastbs != null) {
            // Yes
            // Get number of states so far, since this is next
            idx = lastbs.getStateCount();
        }
        // Build state name
        String sb = "";
        String fname = bd.toString();
        int off1 = fname.indexOf('[');
        if (off1 >= 0) {
            int off2 = fname.indexOf(']');
            sb = fname.substring(off1 + 1, off2);
        }
        Material mat = bd.getMaterial();
        // getLightBlock
        int lightAtten = b.f(bd, BlockAccessAir.INSTANCE, BlockPosition.ZERO);
        // Log.info("statename=" + bname + "[" + sb + "], lightAtten=" + lightAtten);
        // Fill in base attributes
        bld.setBaseState(lastbs).setStateIndex(idx).setBlockName(bname).setStateName(sb).setMaterial(mat.toString()).setAttenuatesLight(lightAtten);
        if (mat.isSolid()) {
            bld.setSolid();
        }
        if (mat == Material.AIR) {
            bld.setAir();
        }
        if ((bd.getBlock() instanceof BlockRotatable) && (bd.getMaterial() == Material.WOOD)) {
            bld.setLog();
        }
        if (mat == Material.LEAVES) {
            bld.setLeaves();
        }
        if ((!bd.getFluid().isEmpty()) && ((bd.getBlock() instanceof BlockFluids) == false)) {
            // Test if fluid type for block is not empty
            bld.setWaterlogged();
        }
        // Build state
        DynmapBlockState dbs = bld.build();
        dataToState.put(bd, dbs);
        lastBlockState.put(bname, (lastbs == null) ? dbs : lastbs);
        Log.verboseinfo("blk=" + bname + ", idx=" + idx + ", state=" + sb + ", waterlogged=" + dbs.isWaterlogged());
    }
}
Also used : BlockRotatable(net.minecraft.server.v1_16_R2.BlockRotatable) HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) Material(net.minecraft.server.v1_16_R2.Material) BukkitMaterial(org.dynmap.bukkit.helper.BukkitMaterial) IBlockData(net.minecraft.server.v1_16_R2.IBlockData) Block(net.minecraft.server.v1_16_R2.Block) BlockFluids(net.minecraft.server.v1_16_R2.BlockFluids)

Aggregations

Block (net.minecraft.server.v1_12_R1.Block)12 ArrayList (java.util.ArrayList)10 ByteString (com.google.protobuf.ByteString)8 Block (net.minecraft.server.v1_10_R1.Block)8 Block (net.minecraft.server.v1_11_R1.Block)8 BlockPosition (net.minecraft.server.v1_12_R1.BlockPosition)8 Block (net.minecraft.server.v1_8_R3.Block)8 FallingBlock (org.bukkit.entity.FallingBlock)8 HashMap (java.util.HashMap)7 BlockPosition (net.minecraft.server.v1_10_R1.BlockPosition)7 BlockPosition (net.minecraft.server.v1_11_R1.BlockPosition)7 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)6 Block (com.google.cloud.vision.v1.Block)6 Feature (com.google.cloud.vision.v1.Feature)6 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)6 Page (com.google.cloud.vision.v1.Page)6 Paragraph (com.google.cloud.vision.v1.Paragraph)6 Symbol (com.google.cloud.vision.v1.Symbol)6 Word (com.google.cloud.vision.v1.Word)6 IdentityHashMap (java.util.IdentityHashMap)5