TWAIN/WIA example for java - java

I am developing a java application that can search my system and find all the scanners and lets me select if there are more than one scanner installed and proceed for scanning the document. I understand i should use twain for this. I have a library file in my system path but i have no idea how do i use this. Are there any sample programs on how to use this in my java application.
I have found the below sample code that uses WIA for communicating with the scanners. Is there any jar file to import to my netbeans or is there any other way out.
WIA.DeviceManager manager = new WIA.DeviceManagerClass();
string deviceName = "";
foreach (WIA.DeviceInfo info in manager.DeviceInfos)
{
if (info.Type == WIA.WiaDeviceType.ScannerDeviceType)
{
foreach (WIA.Property p in info.Properties)
{
if (p.Name == "Name")
{
deviceName = ((WIA.IProperty)p).get_Value().ToString();
Console.WriteLine(deviceName);
}
}
}
}

I'm not sure what library you're using, but I'd recommend one of these two:
Morena (low price, good documentation and email correspondence):
http://www.gnome.sk/index.html
mm's computing (open-source LGPL)
http://thorntonzone.com/manuals/Compression/Fax,%20IBM%20MMR/MMSC/mmsc/uk/co/mmscomputing/device/twain/index.html
If you're willing to pay a small price I'd recommend Morena. With Morena 6 (TWAIN) I was able to make a scan applet (called externally) that returns base64 jpeg data, and only ended up with 145 lines of my own Java code. On top of that they have full working examples and a very good FAQ page that covered almost every error I encountered. I haven't played with mms computing's plugin much because I didn't find out about it until after the Morena project was done.

It is really difficult for someone to make such decisions without knowing a lot about what we are dealing with. First let me shed some light on it.
Every Scanner device comes with a custom scan driver. These drivers either use TWAIN or WIA for communicating with the applications that use the drivers. In other words for all the applications that use these drivers there are two protocols that has to be followed:
WIA : https://msdn.microsoft.com/en-us/library/windows/desktop/ms630368(v=vs.85).aspx
TWAIN: http://www.twain.org/
Trust me you do not want to get in to the details of these.
So your goal would be to use on one of the protocols in your application to query the devices. The code bit you have pasted is a WIA c# sample app that queries and lists all the WIA only drivers installed on the machine.
I would really suggest you to use TWAIN as WIA is completely based on COM and for someone outside C++ world its quite difficult and also I'm not sure if WIA protocol supports TWAIN but the other way round is suppose to work.
If I were to do something like you I would consider writing a custom wrapper for TWAIN in Java like a interop in C# world. TWAIN is supposed to be easier compared to WIA.
In case of any confirmation required feel free to ask.
Thanks!

It's C# code. To make JVM and CLR work together, you can use jni4net to wrap the code block. You can read the article Java TWAIN with Dynamic .NET TWAIN and jni4net to learn how to call .NET code in Java.

Related

Java phonetics or language pronounciation

I am currently making a project for school, where I am going to make a program which teaches children how to read. My basic idea for the program was produce the sentence and then get Windows Anna to say it. My question to you is, how can I access Winodws Anna through Java? and is there a better way of doing this?
Thanks
If having the program access internet is acceptable, then you could use iSpeech.
You can use their API, but the problem with that is that it is limited to 200 uses/day.
iSpeech has decently sounding voices, generally more polished than other TTS engines I've tired like espeak or FreeTTS, because it actually pronounces the words more fluently. Sure, it might pronounce 'Wind', relating with air, as 'Wind', relating to twisting, but other than that, it speaks quite well.
Also, while I haven't had any prior experience with this, I found an article that shows you how to access the MS Speech with command line (which can obviously be commanded through Java[if you do not know how, here is a good article]). It is located here. In command line, all you do is type in 'SayDynamic.exe* the text you want to speak".
*Or SayStatic, the other download available on the page.
This method seems to be better in terms of speed and not relying on internet access, but it definitely does NOT pronounce things as well as iSpeech. I guess the ideal thing for your program to have would be to use iSpeech when online, and use the Say*.exe when offline.
The site also provides the source code of the program. As you might notice, it is NOT Microsoft Anna's voice, but you can specify that in the source and recompile it.
Hope I helped!
You can use command line utiity NirCmd that uses text-to-speech API installed on Windows.
So, supply this utility together with your java application and run it with appropriate command line.
You can try FreeTTS : a speech synthesizer written in java.
You can try to call the Microsoft Speech API (SAPI) but I don't know how to do it in java.
Can you tell us how you invoke NirCmd ?
Altenatively to NirCmd, you can build your own tool in C# that will read the text. The text could be within a txt and your tool invoked with the path to that txt as argument. You can easily adapt a demo project like this one : http://www.codeproject.com/Articles/19334/Text-to-Speech-using-Windows-SAPI
There is the Speech platform of Windows
http://www.microsoft.com/en-us/download/details.aspx?id=27226
The Speech runtime
http://www.microsoft.com/en-us/download/details.aspx?id=27225
You can use JNA (not JNI) to interact with dll from java
https://github.com/twall/jna

1-D barcode scanner(using images from a capturing device) implementation in java

I am a student and as a project i have to implement a barcode(1-D) based attendance marking system.While surfing across the web i came to know that barcode readers are a bit costly toys to purchase,so now what I want to do is I want to capture images of barcodes through a capturing device(mostly a webcam) and then process them to get the content stored in it.
I found a few projects on the internet that do the same but they use .NET f/w and I am not so familiar with .NET technology. The only project that uses java is http://sourceforge.net/projects/javabarcoderead/ but somehow i am not able to run the jar file they are providing.
SO, I would like to know about the algorithms or methods that can be used for the same or even any project from where i can get some insight on how to move further with this...
Happy Coding...
You're right, it would be very difficult to use a library with no documentation and no source code.
I'd suggest using ZXing. It's a well-documented library with lots of examples.

JavaNNS - Parsing the created Neural Network

I'm currently working on a Neural Network for creating a "better" PNG Predictor (Prefilter).
I already created the network (with JavaNNS) which has a quite good learning rate on 8-Bit grayscale images.
Now my next step would be to include this created network in my prepared PNG Encoder/Decoder which is written in Java. But to do that I need to parse the created .net file from JavaNNS.
I don't want to invent the wheel again so is there any chance that another one of you has already written a simple parser for the .net files of the JavaNNS which would read all the layers with the neurons, the connections and the weights on the connections and store it in any usable Java data structure?
I know it isn't that hard to create a parser, but it would be awesome to save time and skip this "boring" task.. :)
Thanks!
JavaNNS's predecessor, SNNS (alternative link), had an export function which exported the trained network as C code (essentially a header and source file pair). These files could then be used in custom code.
In Java you could use JNI or JNA to call C code and I am sure there are threads here on SO how to accomplish this.
I do not know the current version of JavaNNS, but maybe they already provide an export function exporting the network as Java code instead of C? Or you could open your trained network in the old SNNS and export it?
I just wanna add that I've created my own .net (JavaNNS) File Parser in Java. It is possible to parse single hidden layer networks. If anyone needs the code who run into the same problem I had before I am happy to share my code.
You can contact me on my blog. Here is the post about the Neural Network Project I've done. Just let a comment there and I will provide you the JavaNNS Parser and the corresponding NeuralNetwork Class.
http://prineblog.wordpress.com/2011/06/21/neural-network-as-predictor-for-image-coding-png/
I just updated the Version of Nen to Beta - It is a lightweight 3-layer neural network implementation in Java for regression and classification. A little performance comparison against support vector machines (LibSVM) demonstrates its capabilities. It can be used via command line or Java.

Image Processing via Standalone application

I'm developing a project for doing Content Based Image Retrieval where front end will be in java.
The main issue is about choosing tool for performing image processing. Since Matlab provides a lot of functionality for doing CBIR. But the main problem about using Matlab is that you need to have Matlab installed on every computer using the application.
Is there any other way in which I can do my project (Using other tools or driver) so that my application will run without using any other tools ???
Or can I develop entire application in Matlab only and deploy it as a standalone application ???
Thank you..
There are plenty of image processing libraries, for example for Java: ImageJ, there is also one by the Apache Commons project. If you need higher-level computer vision libraries there is OpenCV for C++ that also has bindings for Java, for example.
You can also develop the entire application in Matlab, but to deploy a stand alone application requires this requires licensing Mathworks Builder NE (which can be expensive). Matlab is very good for research and prototyping purposes.
There are other alternatives that are amenable to quick prototyping for example Python and PIL.
I think the bottom line is that there are plenty of options.
Java image utilities library: A Java library for loading, editing, analyzing and saving pixel image files.
It supports various file formats.
Provides demo applications for the command line. It has AWT GUI toolkit too.
Matlab is an excellent tool for prototyping as already pointed out by carlosdc. Matlab offers limited options with regard to UI programming. GUIDE is ok for small projects, but hinders more than it helps on bigger ones.
With MATLAB Builder JA you're able to compile your Matlab code into Java classes.
With regard to plotting time series in real time, libraries like JFreeChart are way slower.
I think OpenCV is one of the best libraries out there for image processing but Java Advanced Imaging is also quite good but doesn't has as much features and examples. Color similarity would be simple in JAI but shape probably would involve more code.
If you choose to use OpenCV I think you have at least two possible binding implementations for Java. The one my group uses is this one. It has some Processing dependencies.
Regardless of what library you choose be prepared for some frustration. Matlab users are used to all the nice features it provides and when they have to port their code to other languages end having to write a lot more code.
Well, after a long search finally I've found the way to deploy Matlab code along with java that too standalone application..
The steps are simple::--
1. Go and get Javabuilder.jar file located at location::
Matlab\toolbox\javabuilder\jar\javabuilder.jar
Next type deploytool in Matlabs command line...
deploytool window will open now create a new java project.
Select Matlab files that you want to use.
The deploytool will now convert the .m file to .jar file.
Now use both of the above mentioned jar files and develop your java compatible matlab code
and thats the way you can create the standalone application of matlab..

Java + OpenOffice, Is interop automation really this difficult?

I'm trying to re-write a C# application of mine in Java. I've chosen Java because our target platform is now Linux, no longer Windows.
My C# application used Microsoft Office Interop to automate things like Word and Excel. It would simply open different documents and apply our formatting to them (adjust column width, remove italics, etc). Finally, it would save the documents as PDF.
Now that we are targeting Java and Linux, and knowing that OpenOffice can do all of these things, I figured it would be a smooth transition. OpenOffice is open source, so it must have a relatively nice automation interface, right?
I've been Google'ing and looking at docs all morning. I've downloaded the OpenOffice SDK. I've followed instructions involving installing MinGW and a Zip toolkit. I've tried NetBeans plugins and Eclipse configuration settings.
The funny thing is, I'm not even sure if I'm in the right direction. I've been reading about OpenOffice UDO interface, but that sounds more like in-OpenOffice Scripts, like VBA or something.
Does anyone know if there's simply some sort of import that allows me to use OpenOffice to open and manipulate documents, similar to Office's Interop libraries? If so, know of any recent examples or blog posts, etc?
Yes, the OpenOffice jar files themselves (from the app) are the SDK. The interface involves calling methods in them. It's not hard once you figure it out, but I agree, documentation for it is pretty weak. It was definitely written by people that know how to do it, and can use it as a reference, but aren't any good at explaining it to others. :-)

Categories

Resources