We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
scanner (Read 1833 times)
scanner
Jul 16th, 2009, 5:20am
 
hi,

I'm converting an flatbed scannern (HP scanjet 2200C) into a camera.  Something similar like this:  http://lifehacker.com/5088105/turn-a-scanner-into-a-camera.

I would like to access the scanner directly from processing, to make a continously updating scan of a room.  After googling around and trying to find a solution for this specific model I figured out that it supports TWAIN, and found an open source java wrapper for TWAIN:

http://www.mms-computing.co.uk/uk/co/mmscomputing/device/twain/index.php

There is a demo applet that succesfully scans an image from my scanner:

http://www.mms-computing.co.uk/uk/co/mmscomputing/application/imageviewer/applet.html

The code can be downloaded here:

http://www.mms-computing.co.uk/uk/co/mmscomputing/download/index.php

How do i get this code to work with processing?  is it necesarry to write a library for this?  Or is there a better alternative for accesing a scanner?

thanks,
any hints are welcome
Re: scanner
Reply #1 - Jul 16th, 2009, 6:40am
 
You don't need to make a Processing library to use a Java library.
If you put the latter in a code folder in your sketch, or in the libraries folder of your sketchbook (respecting folder names and structure), you should be able to use it as a normal Java class.
Re: scanner
Reply #2 - Jul 16th, 2009, 12:55pm
 
thanks... got some early test running  Tongue

i can't seem to cast BufferedImage into a PImage.  

PImage test = new PImage(scan)  does not work.

(where scan is a BufferedImage)

i get following error:

java.lang.ClassCastException: [I cannot be cast to [B
     at sun.awt.image.ByteInterleavedRaster.getDataElements(Unknown Source)
     at processing.core.PImage.<init>(PImage.java:182)
     at scanner_test7$Test.update(scanner_test7.java:88)

the BufferedImage is not empty, i checked by writing it to a file


any pointers?

.
Re: scanner
Reply #3 - Jul 17th, 2009, 3:51am
 
Your buffered image seems to be of a type unsupported by Processing.
Relevant code in the PImage source:
Code:

pixels = new int[width * height];
WritableRaster raster = bi.getRaster();
raster.getDataElements(0, 0, width, height, pixels);

As you can see, it calls getDataElements with an array of ints (color information on 24/32 bits).
The error message says Java can't cast this array of ints (the [I part) to an array of bytes (the [B).
If I look at WritableRaster reference, I see getDataElements actually just expect an Object, which makes quite some room for interpretation for the sub-classes... The one you provide (your library provides...) is ByteInterleavedRaster which implies, well, it is based on an array of bytes!
It might be because you feed the BufferedImage with indexed colors, gray levels, or because that's just how it is implemented (eg. using 3 bytes per pixel (I doubt the scanner provides transparency information...)).

So I think you need to convert your BufferedImage to a compatible one, eg. by creating a new compatible one and drawing the old one in it.
Page Index Toggle Pages: 1