Does anybody knows how to use a wavelet transform (Haar or Daubechies) of BoofCV in Java?
There's no code example on the web and I'm very new at this library.
I've tried this code below, but so for no results.
public static void main(String[] args) throws IOException, InstantiationException, IllegalAccessException {
String dir = "C:\\Users\\user\\Desktop\\ImgTest\\";
BufferedImage buff =UtilImageIO.loadImage(dir+"img.png");
ImageUInt16 aux = UtilImageIO.loadImage(dir+"img.png", ImageUInt16.class);
ImageSInt16 input = new ImageSInt16(aux.width, aux.height);
input =ConvertImage.convert(aux, input);
ImageSInt32 output = new ImageSInt32(aux.width, aux.height);
int minPixelValue = 0;
int maxPixelValue = 255;
WaveletTransform<ImageSInt16, ImageSInt32, WlCoef_I32> transform =
FactoryWaveletTransform.create_I(FactoryWaveletHaar.generate(true, 0), 1,
minPixelValue, maxPixelValue,ImageSInt16.class);
output=transform.transform(input, output);
//BufferedImage out = ConvertBufferedImage.convertTo(output, null);
BufferedImage out = new BufferedImage(input.width*6, input.height*6, 5);
out = VisualizeBinaryData.renderLabeled(output, 0, out);
ImageIO.write(out, "PNG", new File(dir+"out.png"));
}
}
I also tried JWave, but there's no code example either and the responsible wasn't able to help with it.
Thank you!
There are a lot of code examples outside there. I made one before, but in C# not Java. For Java Code, you could refer to here
Related
This code works, it reads a file in byte type and after assigning the image it creates a copy in the directory where the other part is located with a different name, I must do the same, create a new file, I just have to make it rotate on the X and Y axes as the final 180 degree image without creating a library to do the job.
Can you help me with the code or madnar information
Thank you!
public class BMPRotations {
public static void main(String[] args) throws IOException {
int contador=0;
int datos_entrada[] = new int[921655];
try {
FileInputStream archivo_lectura = new FileInputStream("Ruta__picture.bmp");
boolean final_ar = false;
while(!final_ar) {
int byte_entrada = archivo_lectura.read();
if(byte_entrada!=-1)
datos_entrada[contador]=byte_entrada;
else
final_ar=true;
//Muestra todos los bytes
//System.out.println(datos_entrada[contador]);
contador++;
}
archivo_lectura.close();
}catch(IOException e) {
System.out.print("Error");
}
System.out.print("Bystes de la imagen: " + contador);
crea_fichero(datos_entrada);
}
static void crea_fichero(int datos_nuevo_fichero[]) {
try {
FileOutputStream fichero_nuevo = new FileOutputStream("Ruta_picture.bmp");
for(int i=0; i<datos_nuevo_fichero.length;i++) {
fichero_nuevo.write(datos_nuevo_fichero[i]);
}
fichero_nuevo.close();
}catch(IOException e) {
System.out.println("Error ");
}
}
Here is a reference image.
640X480 in 24-bit format
https://i.stack.imgur.com/pz4A4.png
This isn't a full answer but I hope it points you in right direction for what looks like homework.
What you have implemented so far is simply copying a file with hard-coded size 921655, and does not deal with an image - just any file. You could replace the entire program with:
File input = new File("Ruta__picture.bmp");
File output = new File("Ruta_picture.bmp");
Files.copy(input.toPath(), output.toPath(), StandardCopyOption.REPLACE_EXISTING);
To deal with images, look at javax.imageio.ImageIO class. This shows how to load any supported JDK image type and write it back:
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
BufferedImage image = ImageIO.read(input);
// TODO: TRANSFORM "image" here
BufferedImage modified = image;
ImageIO.write(modified , "bmp", output);
Note that ImageIO.write supports other types such as "jpg".
I am trying to read 2D Data matrix barcode using zxing library(GenericMultipleBarcodeReader). I have multiple barcodes on a single image.
The problem is that the efficiency of the zing reader is very low, it
recognizes 1 barcode from image 1.png and no barcode from image 2.png which has 48 barcodes. Is there
any way to get 100% efficiency or any other library which results 100%
My code to read barcode is:
public static void main(String[] args) throws Exception {
BufferedImage image = ImageIO.read(new File("1.png"));
if (image != null) {
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
DataMatrixReader dataMatrixReader = new DataMatrixReader();
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
GenericMultipleBarcodeReader reader = new GenericMultipleBarcodeReader(
dataMatrixReader);
Result[] results = reader.decodeMultiple(bitmap, hints);
for (Result result : results) {
System.out.println(result.toString());
}
}
}
And images I used are:
Please help to resolve this issue.
Thanks
It doesn't quite work this way. It will not read barcodes in a grid, as it makes an assumption that it can cut up the image in a certain way that won't be compatible with grids. You will have to write your own method to cut up the image into scannable regions.
It is also the case that the Data Matrix decoder assumes the center of the image is inside the barcode. This is another reason you need to pre-chop the image into squares around the cylinders and then scan. It ought to work fairly well then.
An alternative solution is to consider a barcode engine that can detect multiple barcodes in various orientations on one document. If you're running on Windows, the ClearImage Barcode SDK has a Java API and should be able to handle your needs without pre-processing. You can test if their engine can read your image using their Online Barcode Reader.
Some sample code:
public static void testDataMatrix () {
try {
String filename = "1.png ";
CiServer objCi = new CiServer();
Ci = objCi.getICiServer();
ICiDataMatrix reader = Ci.CreateDataMatrix(); // read DataMatrix Barcode
reader.getImage().Open(filename, 1);
int n = reader.Find(0); // find all the barcodes in the doc
for (i = 1; i <= n; i++) {
ICiBarcode Bc = reader.getBarcodes().getItem(i); // getItem is 1-based
System.out.println("Barcode " + i + " has Text: " + Bc.getText());
}
} catch (Exception ex) {System.out.println(ex.getMessage());}
}
Disclaimer: I've done some work for Inlite in the past.
I want to pass an image (screenshot of a graph) from Flex to Java over BlazeDS. The goal is that the image will be stored on the serverside.
This is my Flex routine (called after clicking a button):
protected function btn_clickHandler(event:MouseEvent):void
{
var snapshot:ImageSnapshot = ImageSnapshot.captureImage(graphViewStack.selectedChild,);
var balanceSheetImage:String = ImageSnapshot.encodeImageAsBase64(snapshot);
//Testing the image
var base64Dec:Base64Decoder = new Base64Decoder();
base64Dec.decode(balanceSheetImage);
generatedImage.load(base64Dec.toByteArray());
}
In the 'generatedImage', the image is shown, so I assume this routine works.
Now I want to decode the balanceSheetImage in Java. For this reason, I created following Java code. The value contains the string in the generatedImage, which I copy/pasted from the flex code.
import sun.misc.BASE64Decoder;
public static int createPdf() throws IOException{
String value= "t3j1fA31VBp0DAADAJfR3rOfp+4+0H/qO+b//89/6u23566+//mVmZmZmZmb2yl4N8dSFcAzj0t29Xp//x77HfCvc/f8yAAAAfEL8FPT5wdm6/OBrf9SnsgtzAAAA+CBhDgAAAMIcAAAAhLk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AAIcwAAALiqusErBAAAADtyxxwAAACEOQAAAAhzYQ4AAADCHAAAAIS5MAcAAABhDgAAAIcw31fbbsIcAAAAxkn3lQePhTkAAAAMkNtWb41lYQ4AAADbYZ7C790xBwAAgMFh/vId863w/ie2/jfMXp1rzFxj5hozc32Za8zOf42dIcw/9h5zf1HNNwNzjZm5xsz1Za4xM2H+t498Kru/qOabgbnGzFxj5voy15iZMN+Zv6jmm4G5xsxcY+b6MteYmTAX5uabgZlrzFxjZq4vc42ZMBfm/qKabwbmGjNzjZnry1xjZsJcmJtvBmauMXONmbm+zDVmwlyY+4tqvhmYa8zMNWauL3ONmQlzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADeqXoJ2Elp11dtj+Hd5nCNJS8HO8ptsNd/w75285Lw5n/XzxvXlw6AA0jhLyrscX3N3TcG4cSe15j/lrH390thzrsVMc6O/65P068bI/GxDoCDyeGbAoy43oQ5e/KPC/Zwa98nkzBnpzBf42j2cvDmf9f3P+lTdQAc/5sC7Cn5Bwc7Wn9MTzSxhxr+O+Ya493fG/tQ8n9g885/1/fXVNEBIMy5djSJckbwHmD2uKZqN9cYe4a664t3h/mzO+Y6AIQ5F7u2/L//jPpHrDBHNPGn/zfM90ze+e/6373HXAeAMOci+k+adaeJva8zP5mBMOdP/m+Y64s9/l2/9ansOgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOBY/geGctMTogR6kgAAAABJRU5ErkJggg==";
BASE64Decoder decoder = new BASE64Decoder();
byte[] imgBytes = decoder.decodeBuffer(value);
ByteArrayInputStream str = new ByteArrayInputStream(imgBytes);
BufferedImage bufImg = ImageIO.read(str);
File imgOutFile = new File("newLabel.png");
ImageIO.write(bufImg, "png", imgOutFile);
return -1;
}
Unfortunately, this does not work. In particular: BufferedImage is always null. Has anyone a clue why this happens?
I'm currently trying to automatically extract important keywords from a PDF file. I am able to get the text information out of the PDF document. But now I need to know, which font size and font family these keywords have.
The following code I already have:
Main
public static void main(String[] args) throws IOException {
String src = "SEM_081145.pdf";
PdfReader reader = new PdfReader(src);
SemTextExtractionStrategy semTextExtractionStrategy = new SemTextExtractionStrategy();
PrintWriter out = new PrintWriter(new FileOutputStream(src + ".txt"));
Rectangle rect = new Rectangle(70, 80, 490, 580);
RenderFilter filter = new RegionTextRenderFilter(rect);
for (int i = 1; i <= reader.getNumberOfPages(); i++) {
// strategy = new FilteredTextRenderListener(new LocationTextExtractionStrategy(), filter);
out.println(PdfTextExtractor.getTextFromPage(reader, i, semTextExtractionStrategy));
}
out.flush();
out.close();
}
And I have implemented the TextExtraction Strategy SemTextExtractionStrategy which looks like this:
public class SemTextExtractionStrategy implements TextExtractionStrategy {
private String text;
#Override
public void beginTextBlock() {
}
#Override
public void renderText(TextRenderInfo renderInfo) {
text = renderInfo.getText();
System.out.println(renderInfo.getFont().getFontType());
System.out.print(text);
}
#Override
public void endTextBlock() {
}
#Override
public void renderImage(ImageRenderInfo renderInfo) {
}
#Override
public String getResultantText() {
return text;
}
}
I can get the FontType but there is no method to get the font size. Is there another way or how can I get the font size of the current text segment?
Or are there any other libraries which can fetch out the font size from TextSegments? I already had a look into PDFBox, and PDFTextStream. The PDF Shareware Library from Aspose would perfectly do the job. But it's very expensive and I need to use an open source project.
Thanks to Alexis I could convert his C# solution into Java code:
text = renderInfo.getText();
Vector curBaseline = renderInfo.getBaseline().getStartPoint();
Vector topRight = renderInfo.getAscentLine().getEndPoint();
Rectangle rect = new Rectangle(curBaseline.get(0), curBaseline.get(1), topRight.get(0), topRight.get(1));
float curFontSize = rect.getHeight();
I had some trouble using Alexis' and Prine's solution, since it doesn't deal with rotated text correctly. So this is what I do (sorry, in Scala):
val x0 = info.getAscentLine.getEndPoint
val x1 = info.getBaseline.getStartPoint
val x2 = info.getBaseline.getEndPoint
val length1 = (x2.subtract(x1)).cross((x1.subtract(x0))).lengthSquared
val length2 = x2.subtract(x1).lengthSquared
(length1, length2) match {
case (0, 0) => 0
case _ => length1 / length2
}
You can adapt the code provided in this answer, in particular this code snippet:
Vector curBaseline = renderInfo.GetBaseline().GetStartPoint();
Vector topRight = renderInfo.GetAscentLine().GetEndPoint();
iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(curBaseline[Vector.I1], curBaseline[Vector.I2], topRight[Vector.I1], topRight[Vector.I2]);
Single curFontSize = rect.Height;
This answer is in C#, but the API is so similar that the conversion to Java should be straightforward.
If you want the exact fontsize, use the following code in your renderText:
float fontsize = renderInfo.getAscentLine().getStartPoint().get(1)
- renderInfo.getDescentLine().getStartPoint().get(1);
Modify this as indicated in the other answers for rorated text.
I've been trying to load a bmp picture to use it as a texture at my program I've used a IOStream class to extend DataInputStream to read the pixels at the photo with this code based on a texture loader code for C++:
//class Data members
public static int BMPtextures[];
public static int BMPtexCount = 30;
public static int currentTextureID = 0;
//loading methode
static int loadBMPTexture(int index, String fileName, GL gl)
{
try
{
IOStream wdis = new IOStream(fileName);
wdis.skipBytes(18);
int width = wdis.readIntW();
int height = wdis.readIntW();
wdis.skipBytes(28);
byte buf[] = new byte[wdis.available()];
wdis.read(buf);
wdis.close();
gl.glBindTexture(GL.GL_TEXTURE_2D, BMPtextures[index]);
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, 3, width, height, 0, GL.GL_BGR, GL.GL_UNSIGNED_BYTE, buf);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
currentTextureID = index;
return currentTextureID;
}
catch (IOException ex)
{
// Utils.msgBox("File Error\n" + fileName, "Error", Utils.MSG_WARN);
return -1;
}
}
and IOStream code :
public class IOStream extends DataInputStream {
public IOStream(String file) throws FileNotFoundException {
super(new FileInputStream(file));
}
public short readShortW() throws IOException {
return (short)(readUnsignedByte() + readUnsignedByte() * 256);
}
public int readIntW() throws IOException {
return readShortW() + readShortW() * 256 * 256;
}
void read(Buffer[] buf) {
}
}
and the calling:
GTexture.loadBMPTexture(1,"/BasicJOGL/src/basicjogl/data/Font.bmp",gl);
after debugging I figured out that when it come to this line:
IOStream wdis = new IOStream(fileName);
an IOExeption occurred and it's a DispatchException What's this supposed to mean, and how can I solve it?
I tried to:
use \ and \\ and / and //
change the path of the photo and take all the path from c:\ to the photoname.bmp
rename the photo using numbers like 1.bmp
None worked.
Judging by your latest comment, you are no longer getting the IOException but are still having troubles getting the texture to actually render (just getting a white square).
I noticed the following are not in the code you posted here (but could be elsewhere):
gl.glGenTextures
You need to generate places for your textures before binding them. Also, make sure you have enabled texturing:
gl.glEnable(GL.GL_TEXTURE2D);
For additional information / tutorials on getting started with OpenGL texturing, I recommend taking a read of NeHe Productions: OpenGL Lesson #06. Also, down the bottom of the page you will find JOGL sample code to help you convert the concepts from C to Java.
Anyway, hope this gives a few new ideas to try.
Probably don't need help on this anymore, but I noticed that IOStream extends DataInputStream but when it comes to actually implementing read() it's been left blank. so regardless you're never actually reading anything into buf which might explain why your texture is blank but you don't get any other problems.
Here is a simple way of loading a texture in JOGL. It works with BMP as well.
public static Texture loadTexture(String file) throws GLException, IOException
{
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(ImageIO.read(new File(file)), "png", os);
InputStream fis = new ByteArrayInputStream(os.toByteArray());
return TextureIO.newTexture(fis, true, TextureIO.PNG);
}
also dont forget to enable and bind, and set texture-coordinates.
...
gl.glEnableClientState(GL2ES1.GL_TEXTURE_COORD_ARRAY);
if(myTexture == null)
myTexture = loadTexture("filename.png");
myTexture.enable(gl);
myTexture.bind(gl);
gl.glTexCoordPointer(2, GL2ES1.GL_FLOAT, 0, textureCoords);
...