I recently started a small project in which I wanted to use zxing. I downloaded the sources from here. I was able to successfully build the core and the javase jars.
When I tried to code along the sample provided here I ran into a problem I do not quite understand. So far the code looks like this:
public static void main(String[] args)
{
Reader reader = new MultiFormatReader();
ImageIcon imageIcon = new ImageIcon(SOMEPATH);
Image image = imageIcon.getImage();
BufferedImage buffImage = new BufferedImage(
image.getWidth(null),
image.getHeight(null),
BufferedImage.TYPE_INT_RGB);
Graphics2D g = buffImage.createGraphics();
g.drawImage(image, null, null);
LuminanceSource source = new BufferedImageLuminanceSource(buffImage);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
}
As you can see this is pretty much the same code as presented in the DevelopersNotes. But the code will not compile. The error message is:
Type mismatch: cannot convert from BufferedImageLuminanceSource to LuminanceSource
Does somebody know what I am missing?
Edit:
My imports are currently looking like this:
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.Reader;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;
I added the core.jar as well as the javase.jar to my project. Both I compiled using ant leaving the buildfiles as downloaded.
That's all correct. You must have some funny business in your imports. Those types are certainly compatible.
Related
I am trying a web app in bokeh where i import a dlis file through the widget fileinput.
I am using the following libraries
from dlisio import dlis
from pybase64 import b64decode
import io
def upload_file_dlis(attr, old, new):
print('upload_file_dlis')
decoded = b64decode(new)
f = io.BytesIO(decoded)
file_input_dlis.on_change('value', upload_file_dlis)
I have the following issue:
OSError: '<_io.BytesIO object at 0x000001CE6507CF40>' is not an existing regular file
I guess it is because dlis files are not handled by Io library.
What is the best way to work on this?
Do you have any suggestions?
The TESSDATA_PREFIX is set to the parent folder of the tessdata folder of the commandline tesseract 4.0.0 (C:\Program Files (x86)\Tesseract-OCR). The commandline tesseract produces reasonable output in all four OCR Engine Modes.
Here is my code:
package tessTest;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.tess4j.*;
import net.sourceforge.tess4j.ITesseract.RenderedFormat;
public class MainClass {
public static void main(String[] argv) {
ITesseract instance = new Tesseract1();
List<RenderedFormat> formats = new ArrayList<RenderedFormat>();
formats.add(RenderedFormat.PDF);
try {
instance.setPageSegMode(1);
instance.setOcrEngineMode(2);
instance.setTessVariable("textonly_pdf", "1");
instance.createDocuments("D:\\Documents\\Malverne.jpeg",
"D:\\Documents\\testOCR", formats);
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
}
}
With setOcrEngineMode(1) or setOcrEngineMode(0) it produces the pdf as expected. With setOcrEngineMode(2) and setOcrEngineMode(3) it results in the following error:
Exception in thread "main" java.lang.Error: Invalid memory access
at net.sourceforge.tess4j.TessAPI1.TessBaseAPIProcessPages(Native Method)
at net.sourceforge.tess4j.Tesseract1.createDocuments(Tesseract1.java:542)
at net.sourceforge.tess4j.Tesseract1.createDocuments(Tesseract1.java:517)
at net.sourceforge.tess4j.Tesseract1.createDocuments(Tesseract1.java:484)
at tessTest.MainClass.main(MainClass.java:21)
Detected 358 diacritics
contains_unichar_id(unichar_id):Error:Assert failed:in file
c:\projects\github\tesseract-ocr\ccutil\unicharset.h, line 513
It seems to be an issue with this particular image since on other images OEM 2 works fine from tess4j 4.0.0. I am aware that preprocessing the image will probably help, but I am working on a project where regularily many thousands of pictures, only some of which are similar to this one, will have to be OCRed by users so tailored preprocessing on a case-by-case-basis is infeasible.
The image in question is this one:
http://malvernetheatre.org/wp-content/uploads/2012/07/Malverne-Community-Theatre-Newspaper-Reviews-14-page-0.jpg
Any help would be greatly appreciated. Many thanks in advance.
my code is like:
import Render from './AppeRender';
import { Component } from 'react';
export default class appDB extends Component {
render () {
return Render.call(this, this.props, this.state);
}
}
and what i'm getting is:
Module parse failed: /home/projects/node_modules/DB/Db.js Line 5: Unexpected token
You may need an appropriate loader to handle this file type.
Note: Error only comes in web setup, it's working fine in android and in IOS i haven't tried yet.
Does anyone have any idea regarding this.
I think what is wrong here is that you using import twice (and the second one is a destructure.
Try this instead:
import { Component } from 'react';
import Render from './AppeRender';
You can bind Component in one import.
The second import could have been changed to a straight destructure:
const { Component } = React;
But, there is no reason to do this if you are only using Component.
Using import on an Object is not really correct (however, it might work with some implementations), I assume that is why the error was occurring.
I took a backup of my workspace. Meanwhile I created another workspace in my pc after formatting for temprory purposes. So now I've imported everything from my hard disk to my pc from File -> Import. However nothing seems to be 'resolved'. Heres an example of the code:
package com.sarthak.main;
import java.util.Scanner;
public class Myfirstgame {
public static void main(String[] args) {
System.out.println("Welcome to Momo Land, a place full of horror and utter momoness ");
System.out.println("Enter Your Name: ");
Scanner input = new Scanner(System.in);
String name=input.nextLine();
MyGame game=new MyGame(name);
game.run();
}
}
Things like System.out.println , input game.run etc. can't be resolved for some reason.
Check if your Java libraries are referenced in the properties of your project. In most cases, it is the referencing problem when importing projects.
Create a new project and then just copy the code inside the files..This may solve your problem.
How can I make a selenium click() work the same as a manual mouse click?
I have recently upgraded GWT from 1.7.1 to 2.0. Some selenium tests (SeleniumRC v1.0.1, IE7) are now failing. It seems that the Selenium.click() method is not selecting a GWT TreeItem. A manual click will make the TreeItem go blue (ie. look selected and have "gwt-TreeItem-selected" class attribute in the DOM), but the selenium test doesn't.
I'm convinced that selenium is actually finding the right element, just not clicking on it. If you change the string parameter in the click method you can check that selenium throws an exception when the element isn't found.
The sample code below uses the GWT Showcase website. It tries to click on the word "Beethoven". If you click on that word with your mouse, you'll see the TreeItem go blue. However when you run the selenium test, it won't.
package test;
import org.junit.Before;
import org.junit.Test;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
public class TestTreeClick {
static Selenium selenium = null;
#Before
public void setUp() throws Exception {
if (selenium == null) {
selenium = new DefaultSelenium("localhost", 4444, "*iexplore",
"http://gwt.google.com/samples/Showcase/Showcase.html#CwTree");
selenium.start();
}
}
#Test
public void testingClicking() {
selenium.open("http://gwt.google.com/samples/Showcase/Showcase.html#CwTree");
selenium.click("gwt-debug-cwTree-staticTree-root-child0-content");
}
}
I have tried some other methods (Selenium.clickAt(), Selenium.fireEvent(), Selenium.mouseOver()/Down()/Up() ) - but none reproduce the manual behaviour.
Unfortunately having a look at this case I have not been able to replicate clicking with Selenium. I have seen a number of people complaining that they can't use Selenium with GWT and one of the more famous teams have that issue. The Google Wave development team have started using WebDriver to test their code.
Now the good thing is that there currently a project to merge Selenium and WebDriver as they have their strengths and weaknesses and a number of them are in different areas so the final product will be amazing.
I believe that they may have a working version of the WebDriverBackedSelenium at Google Code so all you would need to do is update the instantiation of Selenium and it should start using the WebDriver code to run your test.
It seems that WebDriver can do it like this.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Example {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new InternetExplorerDriver();
driver.get("http://gwt.google.com/samples/Showcase/Showcase.html#CwTree");
WebElement element = driver.findElement(By.id("gwt-debug-cwTree-staticTree-root-child0-content"));
element.click();
}
}
I'd still like to be able to do it with Selenium. It may be that a future Selenium release will more fully incorporate WebDriver, and everything will be wonderful again. But I guess this works for now.
I wanted to post the code that finally worked for me following useful comments from AutomatedTester.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.ie.InternetExplorerDriver;
import com.thoughtworks.selenium.Selenium;
public class TestTreeClick {
public static void main(String[] args) {
WebDriver driver = new InternetExplorerDriver();
Selenium selenium = new WebDriverBackedSelenium(driver, "http://gwt.google.com/samples/Showcase/Showcase.html#CwTree");
selenium.open("http://gwt.google.com/samples/Showcase/Showcase.html#CwTree");
selenium.click("gwt-debug-cwTree-staticTree-root-child0-content");
}
}
You don't actually need to "click" on that button, but press "Enter" on it instead.
See http://dingyichen.livejournal.com/23628.html