Android - Change Camera source from hardware Camera to a TCP source

73 views
Skip to first unread message

Andrei

unread,
Dec 18, 2009, 7:26:10 PM12/18/09
to zxing
Hello !

I'm want to use the library in the Android Emulator and since it
doesn't have webcam support I wan't to stream the pictures from a TCP
source ( http://www.tomgibara.com/android/camera-source ). I've
imported the source files into an Eclipse Project with the core.jar
compiled and I've noticed that CameraManager class does all the Camera
communication stuff.
Anybody knows how to make it happen ?

Sean Owen

unread,
Dec 20, 2009, 2:47:39 AM12/20/09
to zxing
What is your question? it sounds like you have found code that should
do what you like -- you just need to hook it up. Maybe you can be more
specific.

Andrei

unread,
Dec 20, 2009, 5:23:36 AM12/20/09
to zxing
I've found the code ... hooking it up is the problem. The
CameraManager it's built very tightly around Android's Camera class
and I don't know how to "emulate" all the information required by
zxing.
The question is : how you can integrate Tom Gibara's code in the
CameraManager class ?

Andrei

unread,
Dec 25, 2009, 6:19:06 PM12/25/09
to zxing
Hello !

Me again ... I've managed to capture the bitmap from the TCP source
and I've found out that the "requestPreviewFrame" method from the
"CameraManager" class ( called by the decode thread ) is responsible
for sending back a message with the bitmap attached ( please correct
me if I'm wrong ). The problem is that the handler received in the
"requestPreviewFrame" is null. Does anybody know why ?

final class CameraManager {

public static void init(Context context) {
if (cameraManager == null) {
cameraManager = new CameraManager(context);
}
}

public static CameraManager get() {
return cameraManager;
}

private CameraManager(Context context) {
this.context = context;
}

public void openDriver(SurfaceHolder holder) {

if (!initialized) {
initialized = true;
getScreenResolution();
if ( camera == null ) {
camera = new SocketCamera("192.168.0.10", 9889, 320, 240);
}
}
}

public void closeDriver() { }

public void startPreview() { previewing = true; }

public void stopPreview() { previewing = false; }


public void requestPreviewFrame(Handler handler, int message) {

if (camera == null) {
camera = new SocketCamera("192.168.0.10", 9889, 320, 240);
}
Bitmap b = camera.capture();

if ( handler == null ) Log.d("cameraManager", "handler is null");
Message msg = handler.obtainMessage(message, camera.getWidth(),
camera.getHeight(), b);
msg.sendToTarget();
}

public void requestAutoFocus(Handler handler, int message) {
Message msg = handler.obtainMessage(message);
handler.sendMessageDelayed(msg, 1500L);
}

public Rect getFramingRect() {
return new Rect(0, 0, 320, 240);
}

public Point[] convertResultPoints(ResultPoint[] points) { ....
not modified .... }

public BaseLuminanceSource buildLuminanceSource(byte[] data, int
width, int height) { .... not modified .... }

private Point getScreenResolution() { .... not modified .... }

}

Andrei

unread,
Dec 26, 2009, 5:13:30 PM12/26/09
to zxing
Ok, so I found a way to get all things going but I've hit a major
problem ... I'm receiving a RGB Bitmap through the network which is
fine for the Canvas but the Barcode Decoder only accepts the YUV420
format ... how can I convert the Bitmap object into a byte array with
the YUV420 format ? Please help !!!

Andrei

unread,
Dec 26, 2009, 6:05:20 PM12/26/09
to zxing
Found a way to work directly with the Bitmap object using a modified
version of the LCDUIImageLuminanceSource.java from the j2me package.

I'll write an article in a couple of days : http://www.scs.ubbcluj.ro/~masd0215/android/

Tnx for this great library ! You rock !

Daniel Switkin

unread,
Dec 26, 2009, 6:15:52 PM12/26/09
to zx...@googlegroups.com
Glad to hear you figured it out. You can also look at the j2se code to
see how to convert RGB to luminance.

Daniel

Reply all
Reply to author
Forward
0 new messages